agentscope-ai / agentscope-ai/agentscope-java

[Feature]: Allow `Msg.getStructuredData()` to accept a run-time JSON Schema instead of a compiled Class

Ouverte
#208 1 commentaire 0 réactions 1 personne assignée Réclamée par @Jamison929611 Voir sur GitHub
area/core/agent enhancement
Langage dominant
Java
Étoiles
5.6k
Forks
1.3k
Merge moyen
4 j 12 h
PR mergées (30 j)
77

Description

**AgentScope-Java is an open-source project. To involve a broader community, we recommend asking your questions in English.**

**Is your feature request related to a problem? Please describe.**
Yes.
In our use-case, end-users are allowed to design the JSON schema they expect the agent to return (via a visual schema editor on the front-end).
At run-time we only have this user-supplied schema (usually expressed as a `JsonNode` or raw JSON string), **not** a compiled Java class.
Currently `Msg.getStructuredData(Class clazz)` only accepts a compiled `Class` object, so we have to:

1. Generate a Java source file from the schema at run-time.
2. Compile it in-memory.
3. Load the resulting `Class` and pass it to `getStructuredData`.

This is slow, fragile and impossible on some restricted runtimes.
We would like to skip the “generate-and-compile” step and let `getStructuredData` work directly with the user-defined schema.

**Describe the solution you'd like**
Add an overloaded method (or an optional parameter) that accepts a **JSON Schema** instead of a `Class`, e.g.

```java
public T Msg.getStructuredData(JsonNode schema);
// or
public T Msg.getStructuredData(String jsonSchema);
```

Internally the framework would use the same binding / validation engine it already uses (Jackson, JSON-B, etc.) but would build the Java object dynamically (e.g. `JsonNode`, `Map`, or a generated in-memory type) instead of requiring a pre-compiled POJO.

If the returned type must be generic, `JsonNode` or `Map` is perfectly acceptable for us; we just need the validation and conversion to be done by AgentScope-Java.

**Describe alternatives you've considered**
1. Pre-generate one POJO per possible schema – impossible because users create new schemas at any time.
2. Generate and compile a POJO at runtime – works, but adds heavy JDK compiler dependencies and slows the agent response.
3. Call `getText()` and manually validate / convert – duplicates the logic that AgentScope-Java already has inside `getStructuredData`.

**Additional context**
*none*

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.