Skip to content

Commit b075c93

Browse files
author
hzq
committed
Preserve Responses history when caller tools change
Keep the original function declarations and ordered native items, while restricting new calls to the active tools. Append newly available published functions after their confirmed return and require a worker that advertises the matching Responses codec. Improvement-Round: 7/10 after v0.0.73
1 parent eade0cb commit b075c93

21 files changed

Lines changed: 1000 additions & 127 deletions

‎docs/harness.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ Key points:
167167
- Only a valid return with new results can change the run to `tool_choice: "none"`. A bad batch or read-only replay leaves the option and output position unchanged. If storage cannot confirm a return, inspect the original run ID rather than executing the caller tools again.
168168
- On an Anthropic Messages continuation the historical tool declarations and the currently callable tools are distinct. If no tools remain active, the worker keeps the verified declarations for the same provider and sends `tool_choice: {"type":"none"}`. A fresh request without caller tools does not gain any. The kernel checks the entire new plan before opening a step or caller action; earlier accepted results are not undone.
169169
- After a forced caller turn, eligible published tools can return. Plain text and ordinary `tool_use` blocks are checked against their original prefix and replayed unchanged. For a signed or otherwise opaque history that needs tools individually added or withdrawn, enable `anthropicInlineToolChanges` **only on a supporting endpoint/model**. The worker appends the protocol's tool changes after the result; without that option it interrupts with `provider_state_unsupported` rather than rewriting history. Resume the original run after restoring support, not the caller tool. The [Anthropic guidance](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking/change-tools-or-instructions) distinguishes turning tools off from changing their declarations.
170+
- With the **OpenAI Responses provider**, disabling caller tools keeps the original declarations and ordered reasoning, function calls and confirmed results. The worker sends `tool_choice: "none"` if nothing is callable, or [`allowed_tools`](https://developers.openai.com/api/docs/guides/function-calling) to restrict the existing catalog. When a published function first becomes available after a forced caller turn, the worker appends a developer [`additional_tools` item](https://developers.openai.com/api/docs/guides/tools-tool-search#add-tools-at-a-specific-point-in-the-input) after the return. This requires endpoint support; a rejection does not trigger another request with stripped history. Inspect the original run instead of executing the caller tool again. A model-returned declaration is not execution permission.
170171
- Streaming (`stream: true`): when the run parks, the frames are sent in this order: the role frame (with `content: null`, if one has not been sent before), one `tool_calls` delta frame per call (`index` starting at 0), the closing frame with `finish_reason: "tool_calls"`, then (if `include_usage` was requested) the usage frame and `[DONE]`. After continuation, the stream starts from where the last one ended and does not replay earlier text.
171172
- When the arguments the model produces do not match the caller's schema, the call is not handed to the caller. Instead `{"error":"invalid_arguments","detail":...}` is returned to the model as the tool result so that it can fix the call and try again. This differs from argument errors of published tools (`invalid_tool_arguments`, where the run fails outright): the caller's schema is not under the publisher's control.
172173
- Names: must match `^[a-zA-Z0-9_-]{1,64}$`. The internal alias replaces `-` with `_` and prepends `t_` when the first character is not a letter; the original name is always used externally. A conflict with a published tool, workflow, delegate, `execute_graph`, or another caller tool returns `client_tool_conflict`; more than 100 published tools plus caller tools returns `client_tools_too_many`; a schema that cannot be compiled returns `invalid_client_tool`. All of these are checked before any execution. Caller tools cannot appear in `execute_graph` or in workflows.

‎docs/protocol.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,9 @@ Revocation is not remote process attestation, deletion of previously transferred
420420

421421
Model `Work` may carry an optional `maxOutputTokens` (the caller's output cap, always below the published `limits.maxOutputTokens`); a worker applies the smaller of the two to the model call, and an older worker that ignores it uses the published limit. The agent definition itself stays identical to the published one.
422422

423-
`welcome.features` is now `execution-capabilities-v1`, `byok-v1`, `sandbox-v1`, `provider-turn-v1`, `bridge-tool-replay-v1`, `client-tools-v1`, `image-input-v1`, `trace-context-v1`, `conversion-profiles-v1` (and `/health` additionally advertises `prometheus-metrics-v1` for `GET /metrics` and `trace-context-v1` for W3C `traceparent` / `tracestate` propagation). With `trace-context-v1` a worker accepts `WorkContext.trace` and `WorkContext.subject` (stripped automatically when dispatching to legacy workers); with `conversion-profiles-v1` a worker includes `execution.adapterProfiles` so custom remote `adapter/<name>` entries expose their real `ConversionProfile` on the gateway. With `image-input-v1` a worker reports `execution.imageInput = { providers: {<name>: "none"|"inline"|"url"}, native: {<engine>: "native"|"agent-declared"|"workspace-file"} }`; a run with images is placed only on a worker whose declaration covers its provider or engine (placement reason `image_input_unsupported`), so older workers never receive one ([images.md](images.md)). With `client-tools-v1` a worker reports `execution.clientTools = { native: ["kernel", "codex", "claude", "adapter/<acp name>", …] }`: the engines on which it can bridge caller tools (docs/harness.md). Bridged runs are placed only on workers that declared the run's engine there (placement reason `client_tools_unsupported` otherwise); when no such worker exists, submission answers `client_tools_bridge_unsupported` (400). Only those workers receive `Work.native.clientTools` and send the `client_tool` event (`data: { name, arguments, relay_call_id }`), which the gateway answers like an approval with `{ output }` or `{ error }`. Older workers and older gateways keep working; an older worker simply never receives bridged work. Every update is validated against the same node identity and credential grants as the initial registration. Idle peers also lose their registration when heartbeats expire.
423+
`welcome.features` is now `execution-capabilities-v1`, `byok-v1`, `sandbox-v1`, `provider-turn-v1`, `bridge-tool-replay-v1`, `bridge-tool-replay-v2`, `client-tools-v1`, `image-input-v1`, `trace-context-v1`, `conversion-profiles-v1` (and `/health` additionally advertises `prometheus-metrics-v1` for `GET /metrics` and `trace-context-v1` for W3C `traceparent` / `tracestate` propagation). With `trace-context-v1` a worker accepts `WorkContext.trace` and `WorkContext.subject` (stripped automatically when dispatching to legacy workers); with `conversion-profiles-v1` a worker includes `execution.adapterProfiles` so custom remote `adapter/<name>` entries expose their real `ConversionProfile` on the gateway. With `image-input-v1` a worker reports `execution.imageInput = { providers: {<name>: "none"|"inline"|"url"}, native: {<engine>: "native"|"agent-declared"|"workspace-file"} }`; a run with images is placed only on a worker whose declaration covers its provider or engine (placement reason `image_input_unsupported`), so older workers never receive one ([images.md](images.md)). With `client-tools-v1` a worker reports `execution.clientTools = { native: ["kernel", "codex", "claude", "adapter/<acp name>", …] }`: the engines on which it can bridge caller tools (docs/harness.md). Bridged runs are placed only on workers that declared the run's engine there (placement reason `client_tools_unsupported` otherwise); when no such worker exists, submission answers `client_tools_bridge_unsupported` (400). Only those workers receive `Work.native.clientTools` and send the `client_tool` event (`data: { name, arguments, relay_call_id }`), which the gateway answers like an approval with `{ output }` or `{ error }`. Older workers and older gateways keep working; an older worker simply never receives bridged work. Every update is validated against the same node identity and credential grants as the initial registration. Idle peers also lose their registration when heartbeats expire.
424424

425-
With `bridge-tool-replay-v1` a worker may also advertise `execution.bridgeReplayProviders`. Only an eligible worker with this provider-specific capability receives a history-sensitive caller-tool transition. Older peers still handle ordinary turns; when an upgrade is needed, the confirmed caller result stays on the original run.
425+
With `bridge-tool-replay-v1`, `execution.bridgeReplayProviders` covers Anthropic Messages only. A worker that also negotiates `bridge-tool-replay-v2` can report the codec for each provider alias in `execution.bridgeReplayProtocols` (for example, `{"local":"openai-responses"}`). A Responses transition requires an exact match; a v1 claim for the same alias is not enough. Older peers can still handle ordinary turns. If no eligible worker can replay the change, the run is interrupted with `provider_state_unsupported`; resume that run after upgrading rather than resubmitting its confirmed tool result.
426426

427427
Native execution requires the node credential to grant `native/<engine>` (or `*`), in addition to the agent alias. `oaa expose` already grants only its selected native executor. A generic adapter uses `native/adapter/<name>`. Enabled native executables are checked for local availability without starting them; declared model mappings are still not proof of account/model compatibility.
428428

@@ -756,7 +756,7 @@ Error codes and response shapes do not depend on language; only the text of `mes
756756
| `client_tool_conflict` | 400 | A bridged caller tool has the same name as a published tool, workflow, delegate, `execute_graph`, or another caller tool (the internal alias is compared) |
757757
| `client_tools_too_many` | 400 | Published tools plus caller tools exceed 100 |
758758
| `invalid_client_tool` | 400 | A caller tool's name does not match `^[a-zA-Z0-9_-]{1,64}$`, its format is wrong, or its parameter schema cannot be compiled |
759-
| `tool_choice_unmet` | 422 | An Anthropic native bridge plan did not match the forced caller-tool selection, or a bridged external agent did not meet that selection after a correction round |
759+
| `tool_choice_unmet` | 422 | An Anthropic Messages or OpenAI Responses native bridge plan did not match the forced caller-tool selection, or a bridged external agent did not meet that selection after a correction round |
760760
| `output_schema_unsupported` | 400 | The requested output schema (`response_format`, `text.format`, `responseSchema`, `output_config.format`) contains something the gateway cannot honestly enforce: `$async`, a `$ref` outside the document, a `format` nobody implements, a very long or exponentially backtracking regular expression, nesting deeper than 40 levels; rewrite the schema |
761761
| `invalid_json` | 400 | The request body is not valid JSON, or is empty while declared as JSON |
762762
| `payload_too_large` | 413 | The request body or data exceeds the size limit |

‎docs/zh-CN/harness.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ Responses(`/v1/compat/responses`)与 Gemini(`tools[].functionDeclarations`
167167
- 只有包含新结果的有效回传才能把原运行改为 `tool_choice: "none"`。无效批次和只读重试都不会更改选项或输出位置。存储暂时不能确认回传时,请按原运行 ID 检查,不要重新执行调用方工具。
168168
- Anthropic Messages 续接时,历史工具声明不等于本轮执行许可。若本轮已无可执行工具,worker 只向原提供方重发已核验的声明,并显式发送 `tool_choice: {"type":"none"}`;从未声明这些工具的新请求不会获得它们。内核会先检查整批新计划,再创建步骤或调用方待办;已经受理的结果不撤销。
169169
- 首轮强制调用结束后,符合条件的已发布工具可以恢复。普通文本和标准 `tool_use` 块按原请求前缀核验,内容原样重放。若历史含签名或其他不透明内容,又需要单独增减工具,**仅在端点与模型支持时**开启 `anthropicInlineToolChanges`。worker 将工具变更加在结果之后;未开启时以 `provider_state_unsupported` 中断,不改写历史。恢复支持后继续原运行,不要重做调用方工具。[Anthropic 官方说明](https://platform.claude.com/docs/en/build-with-claude/preserved-thinking/change-tools-or-instructions)区分了临时禁用工具和修改工具声明。
170+
- 使用 **OpenAI Responses 提供方**时,禁用调用方工具不会删除原始声明,也不会重排推理条目、函数调用和已确认的结果。没有可用工具时发送 `tool_choice: "none"`;仅能使用部分工具时用 [`allowed_tools`](https://developers.openai.com/api/docs/guides/function-calling) 限定范围。若首轮强制调用结束后有已发布函数首次可用,worker 在返回结果后追加开发者角色的 [`additional_tools` 条目](https://developers.openai.com/api/docs/guides/tools-tool-search#add-tools-at-a-specific-point-in-the-input)。端点必须支持该条目;若被拒绝,网关不会删减历史再发请求。查看原运行,不要重新执行调用方工具。模型回传的声明不是执行许可。
170171
- 流式(`stream: true`):停车时依次发出角色帧(之前没发过时,`content: null`)、每个调用一帧 `tool_calls` 增量(`index` 从 0 起)、`finish_reason: "tool_calls"` 收尾帧、(请求了 `include_usage` 时)用量帧与 `[DONE]`;续接后的流从上次之后开始,不重放之前的文本。
171172
- 模型给出的参数不符合调用方的 schema 时,这次调用不会交给调用方,而是把 `{"error":"invalid_arguments","detail":...}` 作为工具结果交回模型,让它改了再调。这与已发布工具的参数错误(`invalid_tool_arguments`,运行直接失败)不同:调用方的 schema 不受发布者控制。
172173
- 名字:须匹配 `^[a-zA-Z0-9_-]{1,64}$`;内部别名把 `-` 换成 `_`,首字符不是字母时加 `t_`,对外一律用原名。与已发布的工具、工作流、委托、`execute_graph` 或另一个调用方工具冲突报 `client_tool_conflict`;已发布工具加调用方工具超过 100 个报 `client_tools_too_many`;schema 无法编译报 `invalid_client_tool`。这些都在任何执行之前检查。调用方工具不能出现在 `execute_graph` 与工作流里。

0 commit comments

Comments
 (0)