Skip to content

Handle agent_tool_request event type in MessageHandler#15

Open
seahyc wants to merge 2 commits intoelevenlabs:mainfrom
seahyc:fix/handle-agent-tool-request
Open

Handle agent_tool_request event type in MessageHandler#15
seahyc wants to merge 2 commits intoelevenlabs:mainfrom
seahyc:fix/handle-agent-tool-request

Conversation

@seahyc
Copy link
Copy Markdown

@seahyc seahyc commented Feb 23, 2026

Summary

When the ElevenLabs agent calls a server-side tool (webhook), the SDK receives an agent_tool_request event over the data channel. This event type was not handled in MessageHandler, causing it to fall through to the default branch and log Unknown event type: agent_tool_request.

This PR adds proper handling that mirrors the existing agent_tool_response pattern:

  • AgentToolRequest event model in events.dart - parses tool_name, tool_call_id, tool_type, and event_id from the nested agent_tool_request payload (verified against the AsyncAPI schema)
  • onAgentToolRequest callback in ConversationCallbacks - lets SDK consumers react to pending tool calls (e.g., show a loading indicator while a webhook executes)
  • Handler in MessageHandler - parses the event and dispatches to the callback
  • Unit tests for MessageHandler event dispatch - covers agent_tool_request, agent_tool_response, end_call trigger, ping/pong, debug routing, unknown event logging, and event model JSON parsing

Test plan

  • flutter test - all 54 tests pass (10 new tests in test/message_handler_test.dart)
  • Verify agent_tool_request events no longer log as unknown
  • Verify onAgentToolRequest callback fires with correct AgentToolRequest data
  • Verify no regression in agent_tool_response handling
  • Event model parsing matches the official AsyncAPI schema field names

@seahyc seahyc force-pushed the fix/handle-agent-tool-request branch from e5f1120 to 43600ac Compare February 23, 2026 08:10
When the ElevenLabs agent calls a server-side tool (webhook), the SDK
receives an `agent_tool_request` event. Previously this hit the default
branch, logging "Unknown event type: agent_tool_request".

This adds proper handling mirroring the existing `agent_tool_response`
pattern:
- `AgentToolRequest` event model with tool_name, tool_call_id,
  tool_type, and event_id (matching the AsyncAPI schema in
  elevenlabs/packages)
- `onAgentToolRequest` callback in `ConversationCallbacks`
- Handler in `MessageHandler` to parse and dispatch the event

This allows SDK consumers to react to pending tool calls, e.g. showing
a loading indicator while a webhook executes.
@seahyc seahyc force-pushed the fix/handle-agent-tool-request branch from 43600ac to dafa5aa Compare February 23, 2026 08:28
Add test coverage for MessageHandler event parsing and dispatch,
including AgentToolRequest, AgentToolResponse, InterruptionEvent,
ClientToolCall model parsing, ping/pong handling, debug callback
routing, and unknown event type logging.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@kraenhansen
Copy link
Copy Markdown
Collaborator

Thanks for your contribution 👍

@kraenhansen kraenhansen self-assigned this Mar 2, 2026
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