Skip to main content
The tool-call executor caps each tool call with a millisecond timeout and lets you cancel pending calls, returning a typed result the model can reason about instead of hanging the turn.
tool_timeout_ms is in milliseconds. The wrapper-level tool_timeout (YAML / CLI) is in seconds. tool_timeout_ms: 5000 = 5 seconds. See Tool Config for the layers.

Quick Start

1

Cap every tool call

Set tool_timeout_ms inside the llm= dict. A slow tool now returns a typed timeout result instead of freezing the turn.
2

Cancel from another thread

Signal a threading.Event-shaped cancel token to abort pending tool calls — useful in a REPL or gateway where a user hits stop.

How It Works

The executor wraps each tool call, branching to a typed result on timeout or cancellation.
A timed-out sync tool’s worker is abandoned, not killed — Python threads cannot be force-killed. The tool may keep running in the background. Do not rely on the timeout for security-critical bounds.

Configuration Options

The cancel token is duck-typed — it supports both threading.Event and InterruptController-shaped tokens without importing a concrete type.

Structured Error Envelope

ToolResult.structured_error returns a discriminated JSON envelope so the model can tell a timeout from a genuine bug, instead of an opaque "Error executing tool: ..." string.
The kind discriminant lets the model retry a timeout, abort on a cancelled, and report a plain error differently.

Exceptions

These are surfaced as ToolResult.error with the matching error_kind — they are not thrown to your calling code.
There are two ToolTimeoutError classes in PraisonAI. praisonaiagents.tools.ToolTimeoutError (this page, milliseconds, executor layer) is distinct from praisonai.agents_generator.ToolTimeoutError (wrapper layer, seconds, YAML/CLI). Import the one for the layer you are catching at. See Tool Config.

Common Patterns

Bound a whole batch with one timeout — most users’ entry point:
Wire up graceful cancellation for a REPL or long-running gateway:

Best Practices

Use millisecond tool_timeout_ms for user-facing latency budgets (a chat turn should not hang). Use wrapper-level tool_timeout (seconds) for hard operational cutoffs in YAML/CLI crews.
A timed-out sync tool’s daemon worker is abandoned, not killed. Assume the tool may still be running. Never use the timeout to enforce security-critical bounds.
Use cancel_token for interactive or streaming loops (bot, CLI, gateway) where a user can hit stop. Background jobs should rely on tool_timeout_ms alone.
Pass ToolResult.structured_error to the LLM instead of flattening it to a string. The discriminated kind is what lets the agent choose retry vs. abort vs. report.

Async Tool Safety

Wrapper-level timeouts and safe async tool execution.

Tool Config

Configure timeouts across all three enforcement layers.

Concurrency

Parallel tool execution and per-agent limits.