Skip to content

WriteCode序列化问题修复#44

Merged
canfuu merged 5 commits intomainfrom
feature/20260320_28695575_write_code_fix_1
Mar 20, 2026
Merged

WriteCode序列化问题修复#44
canfuu merged 5 commits intomainfrom
feature/20260320_28695575_write_code_fix_1

Conversation

@AQing-527
Copy link
Copy Markdown
Collaborator

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:

  • Introduced FlexibleStringListDeserializer, a custom Jackson deserializer that allows List<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)
  • Applied FlexibleStringListDeserializer to the parameters field in both WriteCodeTool.Request and WriteConditionCodeTool.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:

  • Clarified documentation for the args field in ExecuteCodeTool.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:

  • Updated the parent project and all submodules to version 0.2.1 to 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]

Copilot AI review requested due to automatic review settings March 20, 2026 04:59
@canfuu canfuu enabled auto-merge March 20, 2026 05:00
Copy link
Copy Markdown
Collaborator

@canfuu canfuu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@canfuu canfuu merged commit f43643c into main Mar 20, 2026
3 checks passed
@canfuu canfuu deleted the feature/20260320_28695575_write_code_fix_1 branch March 20, 2026 05:01
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

该 PR 旨在增强 Codeact 代码生成/执行工具对函数参数 parameters 的反序列化兼容性(适配 LLM 可能输出的非标准格式),并同步将各 Maven 模块版本升级到 0.2.1

Changes:

  • 新增 FlexibleStringListDeserializer,允许 List<String> 同时接受 JSON 数组与逗号分隔字符串两种输入形式。
  • WriteCodeTool.RequestWriteConditionCodeTool.Requestparameters 字段上应用该反序列化器,并补充 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("条件函数需要的参数名列表")
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parameters 已通过 FlexibleStringListDeserializer 支持既可以传 JSON 数组也可以传逗号分隔字符串,但这里的描述仍是“参数名列表”且未提示可接受字符串格式。建议在 @JsonPropertyDescription 中明确两种可接受输入,减少 LLM/调用方格式错误。

Suggested change
@JsonPropertyDescription("条件函数需要的参数名列表")
@JsonPropertyDescription("条件函数需要的参数名列表,可以是 JSON 字符串数组或逗号分隔的字符串,例如 [\"user_id\", \"order_id\"] 或 \"user_id,order_id\"")

Copilot uses AI. Check for mistakes.

@JsonProperty
@JsonPropertyDescription("函数接受的参数名列表")
@JsonPropertyDescription("函数参数名的字符串数组")
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parameters 字段现在支持通过 FlexibleStringListDeserializer 接受“逗号分隔字符串”以及“JSON 数组”两种输入,但这里的 @JsonPropertyDescription 仍写成“字符串数组”,会误导工具调用方/LLM 的入参格式。建议描述中明确两种可接受格式(数组或逗号分隔字符串,空/空白会被忽略)。

Suggested change
@JsonPropertyDescription("函数参数名的字符串数组")
@JsonPropertyDescription("函数参数名列表,支持 JSON 数组或逗号分隔字符串,空/空白会被忽略")

Copilot uses AI. Check for mistakes.
Comment on lines +87 to +88
// Fallback for any other token type
return new ArrayList<>();
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FlexibleStringListDeserializer 的 Javadoc 声明仅支持 array/string/null 三种输入,但实现对其它 token(例如 object/number/bool)直接回退为空列表,会静默吞掉不合法入参并可能导致后续逻辑把函数当作“无参数/kwargs”。建议改为通过 ctxt.handleUnexpectedToken(...) 抛出可诊断的反序列化错误,或至少在 Javadoc/日志中明确这一回退行为。

Suggested change
// 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;

Copilot uses AI. Check for mistakes.
"'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={}。" +
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里将“parameters 为空列表”直接等同于“函数没有参数”,但在当前实现里 GeneratedCode.parameters 为空也可能表示使用 **kwargsExecuteCodeTool 在参数列表为空时会按“灵活参数”处理)。建议把文案改成“未声明固定参数/参数列表为空时可省略 args 或传入 {}”,避免把 parameters=[] 误解释为严格的无参函数。

Suggested change
"如果函数没有参数(parameters为空列表),则不要传入 args 字段,或使用 args={}。" +
"如果未声明固定参数(parameters 为空列表),则可以省略 args 字段,或使用 args={}。" +

Copilot uses AI. Check for mistakes.
"参数名必须与生成函数时指定的参数完全匹配。" +
"示例:如果函数生成时参数为 ['a', 'b'],则使用 {\"a\": value1, \"b\": value2}。" +
"如果函数生成时没有指定特定参数(使用 **kwargs),可以传入任意参数。" +
"如果函数没有参数,请省略此字段或传入空对象 {}。" +
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新增的说明“如果函数没有参数,请省略此字段或传入空对象 {}”在语义上容易与上一句“parameters 为空表示 **kwargs”冲突:当前代码里 GeneratedCode.parameters 为空会被当作“灵活参数(**kwargs)”处理,不一定代表严格无参。建议将文案调整为“当函数未声明固定参数(parameters 为空/kwargs/无参)时,可省略 args 或传入 {}”,避免误导工具调用方。

Suggested change
"如果函数没有参数,请省略此字段或传入空对象 {}。" +
"当函数未声明固定参数(parameters 为空/kwargs/无参)时,可省略 args 字段或传入空对象 {}。" +

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants