agentscope-ai / agentscope-ai/agentscope-java

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

Abierto
#208 1 comentario 0 reacciones 1 asignado Reclamado por @Jamison929611 Ver en GitHub
area/core/agent enhancement
Lenguaje dominante
Java
Estrellas
5.6k
Forks
1.3k
Merge medio
4 d 12 h
PR fusionados (30 d)
77

Descripción

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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.