Agent is Calling tool and do not wait for tool's r...
# ask-ai
n
Agent is Calling tool and do not wait for tool's response like even 20 sec timeout for MCP too/call and generating response and once tool is executed again generating response ?
t
Thanks for reaching out, Darshak. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I completely understand how frustrating it can be when the agent responds before the tool has finished its work. Usually, this happens because of timeout settings or how the tool’s execution is managed. Let’s walk through some steps that can help fix this: • Increase Timeout Values: Try adjusting the
client_session_timeout_seconds
and
sse_read_timeout
settings in your MCP server configuration to allow more time for your tool to complete its task. • Prevent Interruptions: Consider using the
disallow_interruptions()
method in your tool’s code to make sure important operations aren’t cut off prematurely. • Monitor Execution Time: It’s helpful to log how long your tools take to run, so you can set timeout values that really fit your needs. • Review Tool Implementation: Double-check that your tools are set up to handle timeouts gracefully and return results exactly as expected. If you’d like, I’m here to help you dive deeper into your configurations or walk you through some debugging steps. Just let me know! Sources: Docs::Agents | mcp_client/util.py | livekit-agents/livekit/agents/voice/agent_activity.py
n
But as I said Agent Called tool and not even 1sec it waited for response even though timeout is 20sec
t
Thanks for reaching out! To help us understand why the agent isn’t waiting for the tool’s response despite the 20-second timeout, could you please share a bit more information? • Where exactly is the 20-second timeout set? Is it on the MCP server, within the tool implementation, or somewhere else? • Are you using
@function_tool
decorators, or are the tools being forwarded via RPC/MCP? • Is this happening with all tools or just specific ones? • Have you noticed any error messages or logs that might explain why the agent moves on too soon? Getting these details will really help us get to the bottom of this and find the best solution for you. Sources: Remote method calls | LiveKit docs | livekit-agents/livekit/agents/voice/generation.py | agents/src/voice/agent_activity.ts | Docs::Agents
n
Copy code
mcp.MCPServerHTTP(
    url=url,
    timeout=20,
    client_session_timeout_seconds=20,
)
t
Thank you so much for sharing your configuration with me. From what you’ve described, the
client_session_timeout_seconds
parameter controls the read timeout for the MCP server’s tool response stream. But if the agent isn’t waiting for the tool response, don’t worry — there are a few things we can check together to help resolve this: • Verify URL Path: Please double-check that your MCP server URL ends with
/mcp
, as this enables the Streamable HTTP transport. If it ends with
/sse
, the
sse_read_timeout
parameter (which defaults to 5 minutes) might actually be taking priority over
client_session_timeout_seconds
. • Set `sse_read_timeout`: If you’re using SSE transport, it’s a good idea to explicitly set
sse_read_timeout
to a value longer than your expected tool execution time to avoid premature timeouts. • Check Logs and Events: Attaching event listeners like
function_tools_executed
and
metrics_collected
can be really helpful — they’ll show whether the tool is being called and if the response is coming through or getting interrupted. • Test Transport Behavior: You might also want to try the LiveKit testing framework. It’s a great way to simulate tool calls and debug any timeout issues in a safe, controlled setting. Could you please confirm the URL path you’re currently using and whether you’ve set the
sse_read_timeout
parameter? That info will really help us zero in on what might be going on. I’m here to help every step of the way! Sources: tests/test_agent_session.py | Docs::Agents | Testing and evaluation | LiveKit Docs | Still Have Questions