Repository navigation
Anthropic: opt-in server-side web_search / web_fetch tools - #145
Conversation
When the agent is talking to Claude (Anthropic provider), Anthropic
will run web_search / web_fetch on its own infrastructure if we
register the corresponding server-tool entries in the request's
tools array. Claude stitches results into the response with no
round-trip back through PasClaw's tool loop — no SearXNG or curl on
the operator's box, no User-Agent bot blocks, fewer API hops.
Opt-in via config.json:
"anthropic_server_tools": {
"web_search": true,
"web_fetch": true,
"web_search_max_uses": 5
}
Off by default — operators who configured a local web_search
provider (SearXNG, Brave, Tavily) keep the existing path. Other
providers (OpenAI, Gemini) ignore the flag entirely; the toggles
sit on the Anthropic provider record.
Tool entries use the GA _20260209 versions — dynamic filtering is
built in, no beta header required. Optional max_uses bounds how
many times Claude may call the tool per turn (0 = Anthropic
default).
When a server tool is active, BuildRequest drops any user-registered
tool whose name collides (web_search, web_fetch) so we don't 400
with "tools[*].name: duplicate". This is what lets an operator flip
the flag on without separately running `--no-tools` or surgically
unregistering the local web_search.
Smoke + the new BuildRequest test pass; the existing test-hashline
and test-toolview failures predate this change (verified by
stash-and-rerun on the prior tip).
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3ff51fa899
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if ServerTools.WebSearch then | ||
| begin | ||
| ToolObj := TJsonObject.Create; | ||
| ToolObj.PutStr('type', 'web_search_20260209'); |
There was a problem hiding this comment.
Continue paused server-tool turns
When this server-side web tool is enabled, Anthropic may return stop_reason: "pause_turn" for a long-running web search/fetch and requires the paused assistant content to be sent back unchanged in a follow-up request (see https://platform.claude.com/docs/en/agents-and-tools/tool-use/server-tools#the-server-side-loop-and-pause_turn). In the inspected tool loop, a response with no client ToolCalls exits immediately, so a pause_turn from these newly enabled server tools is surfaced as the final answer instead of being continued, leaving users with an incomplete response for those searches/fetches.
Useful? React with 👍 / 👎.
Codex P2: when one of the newly-registered server tools
(web_search_20260209 / web_fetch_20260209) runs long enough to hit
Anthropic's server-side 10-iteration ceiling, the API returns
stop_reason: "pause_turn" with the partial assistant content. The
tool loop saw zero client ToolCalls and exited cleanly, surfacing
the half-done answer to the user. The PR body called this a known
follow-up; Codex was right to push back — once these tools are on,
pause_turn is the path that fires on any non-trivial search.
Fix lives entirely inside TAnthropicProvider.Chat. After each POST:
- on stop_reason != pause_turn → return as before
- on pause_turn → build a follow-up body that appends the prior
response's content array verbatim as a new assistant turn, POST
again, accumulate. Anthropic detects the trailing server_tool_use
block and resumes its server-side loop where it paused.
Continuation is capped at 5 rounds so a runaway server-side loop
can't spend forever on a single agent turn. Text content is
concatenated across rounds; ToolCalls / FinishReason / Usage come
from the final round (intermediate rounds are pause_turn and carry
no client ToolCalls).
ContinuePausedTurn is exposed in the interface so the wire-shape
logic gets direct test coverage; the helper that parses the bodies
swallows EPasClawJSON and returns nil to keep the malformed-input
path graceful.
Two new tests:
- TestContinuePausedTurnAppendsAssistantBlock — happy path
- TestContinuePausedTurnHandlesMalformedInput — returns ''
Summary
When the agent is talking to Claude (Anthropic provider), the request can declare Anthropic's server-side
web_search_20260209/web_fetch_20260209tools. Claude runs the queries / fetches on its own infrastructure and stitches results into the response — no round-trip through PasClaw's tool loop, no SearXNG or curl on the operator's box, no User-Agent bot blocks.Opt-in via
config.json:Off by default — operators with a working local
web_searchprovider (SearXNG, Brave, Tavily) keep that path. Other providers (OpenAI, Gemini) ignore the flag entirely; the toggles sit on the Anthropic provider record only.Implementation notes
_20260209versions — noanthropic-betaheader required; dynamic filtering of search results is built in. Optionalmax_usesbounds how many times Claude may call the tool per turn (0 = Anthropic default).BuildRequestdrops any user-registered tool whose name collides (web_search,web_fetch) so the request doesn't 400 withtools[*].name: duplicate. This lets an operator flip the flag without separately unregistering the local tool.cache_controlmarker stays on the trailing entry whether that's a user tool or a server tool.Test plan
make test-anthropic-server-tools— four wire-shape cases (off, search-only, both + max_uses, collision-drop)make smoke— every top-level CLI command still launchesANTHROPIC_API_KEY, flip both flags on inconfig.json, hitpasclaw agent "what's the latest CVE on CVE.org?"and confirm Claude runs the search server-side (no localweb_searchlog entry, response text references current results)Not in this PR (follow-ups)
pasclaw onboarddoesn't yet prompt for the toggles — editconfig.jsondirectly.stop_reason: "pause_turn"(Anthropic's server-side 10-iteration cap) falls through toend_turnsemantics. Rare in practice; can wire proper round-trip later if the cap actually bites.https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
Generated by Claude Code