mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #4700] [CLOSED] [Engine] Claude Code stops when a tool call comes back as text #5141
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#5141
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/4700
Author: @xrip
Created: 10/30/2026
Status: ❌ Closed
Base:
main← Head:pr/anthropic-tool-search📝 Commits (1)
03310deserve: Anthropic's tool search on /v1/messages (defer_loading, tool_reference) (#4663)📊 Changes
4 files changed (+196 additions, -16 deletions)
View changed files
📝
docs/DETAILS.md(+6 -0)📝
serve/frontend.py(+39 -7)📝
serve/server.py(+12 -9)➕
serve/test_tool_search.py(+139 -0)📄 Description
Problem and result
What you see: Claude Code stops in the middle of a job. Its last message is not a step. It is text like this, and the turn ends (
end_turn):Nothing runs, and Claude Code waits for the user.
Why: the model made a good tool call, but Strata sent it back as answer text, not as a tool call. Strata does this for every tool that is not in the request's
toolslist.Claude Code has tool search on by default when
ANTHROPIC_BASE_URLis set. Then its MCP tools are not intoolsuntil the model loads them withToolSearch. Claude Code only gives their names in the chat. So when the model calls an MCP tool straight away, Claude Code gets only text. It has nothing to run, so it stops. Qwen does this, for example, when a hook names the tool.This is the case Tsury reproduced in #4663 on 0.2.8. We had it 8 times in two days of Claude Code work with Qwen3.8-Flash-Next.
After this PR: the call comes to Claude Code as a tool call. Claude Code runs it, and the job goes on.
Two small fixes on the same path:
ToolSearch, it now sees the tool's description in the answer. Before, the answer was empty.Only requests with tool search change (a tool marked
defer_loadingin the request). All other requests work as before.Related discussion
Refs #4663. This fixes the Claude Code case from Tsury's comment.
It does not change the first report in #4663: Chat Completions, with tools that change between turns. There the client gives no sign that it holds tools back, so a call for a tool that is not in the list stays text, as decided in #3075 and #3796.
Approach
Claude Code expects the server behind
ANTHROPIC_BASE_URLto handledefer_loadingandtool_reference, as Anthropic's API does. This PR follows Anthropic's rules.I ran Claude Code 2.1.314 against a small fake API (no model) and saved what it sends:
ToolSearchand an emptyDeferredToolPlaceholdermarkeddefer_loading: true. MCP tools are only named in the chat.ToolSearch, the answer is atool_referenceto the tool. From then on the tool is intools, markeddefer_loading: true.What changed, only on
/v1/messages:defer_loadingtool, a call for a tool that is not in the list is a tool call. This is so in the answer and in the thinking.defer_loadingtool can be called, but it is not in the tool list at the start of the prompt.tool_referencebecomes the tool's description, in the tool list's form, in the same place. Other references are left out, as before.llama.cpp keeps this from happening: after
<tool_call>it lets the model write only names from the list. Strata does not limit the model's output that way, so that is not part of this PR.Validation
Passed:
python -m unittest serve.test_tool_search -von03310de7(upstream main870aedd9+ this commit), Windows 11, Python 3.14.2, jinja2 3.1.6: 12 tests OK. They test:/v1/messagesroute withMockEngine, and that requests without tool search work as before.03310de7, 174 tests OK:serve.test_tool_search serve.test_frontend serve.test_tool_name_alias serve.test_tool_corpus serve.test_tool_routes serve.test_quoted_call_values serve.test_stop_holdback serve.test_parser_call_scan serve.test_parser_hold serve.test_parser_track serve.test_reasoning_loop_recovery serve.test_reasoning_rescue serve.test_reasoning_tools serve.test_tool_call_envelope serve.test_tool_call_unclosed serve.test_tool_name_space serve.test_anthropic_base_urlserve/suite on03310de7, same Windows machine:python -m unittest discover -s serve -p 'test_*.py' -t ., 1268 tests OK (19 skipped).serve.test_tool_searchandserve.test_frontend, 38 tests OK.Failed:
tool_referenceto an unknown tool. That broketest_frontend'stest_messages_tool_reference_in_a_tool_result_is_left_out, so I took it out.Not run:
serve/changed).Limits
/v1/messages. The first report in #4663 (Chat Completions) stays as it is.tool_choicethat names a held-back tool works likeauto, as it does today for any name not in the list.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.