Skip to content

Commit eade0cb

Browse files
author
hzq
committed
Resume Anthropic bridge runs across verified tool policy changes
Verify historical declarations separately from the current tool offer. Preserve accepted results on restart, reject disallowed plans before dispatch, and negotiate replay support with workers. Improvement-Round: 6/10 after v0.0.73
1 parent 9991ca5 commit eade0cb

33 files changed

Lines changed: 1465 additions & 188 deletions

‎docs/compatibility.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ A request that declares `tools` and chooses no mode is handled as `auto` (docs/h
110110

111111
* An agent that can take the tools over (a kernel agent, Codex, Claude Code, Antigravity ACP, or an ACP adapter) gets them: its calls come back as `tool_calls` / `function_call` / `tool_use` / `functionCall`, the run continues from your results, and the response carries `X-OAA-Client-Tools: bridge`. This is what coding agents and agent frameworks (Cline, Roo Code, Continue, Zed, the OpenAI Agents SDK, LangChain, the Vercel AI SDK, ...) need, on the ordinary Base URL, without a header.
112112
* An agent that cannot (DSH, A2A, HTTP adapters) behaves as before. OpenAI's default endpoints refuse with `400 unsupported_parameter` (`error.param` `tools`; the message gives the reason and the three ways out: the Base URL `http://<host>:8787/v1/compat`, `X-OAA-Compat: true`, `X-OAA-Client-Tools: managed`); the compat endpoints, Claude and Gemini let the agent finish with its own tools (`X-OAA-Client-Tools: ignored`).
113-
* Tool choice (`tool_choice` `auto` / `none` / `required` / a named function, Claude `tool_choice`, and Gemini `toolConfig.functionCallingConfig`) is honoured: `none` withholds caller tools for the turn; forced choices push down natively to kernel model drivers (converging back to `auto` on continuation) and enforce prompt + 1-round continuation repair on bridged external agents (failing with `422 tool_choice_unmet` if unmet, or `400 client_tools_unsupported` when `managed` / unbridgeable).
113+
* Tool choice (`tool_choice` `auto` / `none` / `required` / a named function, Claude `tool_choice`, and Gemini `toolConfig.functionCallingConfig`) is honoured: `none` disables caller-tool execution for the turn (see [historical declarations](harness.md) for Anthropic continuations); forced choices push down natively to kernel model drivers (converging back to `auto` on continuation) and enforce prompt + 1-round continuation repair on bridged external agents (failing with `422 tool_choice_unmet` if unmet, or `400 client_tools_unsupported` when `managed` / unbridgeable).
114114
* `X-OAA-Client-Tools: managed | bridge | reject | auto` (or `metadata["oaa.client_tools"]`) chooses explicitly and is never overridden; the gateway setting `clientTools.default` changes what a request that chooses nothing gets.
115115

116116
## Structured output

‎docs/harness.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ For discovery, model selection and multi-model execution see [models.md](models.
4848

4949
A request that declares tools and chooses no mode gets `auto` (the gateway configuration `clientTools.default` can change that default to `managed`, `bridge` or `reject`; an explicit `auto` in the header beats the configuration). The rule, with the agent known at submit time:
5050

51-
1. The agent can take the tools over (kernel agent, or an enabled Codex, Claude Code, Antigravity ACP, or ACP adapter with an online execution machine that declared `client-tools-v1` for it), and the tools are plain functions with names that do not collide with the agent's own: the request is handled as `bridge` (`tool_choice: "none"` withholds caller tools for that turn; forced `tool_choice` is pushed down to kernel model drivers or enforced on bridged external agents via prompt constraint plus up to 1 continuation repair round, failing with 422 `tool_choice_unmet` if still unmet). The response carries `X-OAA-Client-Tools: bridge`; the agent's calls come back as `tool_calls` / `function_call` / `tool_use` / `functionCall`.
51+
1. The agent can take the tools over (kernel agent, or an enabled Codex, Claude Code, Antigravity ACP, or ACP adapter with an online execution machine that declared `client-tools-v1` for it), and the tools are plain functions with names that do not collide with the agent's own: the request is handled as `bridge` (`tool_choice: "none"` disables caller tools for that turn; forced `tool_choice` is pushed down to kernel model drivers or enforced on bridged external agents via prompt constraint plus up to 1 continuation repair round, failing with 422 `tool_choice_unmet` if still unmet). The response carries `X-OAA-Client-Tools: bridge`; the agent's calls come back as `tool_calls` / `function_call` / `tool_use` / `functionCall`.
5252
2. Anything else gets what the entry did before. If a forced `tool_choice` (`required` / `any` or a named function) cannot be bridged (or `managed` was chosen), submission fails with 400 `client_tools_unsupported`. Otherwise OpenAI's default endpoints (`/v1/chat/completions`, `/v1/responses` without `X-OAA-Compat`) refuse with 400 `unsupported_parameter` (`error.param` `tools`): the message says this agent cannot take the tools over, gives the reason (an engine without bridge support, no execution machine for client tools, a name collision, tools that are not functions), and names the three ways out: the Base URL `<origin>/v1/compat`, `X-OAA-Compat: true`, `X-OAA-Client-Tools: managed`. The compatibility endpoints, Claude Messages and Gemini continue as `managed` (the agent finishes with its own tools; `X-OAA-Client-Tools: ignored`).
5353

5454
Legacy integrations retain this auto-selection rule. DSH, A2A and HTTP native/adapter entries remain managed-only; Codex, Claude Code, ACP adapters, and Antigravity's capability-checked ACP path support `bridge`. Selecting auto never grants additional approval authority. New publication and key policies take precedence as described above.
@@ -165,6 +165,8 @@ Key points:
165165
- The final check includes the actual system prompt for that route. If the request does not fit, already completed steps remain recorded, but no new model attempt is saved or sent. At handoff the worker request must still match the admitted conversation; the byte count and digest used for that check are not recorded in public run events.
166166
- A newly returned tool plan must also leave room for the assistant message and **one empty reply per call**, including the call IDs. If even this minimum cannot fit, the kernel does not run a tool, ask for approval, or hand the call to a client. The model turn, its reported usage and already produced output are retained; its rejected arguments are not saved as pending work. A plan that fits can still receive a larger result later. Already accepted calls, including those restored after an upgrade, follow the normal result and recovery paths. A final answer without tools needs no further turn.
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.
168+
- 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.
169+
- 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.
168170
- 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.
169171
- 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.
170172
- 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/models.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ your workspace address if your models accept streamed tool calls.
126126
| `imageInput` | `none`, `inline` or `url` ([images.md](images.md)) |
127127
| `preset` | New. The preset the entry came from (informational) |
128128
| `byok`, `timeoutMs`, `anthropicVersion` | Unchanged |
129+
| `anthropicInlineToolChanges` | Anthropic Messages only, off by default. Permit `inline-tools-2026-09-15` for verified tool changes in a native bridge continuation. Not needed just to turn all tools off. See [caller tools](harness.md). |
129130

130131
## `oaa models`
131132

‎docs/protocol.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +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`, `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`, `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.
424+
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.
424426

425427
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.
426428

@@ -754,7 +756,7 @@ Error codes and response shapes do not depend on language; only the text of `mes
754756
| `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) |
755757
| `client_tools_too_many` | 400 | Published tools plus caller tools exceed 100 |
756758
| `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 |
757-
| `tool_choice_unmet` | 422 | A forced `tool_choice` (`required`, `any`, or a named function) was requested in bridge mode, but the external agent still did not invoke the required caller tool after a correction round |
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 |
758760
| `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 |
759761
| `invalid_json` | 400 | The request body is not valid JSON, or is empty while declared as JSON |
760762
| `payload_too_large` | 413 | The request body or data exceeds the size limit |
@@ -964,7 +966,7 @@ Error codes and response shapes do not depend on language; only the text of `mes
964966
| `invalid_provider_state` | 502 | The provider's native turn state (Provider Turn State) is missing, malformed, failed verification, does not match the normalized result, or the underlying SDK cannot replay it safely; this indicates corrupted or tampered state, and the caller should start a new session |
965967
| `provider_state_mismatch` | 409 | The provider protocol, endpoint, model, tools, or conversation prefix changed on continuation, or native state was replayed across incompatible protocols; the caller must restore the original configuration or start a new session |
966968
| `provider_state_too_large` | 413 | One turn's native state exceeds 2,000,000 bytes of UTF-8 JSON. The checked state is the snapshot used for replay. Trim the turn's output or tool data, or start a new session. |
967-
| `provider_state_unsupported` | 502/503 | The worker node or driver cannot keep the provider's native turn state, the gateway did not negotiate native-state capability, or the streamed output contains state deltas that cannot be kept safely; the caller must route to a supported node or start a new session |
969+
| `provider_state_unsupported` | 502/503 | The worker node or driver cannot keep the provider's native turn state, the gateway did not negotiate native-state capability, or the streamed output contains state deltas that cannot be kept safely, or the required bridge replay / inline tool-change capability is unavailable; the caller must route to a supported node or start a new session |
968970

969971
### Native agents and adapters (including ACP)
970972

‎docs/zh-CN/compatibility.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Base URL 写错是 404 最常见的原因。网关现在忽略末尾斜杠与重
110110

111111
* 能接管工具的智能体(内核智能体、Codex、Claude Code、Antigravity ACP 或 ACP 适配器智能体)拿到它们:它的调用以 `tool_calls` / `function_call` / `tool_use` / `functionCall` 交回,运行从你回传的结果接着做,响应带 `X-OAA-Client-Tools: bridge`。编码代理和智能体框架(Cline、Roo Code、Continue、Zed、OpenAI Agents SDK、LangChain、Vercel AI SDK 等)需要的正是这个,用普通的 Base URL,不用任何请求头。
112112
* 接管不了的智能体(DSH、A2A、HTTP 适配器)照旧。OpenAI 默认端点返回 `400 unsupported_parameter`(`error.param` 是 `tools`;信息给出原因和三条出路:Base URL 用 `http://<主机>:8787/v1/compat`、`X-OAA-Compat: true`、`X-OAA-Client-Tools: managed`);兼容端点、Claude 与 Gemini 让智能体用自己的工具完成(`X-OAA-Client-Tools: ignored`)。
113-
* 工具选择策略(OpenAI 的 `tool_choice` `auto` / `none` / `required` / 具名函数、Claude 的 `tool_choice`、Gemini 的 `toolConfig.functionCallingConfig`)已正式生效:`none` 本轮不暴露调用方工具;强制调用对内核模型驱动原生下推(续接轮自动收敛回 `auto`),对桥接外部智能体实施提示约束加最多 1 轮续接纠正(未满足时报 `422 tool_choice_unmet`,在 `managed` 或不支持桥接的目标上报 `400 client_tools_unsupported`)。
113+
* 工具选择策略(OpenAI 的 `tool_choice` `auto` / `none` / `required` / 具名函数、Claude 的 `tool_choice`、Gemini 的 `toolConfig.functionCallingConfig`)已正式生效:`none` 本轮禁止调用调用方工具(Anthropic 续接可能仍需重放[历史声明](harness.md));强制调用对内核模型驱动原生下推(续接轮自动收敛回 `auto`),对桥接外部智能体实施提示约束加最多 1 轮续接纠正(未满足时报 `422 tool_choice_unmet`,在 `managed` 或不支持桥接的目标上报 `400 client_tools_unsupported`)。
114114
* `X-OAA-Client-Tools: managed | bridge | reject | auto`(或 `metadata["oaa.client_tools"]`)显式选择,永远不被覆盖;网关设置 `clientTools.default` 改变「什么都没选」的请求得到什么。
115115

116116
## 结构化输出

0 commit comments

Comments
 (0)