Skip to content

fix(agent): recover unknown tool calls before they abort the turn - #273

Open
PsiACE wants to merge 2 commits into
mainfrom
fix/unknown-tool-recovery
Open

fix(agent): recover unknown tool calls before they abort the turn#273
PsiACE wants to merge 2 commits into
mainfrom
fix/unknown-tool-recovery

Conversation

@PsiACE

@PsiACE PsiACE commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Why

The model can call a tool that does not exist (a hallucinated name). The resolver used to raise there, so the whole turn stopped before any hook ran.

What

  • The resolver only parses (name, arguments), no resolve or decision.
  • ToolExecutor.execute_async takes (name, args) plus the available tools, builds the tool map, and routes each call through the hooks.
  • Unknown names go to before_tool_call, where the builtin impl replaces them with a tool_result listing the available tools so the model can re-issue. after_tool_call still observes.
  • Without hooks, the executor raises a clear Unknown tool name error instead of crashing.

Net effect: the model loop keeps running and the model corrects its own call.

Notes

  • ToolExecutor.execute_async changed signature: pass (name, args) and tools=.
  • 272 tests pass.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 10, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bub 5173100 Commit Preview URL

Branch Preview URL
Aug 10 2026, 03:57 PM

The model can emit a tool name outside the agent tool set. tool_invocation_from_native used to raise there, ending the turn before any hook could react.

Now an unknown name resolves to a placeholder Tool and flows through ToolExecutor, where the builtin before_tool_call replaces it with a tool_result listing the available tools so the model can re-issue. after_tool_call still observes the outcome. No signature changes outside the new hooks.
@PsiACE
PsiACE force-pushed the fix/unknown-tool-recovery branch from 4cc6ca4 to be8b31b Compare August 10, 2026 15:51
@PsiACE
PsiACE marked this pull request as ready for review August 10, 2026 15:57
@PsiACE
PsiACE requested a review from frostming August 10, 2026 15:57
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.

1 participant