Skip to content

Report unhandled client tool calls to the application - #931

Merged
kraenhansen merged 1 commit into
mainfrom
sdk-parity/align/grp_675b2a
Nov 13, 2026
Merged

kraenhansen merged 1 commit into
mainfrom
sdk-parity/align/grp_675b2a

Conversation

@elevenlabs-triaging

Copy link
Copy Markdown
Contributor

Aligns the Python SDK with the cross-SDK parity tracker (MATRIX.md), group grp_675b2a.

Statement

  • stmt_b3780c Notifies the application of a client tool call for which no handler is registered.

Gap (elevenlabs-python)

ClientTools.handle raises ValueError for an unknown tool name, execute_tool catches it, and the only reaction is the is_error client_tool_result sent to the agent over the websocket. The application has no way to observe the call.

SDKs this follows

All three expose an optional onUnhandledClientToolCall callback that receives the client_tool_call payload when its tool_name has no registered handler:

The references differ on what the agent gets back: js-client skips the error client_tool_result when the callback is set, while Kotlin still sends one. The statement doesn't observe that, and the agent-facing result is tracked separately as stmt_119917. So this PR keeps Python's existing error result unchanged, like Kotlin does.

What changed

  • Conversation and AsyncConversation accept a new optional keyword argument, callback_unhandled_client_tool_call. It is synchronous on Conversation and async on AsyncConversation, like the other callbacks. When a client_tool_call arrives for a tool name that isn't registered in client_tools, it is called with the raw client_tool_call dict (tool_name, tool_call_id, parameters, expects_response). The callback runs after the error result has been scheduled, so an exception in the callback can't stop the agent's error result.
  • ClientTools.is_registered(tool_name) checks the registry under the existing lock.
  • A README section documents the callback.

The change is backward compatible: the callback defaults to None, and without it behaviour is unchanged. Only hand-maintained files listed in .fernignore are touched.

Testing

  • New tests/test_convai_unhandled_client_tool.py covers sync and async. The callback fires once with the payload for an unregistered tool, the agent still gets its is_error result, and a registered tool doesn't trigger the callback. All three tests fail without the change.
  • poetry run pytest .: 376 passed (Python 3.12).
  • poetry run mypy .: no issues.
  • poetry run python tests/verify_types.py: passes.
  • I didn't run the CI matrix's Python 3.8, 3.13 and 3.14 locally. The change uses no syntax newer than 3.8.

Opened by the nightly SDK parity aligner.

Add callback_unhandled_client_tool_call to Conversation and
AsyncConversation. It receives the client_tool_call payload when the
agent calls a client tool with no handler registered in ClientTools.
The agent still receives the existing is_error client_tool_result.

Co-authored-by: kraen <[email protected]>
@elevenlabs-triaging elevenlabs-triaging Bot added the parity Part of the cross-SDK parity tracking effort label Nov 12, 2026
@kraenhansen
kraenhansen marked this pull request as ready for review November 13, 2026 08:33
@cursor

cursor Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Backward-compatible optional callback on conversational AI message handling; no auth or protocol changes.

Overview
Adds optional callback_unhandled_client_tool_call on Conversation and AsyncConversation so the app is notified when the agent invokes a client tool that is not registered in ClientTools. The callback receives the full client_tool_call payload; agent-facing behavior is unchanged—an error client_tool_result is still sent on the websocket.

ClientTools.is_registered(tool_name) supports that check under the existing registry lock. README documents the callback; new tests cover sync/async paths (unregistered fires once; registered tools do not).

Reviewed by Cursor Bugbot for commit 79fb14b. Bugbot is set up for automated code reviews on this repo. Configure here.

@kraenhansen
kraenhansen merged commit 9b06fa3 into main Nov 13, 2026
6 checks passed
@kraenhansen
kraenhansen deleted the sdk-parity/align/grp_675b2a branch November 13, 2026 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

parity Part of the cross-SDK parity tracking effort

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants