Skip to content

Anthropic: opt-in server-side web_search / web_fetch tools - #145

Merged
FMXExpress merged 2 commits into
mainfrom
claude/nice-dirac-sBwXK
Jun 5, 2026
Merged

FMXExpress merged 2 commits into
mainfrom
claude/nice-dirac-sBwXK

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

Summary

When the agent is talking to Claude (Anthropic provider), the request can declare Anthropic's server-side web_search_20260209 / web_fetch_20260209 tools. 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:

"anthropic_server_tools": {
  "web_search": true,
  "web_fetch": true,
  "web_search_max_uses": 5
}

Off by default — operators with a working local web_search provider (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

  • GA _20260209 versions — no anthropic-beta header required; dynamic filtering of search results is built in. Optional max_uses bounds how many times Claude may call the tool per turn (0 = Anthropic default).
  • Collision handling. When a server tool is on, BuildRequest drops any user-registered tool whose name collides (web_search, web_fetch) so the request doesn't 400 with tools[*].name: duplicate. This lets an operator flip the flag without separately unregistering the local tool.
  • Cache breakpoint tracks effective last-tool index so the existing cache_control marker 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 launches
  • Full FPC build clean — no new warnings on touched units
  • Live exercise: set ANTHROPIC_API_KEY, flip both flags on in config.json, hit pasclaw agent "what's the latest CVE on CVE.org?" and confirm Claude runs the search server-side (no local web_search log entry, response text references current results)

Not in this PR (follow-ups)

  • pasclaw onboard doesn't yet prompt for the toggles — edit config.json directly.
  • stop_reason: "pause_turn" (Anthropic's server-side 10-iteration cap) falls through to end_turn semantics. Rare in practice; can wire proper round-trip later if the cap actually bites.

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon


Generated by Claude Code

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).

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants