Skip to main content
A task is a discrete unit of work whose result can be checkpointed on its own. When an entrypoint or a Graph API node runs several operations, wrap each operation in a task instead of putting all the work in one function body. With a checkpointer, completed task results are saved, so a resumed thread can skip finished work and continue from the next task. This page covers retries, timeouts, caching, and error recovery on tasks. For concepts, see the Functional API overview. For an ordered build path, see the Build checklist for the Functional API. For the shared retry and timeout lifecycle, see Fault tolerance.

Add a retry policy

Pass retry on task (not retryPolicy). Retries are opt-in. If the policy omits retryOn, LangGraph retries most thrown errors except abort/cancel, GraphValueError, aborted connections, selected HTTP 4xx statuses, and OpenAI-style quota errors. This example retries any Error. See Fault tolerance for the full default list.

Set a timeout

Cap how long a single async attempt can run. If a retry policy retries the timeout error, the timer resets on the next attempt. Pass timeout on task or entrypoint in milliseconds, or as { idleTimeout: 30_000 }. Use isNodeTimeoutError to narrow timeout errors. NodeTimeoutError is retryable when a retry policy is set. The first attempt sleeps past the timeout. The retry policy retries. The second attempt returns immediately.

Cache a task

Cache a task result by input. Pass a cache on the entrypoint and a policy on the task. ttl is in seconds. The second call is a cache hit, so this run takes about 1 second, not 2.

Resume after an error

A checkpointer is required so completed task results survive the failed run. slow_task is restored from the checkpoint. get_info runs again and returns "OK". The entrypoint still returns the slow_task result. Resume the same thread_id with null.

See also