agentscope-ai / agentscope-ai/agentscope-java

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

Aperta
#208 1 commento 0 reazioni 1 assegnatario Rivendicata da @Jamison929611 Vedi su GitHub
area/core/agent enhancement
Lingua principale
Java
Stelle
5.6k
Fork
1.3k
Merge medio
4g 12h
PR unite (30g)
77

Descrizione

**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*

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.