agent.achat() now route through the same safety mechanisms as sync execution, including approval checks, circuit breakers, and timeouts.
Quick Start
How It Works
| Safety Layer | Sync Mode | Async Mode |
|---|---|---|
| Approval checks | ✅ | ✅ |
| Argument type casting | ✅ | ✅ |
| Circuit breaker | ✅ | ✅ |
| Tool timeout | ✅ | ✅ |
| Doom-loop tracking | ✅ | ✅ |
| Trace events | ✅ | ✅ |
| Output truncation | ✅ | ✅ |
| Error wrapping | ✅ | ✅ |
execute_tool_async for tool invocations, so long-running tools no longer block the event loop.
Safety Mechanisms
Approval Checks
User approval prompts now appear during async tool execution:Circuit Breaker Protection
Tool failure rates are tracked across async calls:Timeout Controls
Async tool execution respects timeout settings:Wrapper-Level Timeout (YAML / framework: praisonai)
When running through YAML or the CLI, the wrapper wraps every tool with a timeout-enforcing shim before handing the agent to the SDK. This provides defense-in-depth timeout enforcement even for pathological tools. The wrapper handles sync and async tools differently:- Sync tools run in a daemon thread (
threading.Thread(daemon=True)); on timeout the wrapper returns a JSON error dict and abandons the thread (daemon threads do not block process exit). - Async tools are wrapped with
asyncio.wait_for(...); on timeout the wrapper returns the same JSON error dict.
tool_config=ToolConfig(timeout=…).
JSON return shape on wrapper-level timeout:
Task-Scoped Tools
Thetools_override parameter allows tasks to provide their own tool set for async execution:
Trace Events
Async tool execution now emits the same trace events as sync execution:| Event | When | Data |
|---|---|---|
TOOL_CALL_START | Before execution | tool_name, arguments |
TOOL_CALL_RESULT | After execution | result, duration, errors |
Migration Notes
No code changes required - async tool safety is automatically enabled: Before: Async calls bypassed safety mechanismsBest Practices
Handle Approval in Async Context
Handle Approval in Async Context
When using approval in async environments, ensure your event loop can handle user input:
Configure Timeouts for Async Tools
Configure Timeouts for Async Tools
Set appropriate timeouts for async tool execution:
Monitor Circuit Breaker in Async Workflows
Monitor Circuit Breaker in Async Workflows
Circuit breaker state affects all calls - monitor in async workflows:
Task Tools Override Agent Tools
Task Tools Override Agent Tools
Design task tools to be self-contained since they override agent tools:
Related
Approval
Tool approval configuration
Tool Circuit Breaker
Tool failure protection

