Repository navigation
Report unhandled client tool calls to the application - #931
Conversation
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]>
PR SummaryLow Risk Overview
Reviewed by Cursor Bugbot for commit 79fb14b. Bugbot is set up for automated code reviews on this repo. Configure here. |
Aligns the Python SDK with the cross-SDK parity tracker (MATRIX.md), group
grp_675b2a.Statement
stmt_b3780cNotifies the application of a client tool call for which no handler is registered.Gap (
elevenlabs-python)ClientTools.handleraisesValueErrorfor an unknown tool name,execute_toolcatches it, and the only reaction is theis_errorclient_tool_resultsent to the agent over the websocket. The application has no way to observe the call.SDKs this follows
All three expose an optional
onUnhandledClientToolCallcallback that receives theclient_tool_callpayload when itstool_namehas no registered handler:The references differ on what the agent gets back: js-client skips the error
client_tool_resultwhen the callback is set, while Kotlin still sends one. The statement doesn't observe that, and the agent-facing result is tracked separately asstmt_119917. So this PR keeps Python's existing error result unchanged, like Kotlin does.What changed
ConversationandAsyncConversationaccept a new optional keyword argument,callback_unhandled_client_tool_call. It is synchronous onConversationand async onAsyncConversation, like the other callbacks. When aclient_tool_callarrives for a tool name that isn't registered inclient_tools, it is called with the rawclient_tool_calldict (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.The change is backward compatible: the callback defaults to
None, and without it behaviour is unchanged. Only hand-maintained files listed in.fernignoreare touched.Testing
tests/test_convai_unhandled_client_tool.pycovers sync and async. The callback fires once with the payload for an unregistered tool, the agent still gets itsis_errorresult, 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.Opened by the nightly SDK parity aligner.