feat(output): add support for structured data dynamic define#357
Conversation
…structured_data_dynamic_define # Conflicts: # agentscope-core/src/main/java/io/agentscope/core/agent/StructuredOutputHandler.java
…ithub.com/chiangzeon/agentscope-java into feat/allow_structured_data_dynamic_define
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
| this.content = | ||
| Objects.nonNull(content) && content.stream().allMatch(Objects::nonNull) | ||
| ? List.copyOf(content) | ||
| : List.of(); | ||
| this.metadata = | ||
| Objects.nonNull(metadata) | ||
| && metadata.entrySet().stream() | ||
| .allMatch( | ||
| entry -> | ||
| Objects.nonNull(entry.getKey()) | ||
| && Objects.nonNull( | ||
| entry.getValue())) | ||
| ? Map.copyOf(metadata) | ||
| : Map.of(); |
There was a problem hiding this comment.
Why change this?
https://github.com/agentscope-ai/agentscope-java/issues/300 new bug report
There was a problem hiding this comment.
Please submit a new PR to fix it
| if (Objects.nonNull(targetClass)) { | ||
| OBJECT_MAPPER.convertValue(responseData, targetClass); | ||
| } |
There was a problem hiding this comment.
Can we validate the schemaDesc here?
There was a problem hiding this comment.
Yes, this is technically feasible. However, I would generally advise against it because a dynamically generated validation mechanism cannot comprehensively cover all business rules. Implementing this feature would incur significant development and maintenance overhead. Therefore, I propose that the responsibility for parameter validation should lie with the calling client. Do you agree with this perspective?
There was a problem hiding this comment.
Given that current Large Language Models (LLMs) still exhibit limitations in generating complex structures, it is essential to implement data format validation within the Agent. This facilitates timely prompting of the model for error correction.
There was a problem hiding this comment.
Given that current Large Language Models (LLMs) still exhibit limitations in generating complex structures, it is essential to implement data format validation within the Agent. This facilitates timely prompting of the model for error correction.
Done
| this.content = | ||
| Objects.nonNull(content) && content.stream().allMatch(Objects::nonNull) | ||
| ? List.copyOf(content) | ||
| : List.of(); | ||
| this.metadata = | ||
| Objects.nonNull(metadata) | ||
| && metadata.entrySet().stream() | ||
| .allMatch( | ||
| entry -> | ||
| Objects.nonNull(entry.getKey()) | ||
| && Objects.nonNull( | ||
| entry.getValue())) | ||
| ? Map.copyOf(metadata) | ||
| : Map.of(); |
There was a problem hiding this comment.
Please submit a new PR to fix it
…structured_data_dynamic_define
AgentScope-Java Version
[The version of AgentScope-Java you are working on, e.g. 1.0.3, check your pom.xml dependency version or run
mvn dependency:tree | grep agentscope-parent:pom(only mac/linux)]Description
Support dynamic structured data definition.
Summary
1.io.agentscope.core.agent.Agent#call(io.agentscope.core.message.Msg, java.lang.Class) The reason for passing POJO is because it is called io.agentscope.core.ReActAgent#doCall(java.util.List, java.lang.Class) We need to register a tool to summarize the output.
Need to overload getStructuredData method, as the dynamic type return can only be KV data and metadata already contains the original response. For concurrency security, the input parameter provides a Boolean type for the caller to choose whether it can be modified.
The core call is in io.agentscope. core. tracking. Tracer # callModel. Based on the protocols of different providers, the override io. agentscope. core. model. ChatModelBase # doStream method is required.
If there is any mistake, please point it out promptly. Thank you
https://github.com/agentscope-ai/agentscope-java/issues/208
Checklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test)