agentscope-ai / agentscope-ai/agentscope-java

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

オープン
#208 コメント 1 件 リアクション 0 件 担当者 1 名 @Jamison929611 が担当を希望しています GitHub で見る
area/core/agent enhancement
主要言語
Java
スター
5.6k
フォーク
1.3k
平均マージ
4日 12時間
マージ済み PR(30日)
77

説明

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

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。