Skip to content

fix: handle agent_tool_request event type and fix expects_response default#34

Merged
shiragannavar merged 3 commits intomainfrom
fix/agent-tool-request-expects-response
Dec 11, 2025
Merged

fix: handle agent_tool_request event type and fix expects_response default#34
shiragannavar merged 3 commits intomainfrom
fix/agent-tool-request-expects-response

Conversation

@shiragannavar
Copy link
Copy Markdown
Collaborator

Summary

Fixes issue where client tools configured with expects_response: true were not working, causing sendToolResult() to break the connection.

Root Cause: The server sends agent_tool_request event type, but the SDK only handled client_tool_call. Additionally, the server doesn't include the expects_response field in the payload (it's only in the tool configuration), so the SDK was defaulting to false.

Changes

  • Add support for agent_tool_request event type alongside client_tool_call
  • Parse nested agent_tool_request object in addition to client_tool_call
  • For new agent_tool_request format: default expects_response to true for client tools when tool_type: "client"
  • Maintain backward compatibility: legacy client_tool_call format still defaults to false

Event Format Comparison

What SDK expected:
{
"type": "client_tool_call",
"client_tool_call": {
"tool_name": "...",
"expects_response": true
}
}What server sends:
{
"type": "agent_tool_request",
"agent_tool_request": {
"tool_name": "...",
"tool_type": "client",
"tool_call_id": "..."
}
}## Backward Compatibility

Fully backward compatible - no breaking changes for existing deployments

Event Format expects_response in payload Result
client_tool_call true true
client_tool_call false false
client_tool_call missing false (unchanged)
agent_tool_request true true
agent_tool_request false false
agent_tool_request missing + tool_type: client true (new)

Testing

  • Verified with conversation that was previously failing
  • sendToolResult() now works correctly without breaking the connection

…fault

- Add support for 'agent_tool_request' event type alongside 'client_tool_call'
- Parse nested 'agent_tool_request' object in addition to 'client_tool_call'
- For new agent_tool_request format: default expects_response to true for client tools
- Maintain backward compatibility: legacy client_tool_call format still defaults to false

Fixes issue where client tools with expects_response:true in config were not
receiving the field in the event payload, causing sendToolResult() to fail.
Previously, expects_response only defaulted to true for agent_tool_request
events with tool_type: 'client'. This fix extends the default to ALL client
tool events (both client_tool_call and agent_tool_request) when the field
is missing from the payload.

Rationale: The server may not include expects_response in the payload even
when the tool configuration has expects_response: true. Since client tools
primarily exist to execute on the client and return results to the agent,
defaulting to true is the safer and more expected behavior.

This fixes issues where:
- client_tool_call events without expects_response field
- agent_tool_request events without tool_type field

Both now correctly default to expects_response: true.

BREAKING CHANGE: Client tools that previously relied on the false default
and did NOT send responses will now be expected to send responses. Such
tools should explicitly set expects_response: false in their configuration.
@shiragannavar
Copy link
Copy Markdown
Collaborator Author

@PaulAsjes @franklintra

Backend fix was merged into main

Can you please re-review this PR?

…ault

Added 14 tests covering:
- client_tool_call with explicit expects_response true/false
- client_tool_call without expects_response field (should default to true)
- client_tool_call with null expects_response (should default to true)
- agent_tool_request with tool_type client (should default to true)
- agent_tool_request with explicit expects_response false
- agent_tool_request without tool_type (should still default to true)
- Parameter parsing (string, numeric, boolean, empty)
- Edge cases (unknown event type, malformed JSON)
@shiragannavar shiragannavar merged commit fe2ffa4 into main Dec 11, 2025
1 check passed
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