Skip to main content
Cap how long one chat turn runs with ExecutionConfig(max_execution_time=...), or how long a whole autonomous run takes with run_autonomous(timeout_seconds=...) — a timed-out turn stops at its next loop boundary and reports last_stop_reason == "timeout".
Shipped in PR #6062. Before it, max_execution_time only halted at tool calls, and a run_autonomous turn that overran timeout_seconds could still finish and be reported as "goal". No new parameters, and no overhead when neither cap is set.

Quick Start

1

Bound a single chat turn

2

Bound a whole autonomous run


Which cap do I want?

They compose: with timeout_seconds=600 and max_execution_time=120, any single turn stops after 2 minutes and the whole run after 10. In an autonomous run, a turn cut by max_execution_time is also reported as completion_reason="timeout".

What a timeout stops

The deadline is checked at loop boundaries, not inside running code. Pair max_execution_time with tool_config=ToolConfig(timeout=...) on slow tools, and with an LLM timeout on slow providers, to keep the overall cap tight.

Best Practices

Check agent.last_stop_reason == "timeout" or result.completion_reason == "timeout" instead of parsing the reply. See Agent Run Outcomes for every stop reason.
A turn stops at the next boundary, so actual elapsed time can run past the cap by one LLM call or tool call. Set the cap a little below your hard limit.

Execution

Full ExecutionConfig overview

Loop Guard

Tool-boundary halt that also reads max_execution_time

LLM Timeouts

Per-request timeout on each LLM call

Autonomy Loop

run_autonomous iterations and completion reasons