fix: preserve Responses function call namespace#1797
Conversation
Greptile SummaryThis PR adds
Confidence Score: 5/5Safe to merge — the change is additive field propagation with Every conversion site (streaming and non-streaming, inbound and outbound, aggregator and response builder) now consistently threads the new No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant UP as Upstream Provider
participant OS as outbound_stream.go
participant IS as inbound_stream.go
participant AGG as aggregator.go
participant Client
UP->>OS: "output_item.added {type:function_call, name, namespace}"
OS->>OS: "store toolCall{Name, Namespace} in state"
OS->>Client: "stream delta ToolCall{Name, Namespace}"
UP->>OS: "function_call_arguments.delta {delta}"
OS->>Client: "stream delta ToolCall{Arguments delta}"
UP->>OS: "function_call_arguments.done {name?, namespace?, arguments}"
OS->>OS: guard update Name (if non-empty), Namespace (if non-empty)
Note over OS: Returns nil — no event emitted
UP->>OS: response.completed
OS->>Client: "finish_reason=tool_calls"
Note over IS,AGG: Aggregator path (non-streaming client)
IS->>AGG: "OutputItemAdded {Item{Name, Namespace}}"
AGG->>AGG: "aggregatedItem.Namespace = item.Namespace"
IS->>AGG: FunctionCallArgumentsDelta
IS->>AGG: "FunctionCallArgumentsDone {namespace? (guarded)}"
AGG->>AGG: "if ev.Namespace != empty then item.Namespace = ev.Namespace"
IS->>AGG: OutputItemDone
AGG->>AGG: "buildResponse() with Item{Name, Namespace, Arguments}"
Reviews (2): Last reviewed commit: "fix: preserve namespace in function call..." | Re-trigger Greptile |
|
已补充 aggregator 在 |
* fix: preserve Responses function call namespace * fix: preserve namespace in function call done aggregation
修复 OpenAI Responses 流式响应中
function_call.namespace丢失问题概述
这个 PR 修复 AxonHub 在 OpenAI Responses API 转换链路中丢弃
function_call.namespace字段的问题。此前,上游 provider 返回的 Responses
function_callitem 中可以正常包含namespace,但经过 AxonHub 的解析、内部转换、流式转发或最终聚合后,该字段会被丢弃。对于依赖 namespace tools 的客户端来说,这会导致工具调用无法正确路由。例如模型实际调用的是
mcp__gitnexus.query,但客户端最终只收到裸函数名query,无法判断它属于哪个 namespace。问题表现
请求体中的 namespace tool 是正确的:
{ "type": "namespace", "name": "mcp__gitnexus", "tools": [ { "type": "function", "name": "query" } ] }上游 provider 返回的
function_call也包含 namespace:{ "type": "function_call", "name": "query", "namespace": "mcp__gitnexus", "call_id": "call_xxx" }但修复前 AxonHub 返回或保存的结果会变成:
{ "type": "function_call", "name": "query", "call_id": "call_xxx" }缺少
namespace后,客户端无法把该调用分发到mcp__gitnexus.query。修改内容
本 PR 做了以下调整:
llm.FunctionCall添加Namespace字段;Item添加Namespace字段;StreamEvent添加Namespace字段;response.output[]中输出。验证
我使用 streaming
/v1/responses请求和 namespace tool 复现了该问题。修复前,数据库中保存的 function call 类似:
使用本补丁重新构建 AxonHub Docker 镜像后,数据库记录变为:
随后客户端可以正确路由 GitNexus MCP 工具调用。
兼容性
这个修改不应该影响普通非命名空间 function call。
namespace是可选字段,空值时会继续通过omitempty省略;普通 function call 的返回结构保持不变。