#6005 [Engine] read tools from Anthropic tool_addition blocks (#5952)

closed · @connorbanting03 · 0 コメント · GitHub で見る

Server & APISecurityLinux

本文

Fixes #5952.

**Problem and result**

Claude Code sends some tools as `tool_addition` blocks in a `role: "system"` message inside `messages`, not in the top-level `tools`. `anthropic_to_messages()` left the block out as an unread type, and `anthropic_tools()` read only the top-level `tools`. So the model never saw these tools, and a call for one would not have been read as a tool call. No error was returned.

With this change, the added tool's definition is in the prompt where the client added it, and a call for it comes back as a `tool_use` with arguments typed from its `input_schema`.

**Approach**

- `tool_addition` is now a read block type. The definition is rendered at the block's position as `<tools>\n{json}\n</tools>`, the same form `_tool_references` uses to load a deferred tool. The prompt's tool list does not change, so the prompt cache keeps its start. The late system message becomes a user message, as before (`_late_system_to_user`).
- `anthropic_tools()` adds the definitions from `tool_addition` blocks to the callable tools, so `OutputParser` gets their schemas. It copies the request's tool list, so the request is not changed.
- These add nothing: a tool already in the prompt's tool list, a repeated addition of the same tool, and a block without a usable definition (no name, or an `input_schema` that is not an object). The last one keeps the old behaviour: left out, with a debug line.
- `cache_control` on the block is ignored, as on other blocks.

**Validation** (revision `5d0a8de` on top of `13eedf5`; Linux, Python 3.14.4, deps from `requirements.txt` + `requirements-dev.txt`, no GPU needed)

Passed:
- The issue's snippet: before, `prompt mentions mcp__docs__batch: False` / `callable tools: ['Read']`. After, `True` / `['Read', 'mcp__docs__batch']`.
- `python -m unittest serve.test_tool_addition -v`: 8 tests OK. With `serve/frontend.py` reverted to `13eedf5`, 7 of the 8 fail. The one that passes on both checks that a malformed block is still left out.
- `python -m unittest discover -s serve -t . -p "test_*.py"`: `Ran 1598 tests in 653.694s, OK (skipped=24)`.

Failed: none observed.

Not run:
- A real Claude Code session that sends `tool_addition` blocks. I pointed Claude Code (`claude -p`) at the patched server (`--engine mock`) and logged each `/v1/messages` request. With `ANTHROPIC_AUTH_TOKEN` it sent 12 top-level tools; with the claude.ai sign-in, over two requests (a scripted `Read` call and its result), it sent 11. No request carried a `tool_addition` block: no connector tools loaded in these non-interactive runs. The real block shape is covered only through the example in the issue.
- A real model on a GPU. This change is in the Python request conversion only; the engine is not touched.

**Limits**

- Only `tool_addition` is handled. I did not see or implement any matching removal block.
- An added tool stays callable for the rest of the request even if it was added late in the conversation. That matches how a loaded deferred tool behaves.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01GKfvqPVRo2K8QSAj7LHdE4

関連リンク

インストール・モデル・リリースへのサイト内リンク。