Quick Start
1
Limit parallel runs of an agent
Control how many instances of the same agent can run concurrently:
2
Same, async
Use async context for better resource utilization:
3
Bound tool time with ToolConfig
Prevent slow tools from blocking agent execution:
How It Works
Sync vs Async Rule
The concurrency registry enforces strict separation between sync and async contexts:
Example error:
Tool Timeout Behavior
Whentool_config=ToolConfig(timeout=...) is set, tools run in a dedicated executor with these characteristics:
In YAML the field name is still tool_timeout:; in Python use tool_config=ToolConfig(timeout=…).
Timeout Return Shape
On timeout, each layer surfaces the timeout differently:Effective Timeout Precedence
When multipletool_timeout values are declared, the wrapper resolves a single effective timeout applied to every tool in the shared tool dict:
- CLI wins. An explicit
--tool-timeout Non the command line (orcli_config={"tool_timeout": N}when embedding) is used verbatim. - Otherwise, the largest per-role/per-agent value. The wrapper picks
max(tool_timeout)across every entry underroles:andagents:in the YAML. This is the safest default for a shared tool dict — a slow-tool role won’t have its tools killed by another role’s stricter timeout. - Otherwise, no wrapping. If nothing declares a timeout, tools run without wrapper-layer enforcement (the SDK executor-layer enforcement still applies if
tool_config=ToolConfig(timeout=…)is set in Python).
AgentsGenerator._resolve_effective_tool_timeout(config) — see praisonai/agents_generator.py.
Executor Details
- One executor per
Agentinstance (lazy creation) max_workers=2threads per agent- Thread name prefix:
tool-<agent_name>— useful for log filtering - Reused across calls — no resource leak
Common Patterns
Limit FastAPI Route Concurrency
Async Context Manager Helper
Timeout Selection by Tool Type
Best Practices
Always release in finally blocks
Always release in finally blocks
Prevents deadlocks when exceptions occur:
Don't mix sync and async acquire
Don't mix sync and async acquire
Keep acquisition method consistent with execution context:
Set tool_timeout for network tools
Set tool_timeout for network tools
Any tool that does network IO should have a timeout:
Use thread names for debugging
Use thread names for debugging
Filter logs by agent name using the thread prefix:
Retries
Tool failures can be automatically retried using the retry policy feature. This works alongside timeouts to handle transient errors:Related
Tool Retry Policy
Automatically retry failed tool calls with exponential backoff
Tool Configuration
Tool timeout settings and performance tuning
Async Bridge
Safe sync↔async boundary crossing utilities
Thread Safety
Chat history and state protection mechanisms

