Skip to main content
The agent loop runs several operations in sequence: an LLM call, optional tool executions, memory reads/writes, conversation persistence, and sub-agent delegation. By default, each operation uses a conservative SDK-wide timeout and attempt limit. Execution config lets you tune these per operation without changing the global agent timeout.

How it works

Provide an ExecutionConfig for one or more operations via With*ExecutionConfig options when creating the agent. Zero fields keep the SDK default — only set what you want to change.
type ExecutionConfig struct {
    Timeout     time.Duration // 0 = keep SDK default
    MaxAttempts int           // 0 = keep SDK default; 1 = single attempt
}
At runtime the SDK merges your overrides onto the defaults and produces a fully resolved policy — including exponential backoff — that the runtime enforces on each attempt.

SDK defaults

OperationOptionDefault TimeoutDefault MaxAttempts
LLM generate / streamWithLLMExecutionConfig30 min3
Tool authorizationWithToolAuthExecutionConfig30 min1
Tool executionWithToolExecutionConfig30 min3
MCPWithMCPExecutionConfig30 min3
A2AWithA2AExecutionConfig30 min3
Retriever prefetchWithRetrieverExecutionConfig5 min3
Memory recall / storeWithMemoryExecutionConfig5 min3
Conversation persistWithConversationExecutionConfig30 s1
Sub-agent delegationWithSubAgentExecutionConfig(agent run timeout)1
Sub-agent timeout has no fixed SDK default — when no override is set and the resolved timeout is still zero, the agent run timeout (WithTimeout) is used as the ceiling.

Retry backoff

When MaxAttempts is greater than 1, failed attempts use exponential backoff with SDK defaults:
ParameterValue
Initial interval1 s
Backoff coefficient
Maximum interval10 min
MaxAttempts: 1 runs the operation once with no retry. Backoff is not user-configurable today.

Usage

Override only the operations you want to tune:
a, err := agent.NewAgent(
    agent.WithLLMClient(llmClient),

    // LLM: tighter timeout for a chat agent; up to 3 attempts for transient errors.
    agent.WithLLMExecutionConfig(agent.ExecutionConfig{
        Timeout:     10 * time.Minute,
        MaxAttempts: 3,
    }),

    // Tools: fast operations — short deadline, single attempt.
    agent.WithToolExecutionConfig(agent.ExecutionConfig{
        Timeout:     2 * time.Minute,
        MaxAttempts: 1,
    }),

    // Sub-agents: explicit ceiling of the agent run timeout.
    agent.WithSubAgentExecutionConfig(agent.ExecutionConfig{
        Timeout: 5 * time.Minute,
    }),
)

Override a single field

Zero fields fall through to the SDK default:
// Extend LLM timeout only — MaxAttempts stays at SDK default (3).
agent.WithLLMExecutionConfig(agent.ExecutionConfig{
    Timeout: 45 * time.Minute,
})

// Reduce max attempts only — Timeout stays at SDK default (30m).
agent.WithToolAuthExecutionConfig(agent.ExecutionConfig{
    MaxAttempts: 2,
})

Relationship to agent run timeout

ExecutionConfig controls individual operation attempts. The agent run timeout (WithTimeout or context deadline) is a ceiling on the entire run — if it fires, the run ends regardless of where the current operation is.
Timeout typeScopeSet via
Agent run timeoutEntire Run / Stream / RunAsync callWithTimeout or context deadline
Per-operation timeoutSingle attempt of one operationWith*ExecutionConfig
A single LLM call timing out after Timeout does not end the run — it counts as a failed attempt and may be retried until MaxAttempts is exhausted. The run ends only if the agent run timeout fires or all attempts are exhausted.

Works with both runtimes

Execution config applies to both the in-process and Temporal runtimes with the same semantics.

Example

Execution Config

LLM, tool, and sub-agent overrides with calculator and time tools

Timeouts & Modes

Agent run timeout, approval timeout, and agent modes

Approvals

Per-tool approval timeout and approval handler

Sub-agents

Sub-agent delegation and depth limits

MCP

MCP integration