New Tool Radar

AI Agents & Automation

How to Set a Timeout So a Stuck Agent Task Is Abandoned

Give every agent task a timeout, so a stuck task is abandoned cleanly instead of hanging forever.

Schematic illustration with three step boxes: measure normal durations, set the timeout, and test the abandon.

A task with no timeout can hang forever: a tool that never returns, a model call that never finishes, a loop that never breaks. A timeout ends the run at a known time, logs the reason, and frees the agent for the next task. The timeout must be set from measured durations, not from a guess, or it will cut off normal work.

Before you start

An agent loop where you can set a per-task timeout, and a log of how long normal tasks take.

Measure how long normal tasks take

Look at the last 20 completed tasks and record the duration of each. Note the longest normal duration and the task type it belongs to: a research task takes longer than a lookup.

Note the durations by task type separately, so one timeout does not have to fit both.

Set the timeout above normal, below forever

Set the timeout at about three times the longest normal duration for that task type. Three times gives room for a slow day and still ends a stuck task in minutes, not hours.

Write the timeout into the loop code with a clear action on expiry: stop the run, log the timeout, and escalate or retry once, not forever.

Test the abandon on a stuck task

Run a task against a tool that never returns, and confirm the run ends at the timeout with a log entry and no further tool calls. Confirm the agent is free for the next task afterwards.

Check that the partial work is saved: an abandoned task should leave its state behind, so a human or a retry can pick it up.

Practice check: fictional Maple Corner agent, lookup tasks, timeout 180 seconds

The table below is fictional practice material, worked out by hand from the stated durations. It is the expected result for the practice tasks, not a run of any agent.

Task Duration Timeout Verdict
Normal lookup 38 s 180 s Pass
Slow lookup 61 s 180 s Pass
Stuck tool call 180 s 180 s Pass – abandoned at timeout
No timeout, stuck call 1,800 s None Fail – hung 30 minutes

Normal lookups take 38 to 61 seconds, so a 180-second timeout leaves room and still abandons the stuck call at 3 minutes. Without the timeout the same call hung for 30 minutes.

Expected result. UNTESTED: the durations in the practice table are worked out by hand, not measured by running an agent. Measure your own last 20 task durations, set the timeout at three times the longest normal one, and test it on a stuck task.

Limits

  • A timeout that is too short cuts off slow but normal work: set it from measured durations.
  • Abandoning is not failing silently: log the timeout and escalate the task.

Sources

See all