Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add tool timeout support
Summary
This PR adds timeout support for tool execution, allowing users to set both global and per-tool timeouts. When a tool exceeds its timeout, a
RetryPromptPartis returned to the model instead of raising an exception, enabling the model to try a different approach.Features
Agent(tool_timeout=30)@agent.tool(timeout=60)None(no timeout)Usage
Implementation Details
anyio.fail_after()for async timeout handlingRetryPromptPartwith message:"Tool '{name}' timed out after {timeout} seconds. Please try a different approach."timeoutfield toTool,ToolDefinition, andToolsetToolclassesTests Added
test_tool_timeout_triggers_retry- Verifies slow tools return RetryPromptParttest_per_tool_timeout_overrides_global- Verifies per-tool > global precedencetest_no_timeout_by_default- Verifies backward compatibilitytest_tool_timeout_retry_counts_as_failed- Verifies retry mechanism integrationtest_tool_timeout_message_format- Verifies error message formattest_tool_timeout_definition- Verifies ToolDefinition has timeout fieldtest_tool_timeout_default_none- Verifies default timeout is None