feat: feat-agentscope 分支兼容 OpenAI Responses API(含 tool calling)#545
Open
WinSalty wants to merge 2 commits into
Open
feat: feat-agentscope 分支兼容 OpenAI Responses API(含 tool calling)#545WinSalty wants to merge 2 commits into
WinSalty wants to merge 2 commits into
Conversation
新增 Responses API 适配层(ResponsesApi + ResponsesApiChatModel), 实现 ChatModel 接口使上层服务无感切换;前端模型配置增加接口协议选项。 代码审核修复: - 流式终包改为空文本,避免上层 FluxUtil 聚合时全文重复 - SSE 解析捕获 IllegalArgumentException,畸形事件不再中断流 - 运行时 options 改用 ChatOptions 接口取值,兼容任意实现 - 同步调用接入统一重试模板,与 OpenAiChatModel 容错对齐 - 补充 18 个单元测试覆盖协议映射与事件解析 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
请求侧将 ToolCallingChatOptions 的工具声明映射为 tools 字段, 助手历史工具调用与执行结果映射为 function_call / function_call_output; 响应侧从 output 中提取 function_call 转为 AssistantMessage.toolCalls, 流式场景由终包携带(文本仍为空串,不影响上层聚合)。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
40db5a7 to
4a65e50
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
将 #544 的 Responses API 协议兼容能力移植到
feat-agentscope分支,并针对 AgentScope 链路的需求扩展了 tool calling 支持,使仅支持POST /v1/responses协议的模型也能驱动 AgentScope agent 的完整工具调用循环。关联:#531(原始需求)、#544(main 分支的 Responses API 兼容实现)
改动内容
移植自 #544(cherry-pick)
ChatApiProtocol枚举、ResponsesApiHTTP 客户端、ResponsesApiChatModel适配层DynamicModelFactory按chatApiProtocol配置分支创建 ChatModelchat_api_protocol字段本 PR 新增:tool calling 支持
AgentScope 链路(
SpringAiAgentScopeModel→delegate.stream(prompt))依赖 Spring AI 的 tool calling 协议,本 PR 在适配层补齐双向映射:请求侧
ToolCallingChatOptions,将ToolCallback的ToolDefinition(name/description/inputSchema)映射为 Responses API 的tools字段(扁平 function 结构,inputSchema JSON 字符串解析为对象)AssistantMessage.toolCalls→function_call输入项ToolResponseMessage→function_call_output输入项(靠call_id与调用配对,多轮 agent 循环回放历史依赖此映射)响应侧
type=function_call项转为AssistantMessage.ToolCall,存在工具调用时 finishReason 为TOOL_CALLS(与OpenAiChatModel对齐)function_call项只在 completed 事件的完整 output 中出现一次,由终包携带 toolCalls(文本仍为空串,不破坏上层 FluxUtil 文本聚合);参数增量事件被忽略,AgentScope 桥接层对每个 chunk 读取 toolCalls,单次完整携带即可驱动工具执行设计边界
internalToolExecutionEnabled=false),工具调用返回给调用方执行——与 AgentScope runtime 自管工具执行的设计一致tools字段,纯文本链路行为与 feat: 兼容 OpenAI Responses API #544 完全一致response.function_call_arguments.delta)静默忽略,保证向前兼容存量部署升级说明
已有 MySQL 部署需手动执行:
测试方案
ResponsesApiTest10 个 +ResponsesApiChatModelTest14 个),新增覆盖:tools 字段映射、工具历史 function_call/function_call_output 映射、响应 toolCalls 提取、流式终包携带 toolCalls、function_call SSE 事件反序列化spring-javaformat:validate+checkstyle:check通过/v1/responses,模型qwen-plus,见下)端到端测试结果
call()stream()function_call)function_call_output历史回放)关于回传步骤的说明:用标准 OpenAI Responses API 格式的最小 curl 请求可复现同样错误——DashScope 兼容层内部将
function_call_output转为role='tool'消息后,又被其自身校验器拒绝(只接受 user/assistant/system/function)。这是 DashScope/v1/responses兼容实现的服务端限制,并非本适配层问题;本 PR 的请求格式符合 OpenAI 规范,在规范实现的服务端(如 OpenAI 官方)上完整工具循环可用。错误示例:🤖 Generated with Claude Code