Conversation
…/20260317195358450_r_release_1003870_meow-agent-code
There was a problem hiding this comment.
Pull request overview
该 PR 旨在增强 Codeact 代码生成/执行工具对函数参数 parameters 的反序列化兼容性(适配 LLM 可能输出的非标准格式),并同步将各 Maven 模块版本升级到 0.2.1。
Changes:
- 新增
FlexibleStringListDeserializer,允许List<String>同时接受 JSON 数组与逗号分隔字符串两种输入形式。 - 在
WriteCodeTool.Request与WriteConditionCodeTool.Request的parameters字段上应用该反序列化器,并补充execute_code.args的使用说明。 - 将父工程及各子模块版本统一升级至
0.2.1。
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| pom.xml | 父工程版本升级至 0.2.1 |
| assistant-agent-autoconfigure/pom.xml | 模块版本升级至 0.2.1 |
| assistant-agent-common/pom.xml | 模块版本升级至 0.2.1 |
| assistant-agent-core/pom.xml | 模块版本升级至 0.2.1 |
| assistant-agent-evaluation/pom.xml | 模块版本升级至 0.2.1 |
| assistant-agent-extensions/pom.xml | 模块版本升级至 0.2.1 |
| assistant-agent-prompt-builder/pom.xml | 模块版本升级至 0.2.1 |
| assistant-agent-start/pom.xml | 模块版本升级至 0.2.1 |
| assistant-agent-autoconfigure/.../FlexibleStringListDeserializer.java | 新增灵活字符串列表反序列化器 |
| assistant-agent-autoconfigure/.../WriteCodeTool.java | parameters 字段启用自定义反序列化 |
| assistant-agent-autoconfigure/.../WriteConditionCodeTool.java | parameters 字段启用自定义反序列化 |
| assistant-agent-autoconfigure/.../ExecuteCodeTool.java | 更新 args 字段说明文案 |
| assistant-agent-autoconfigure/.../CodeactAgent.java | 更新 execute_code 工具描述文案 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -340,6 +341,7 @@ public static class Request { | |||
|
|
|||
| @JsonProperty | |||
| @JsonPropertyDescription("条件函数需要的参数名列表") | |||
There was a problem hiding this comment.
parameters 已通过 FlexibleStringListDeserializer 支持既可以传 JSON 数组也可以传逗号分隔字符串,但这里的描述仍是“参数名列表”且未提示可接受字符串格式。建议在 @JsonPropertyDescription 中明确两种可接受输入,减少 LLM/调用方格式错误。
| @JsonPropertyDescription("条件函数需要的参数名列表") | |
| @JsonPropertyDescription("条件函数需要的参数名列表,可以是 JSON 字符串数组或逗号分隔的字符串,例如 [\"user_id\", \"order_id\"] 或 \"user_id,order_id\"") |
|
|
||
| @JsonProperty | ||
| @JsonPropertyDescription("函数接受的参数名列表") | ||
| @JsonPropertyDescription("函数参数名的字符串数组") |
There was a problem hiding this comment.
parameters 字段现在支持通过 FlexibleStringListDeserializer 接受“逗号分隔字符串”以及“JSON 数组”两种输入,但这里的 @JsonPropertyDescription 仍写成“字符串数组”,会误导工具调用方/LLM 的入参格式。建议描述中明确两种可接受格式(数组或逗号分隔字符串,空/空白会被忽略)。
| @JsonPropertyDescription("函数参数名的字符串数组") | |
| @JsonPropertyDescription("函数参数名列表,支持 JSON 数组或逗号分隔字符串,空/空白会被忽略") |
| // Fallback for any other token type | ||
| return new ArrayList<>(); |
There was a problem hiding this comment.
FlexibleStringListDeserializer 的 Javadoc 声明仅支持 array/string/null 三种输入,但实现对其它 token(例如 object/number/bool)直接回退为空列表,会静默吞掉不合法入参并可能导致后续逻辑把函数当作“无参数/kwargs”。建议改为通过 ctxt.handleUnexpectedToken(...) 抛出可诊断的反序列化错误,或至少在 Javadoc/日志中明确这一回退行为。
| // Fallback for any other token type | |
| return new ArrayList<>(); | |
| // Any other token type is unexpected: delegate to Jackson's error handling | |
| @SuppressWarnings("unchecked") | |
| List<String> result = (List<String>) ctxt.handleUnexpectedToken(List.class, p); | |
| return result; |
| "'args' 参数名必须与 write_code 中指定的 'parameters' 完全匹配。" + | ||
| "示例:如果调用 write_code 时使用 functionName='calculate_sum' 和 parameters=['a', 'b']," + | ||
| "则调用 execute_code 时必须使用 functionName='calculate_sum' 和 args={'a': 10, 'b': 20}。" + | ||
| "如果函数没有参数(parameters为空列表),则不要传入 args 字段,或使用 args={}。" + |
There was a problem hiding this comment.
这里将“parameters 为空列表”直接等同于“函数没有参数”,但在当前实现里 GeneratedCode.parameters 为空也可能表示使用 **kwargs(ExecuteCodeTool 在参数列表为空时会按“灵活参数”处理)。建议把文案改成“未声明固定参数/参数列表为空时可省略 args 或传入 {}”,避免把 parameters=[] 误解释为严格的无参函数。
| "如果函数没有参数(parameters为空列表),则不要传入 args 字段,或使用 args={}。" + | |
| "如果未声明固定参数(parameters 为空列表),则可以省略 args 字段,或使用 args={}。" + |
| "参数名必须与生成函数时指定的参数完全匹配。" + | ||
| "示例:如果函数生成时参数为 ['a', 'b'],则使用 {\"a\": value1, \"b\": value2}。" + | ||
| "如果函数生成时没有指定特定参数(使用 **kwargs),可以传入任意参数。" + | ||
| "如果函数没有参数,请省略此字段或传入空对象 {}。" + |
There was a problem hiding this comment.
新增的说明“如果函数没有参数,请省略此字段或传入空对象 {}”在语义上容易与上一句“parameters 为空表示 **kwargs”冲突:当前代码里 GeneratedCode.parameters 为空会被当作“灵活参数(**kwargs)”处理,不一定代表严格无参。建议将文案调整为“当函数未声明固定参数(parameters 为空/kwargs/无参)时,可省略 args 或传入 {}”,避免误导工具调用方。
| "如果函数没有参数,请省略此字段或传入空对象 {}。" + | |
| "当函数未声明固定参数(parameters 为空/kwargs/无参)时,可省略 args 字段或传入空对象 {}。" + |
This pull request focuses on improving the handling and robustness of function parameter deserialization in the agent's code generation tools, as well as updating project versioning. The most significant changes include introducing a custom deserializer to accept both string and array formats for function parameters, applying it to relevant request classes, and clarifying documentation for parameter handling. Additionally, all Maven modules are updated to version 0.2.1.
Parameter Handling Improvements:
FlexibleStringListDeserializer, a custom Jackson deserializer that allowsList<String>fields to accept both JSON arrays and comma-separated strings, improving compatibility with varied LLM outputs. (assistant-agent-autoconfigure/src/main/java/com/alibaba/assistant/agent/autoconfigure/tools/FlexibleStringListDeserializer.java)FlexibleStringListDeserializerto theparametersfield in bothWriteCodeTool.RequestandWriteConditionCodeTool.Request, ensuring flexible and robust parameter parsing. (assistant-agent-autoconfigure/src/main/java/com/alibaba/assistant/agent/autoconfigure/tools/WriteCodeTool.java,assistant-agent-autoconfigure/src/main/java/com/alibaba/assistant/agent/autoconfigure/tools/WriteConditionCodeTool.java) [1] [2] [3] [4]Documentation and Usability:
argsfield inExecuteCodeTool.Request, specifying that if a function has no parameters, the field should be omitted or set to an empty object. (assistant-agent-autoconfigure/src/main/java/com/alibaba/assistant/agent/autoconfigure/CodeactAgent.java,assistant-agent-autoconfigure/src/main/java/com/alibaba/assistant/agent/autoconfigure/tools/ExecuteCodeTool.java) [1] [2]Project Version Updates:
0.2.1to reflect these changes and maintain consistency across the codebase. (pom.xml,assistant-agent-autoconfigure/pom.xml,assistant-agent-common/pom.xml,assistant-agent-core/pom.xml,assistant-agent-evaluation/pom.xml,assistant-agent-extensions/pom.xml,assistant-agent-prompt-builder/pom.xml,assistant-agent-start/pom.xml) [1] [2] [3] [4] [5] [6] [7] [8]