Back to series
· 15 min read

Long-Horizon Tasks and Autonomous Execution Agents


I. What Is a Long-Horizon Task?

Traditional interactions with large models usually revolve around a single request: the user asks a question, the model generates an answer, and the interaction ends.

But complex work in the real world often cannot be completed in a single call. For example:

  • Completing a software project over several hours or even several days.
  • Analyzing large volumes of material, compiling research reports, and continuously updating them.
  • Automatically performing data collection, cleaning, analysis, and report generation.
  • Continuously monitoring business metrics and triggering processing workflows when conditions are met.
  • Completing multi-step business processes that span multiple systems.
  • Repeatedly revising a plan based on external feedback until it meets the acceptance criteria.

These tasks share several characteristics:

  1. Long execution time: they may span multiple model calls, tool calls, or even multiple sessions.
  2. Complex steps: the task contains multiple sub-goals, and the order of execution involves dependencies.
  3. Constantly changing state: each step produces new results, constraints, or to-do items.
  4. Uncertain external environment: tools may fail, data may change, and execution conditions may shift.
  5. Need for dynamic adjustment: the original plan may no longer apply, and the Agent must re-plan.
  6. Results need verification: you cannot conclude that the goal has been achieved simply because the model believes the task is complete.

So the core of a long-horizon task is not to have the model keep generating more text, but to have the Agent maintain its goals, state, plan, and execution results over the long term within a persistent execution environment.

II. How Long-Horizon Tasks Differ from Ordinary Agents

An ordinary Agent usually handles relatively short-lived tasks, whereas a long-horizon Agent must take on ongoing responsibility for task management and execution.

Dimension Ordinary Agent Long-Horizon Agent
Execution time Single run or short duration Long duration, multiple phases
Task structure Relatively simple Multi-level, heavily interdependent
State management Mostly the current context Persisted task state
Memory mechanism Short-term context Short-term and long-term memory
Planning approach Mainly one-shot planning Dynamic planning and re-planning
Error handling Retry the current step Failure recovery and resuming from checkpoints
Resource management Per-call budget Long-term budget and resource scheduling
Result verification Single output check Stage-by-stage acceptance and final acceptance
Human involvement Interaction at request time Approval and oversight at key checkpoints

Note that a long-horizon Agent does not necessarily mean the model runs continuously for hours.

A more sensible design is:

  • Run for a while.
  • Save the current state.
  • Release runtime resources.
  • Wait for external conditions or scheduled events.
  • Resume the task and continue execution.

This is a persistent, recoverable mechanism for autonomous execution.

III. Core Architecture of Long-Horizon Tasks

A complete long-horizon Agent typically consists of components for task management, planning, execution, memory, state storage, scheduling, and verification.

1. Core Architecture Components

Component Core responsibility
Task Manager Manages task creation, lifecycle, and priority
Planner Creates execution plans and decomposes sub-tasks
Orchestrator Coordinates execution phases and tools
Executor Invokes models, APIs, browsers, and other tools
State Manager Manages current execution state and progress
Memory Manager Stores historical experience and long-term knowledge
Checkpoint Manager Creates and restores execution checkpoints
Scheduler Manages scheduled execution, delayed tasks, and wake-ups
Verifier Checks stage results and the final goal
Recovery Manager Handles failures, retries, and task recovery
Policy Guard Controls permissions, budgets, and high-risk operations

2. Overall Architecture Diagram

flowchart TB
    A["User Goals and Task Request"] --> B["Task Manager"]
    B --> C["Planner"]
    C --> D["Orchestrator"]
    D --> E["Executor Tool Execution"]
    E --> F["Verifier Result Validation"]
    F --> G{"Stage goal reached?"}
    G -->|"No"| H["Recovery Manager"]
    H --> C
    G -->|"Yes"| I["State Manager State Update"]
    I --> J["Checkpoint Manager"]
    J --> K["Memory Manager Long-Term Memory"]
    K --> L{"Task complete?"}
    L -->|"No"| M["Scheduler Wait or Wake"]
    M --> D
    L -->|"Yes"| N["Final Result and Task Archiving"]

    style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style B fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style C fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style D fill:#EAF3EC,stroke:#83A995,color:#315D49
    style E fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style F fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style G fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style H fill:#F7EAE7,stroke:#C98D7C,color:#754438
    style I fill:#EAF3EC,stroke:#83A995,color:#315D49
    style J fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style K fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style L fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style M fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style N fill:#DCEFE5,stroke:#4F8B70,color:#24563F

The entire architecture can be divided into three layers:

  • Decision layer: responsible for understanding goals, planning tasks, and determining the next action.
  • Execution layer: responsible for invoking tools, executing subtasks, and handling interactions with external systems.
  • Persistence layer: responsible for saving state, memory, checkpoints, and execution records.

Working together, these three layers mean the Agent no longer relies on a single model context to sustain an entire task.

IV. Task Decomposition and Dynamic Planning

Long-horizon tasks generally cannot be handed directly to the model for execution; they must first be converted into structured tasks.

1. Why is task decomposition necessary?

For example, a user proposes:

Build a complete competitive analysis report, continuously collect information on competing products, compare prices, features, and market changes, and ultimately generate an analysis document.

This is a complex goal that includes at least:

  • Determining the scope of competitors.
  • Collecting product information.
  • Obtaining price and feature data.
  • Unifying the data format.
  • Establishing comparison dimensions.
  • Analyzing competitive differences.
  • Generating the report.
  • Updating information periodically.

Without task decomposition, the Agent is prone to the following problems:

  1. Omitting key steps.
  2. Repeatedly executing work that is already complete.
  3. Being unable to identify task dependencies.
  4. Finding it difficult to judge current progress.
  5. Being unable to determine where to resume from after a failure.

2. Converting goals into a task tree

A tree structure can be used to express the task hierarchy:

Competitive Analysis Project
├── 1. Determine Competitor Scope
│   ├── Define target market
│   ├── Identify competing products
│   └── Build competitor list
├── 2. Information Collection
│   ├── Product features
│   ├── Product prices
│   └── Market developments
├── 3. Data Processing
│   ├── Data cleaning
│   ├── Data deduplication
│   └── Data standardization
├── 4. Competitive Analysis
│   ├── Feature comparison
│   ├── Price comparison
│   └── Strengths and weaknesses analysis
├── 5. Report Generation
│   ├── Generate analysis results
│   └── Output report
└── 6. Continuous Updates
    ├── Periodic collection
    ├── Detect changes
    └── Update report

The task tree describes the goal structure, but task dependencies are also needed to determine execution order.

3. Task dependencies

Some tasks can be executed in parallel, while others must wait for prerequisite tasks to complete.

For example:

  • Product features and prices can be collected in parallel.
  • Data cleaning must wait for the corresponding data collection to complete.
  • Competitive analysis must wait for data standardization to complete.
  • The final report must wait for the analysis results to be generated.

A directed acyclic graph (DAG) can be used to represent dependencies.

flowchart TD
    A["Determine Competitor Scope"] --> B["Collect Product Features"]
    A --> C["Collect Product Pricing"]
    A --> D["Collect Market Intelligence"]
    B --> E["Clean Feature Data"]
    C --> F["Clean Pricing Data"]
    D --> G["Clean Market Data"]
    E --> H["Comprehensive Competitor Analysis"]
    F --> H
    G --> H
    H --> I["Generate Analysis Report"]
    I --> J["Result Acceptance"]

    style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style B fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style C fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style D fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style E fill:#EAF3EC,stroke:#83A995,color:#315D49
    style F fill:#EAF3EC,stroke:#83A995,color:#315D49
    style G fill:#EAF3EC,stroke:#83A995,color:#315D49
    style H fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style I fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style J fill:#DCEFE5,stroke:#4F8B70,color:#24563F

A DAG can support:

  • Automatically identifying executable tasks.
  • Scheduling independent tasks in parallel.
  • Preventing tasks whose dependencies are not complete from executing early.
  • Retrying only the affected tasks after a failure.
  • Calculating overall task completion progress.

4. Static Planning and Dynamic Planning

Static planning creates a complete plan when the task begins.

Advantages:

  • Clear execution path.
  • Easy to estimate resources.
  • Suitable for tasks with stable processes.

Disadvantages:

  • Cannot fully adapt to external changes.
  • A failure in one step may affect subsequent plans.
  • It may execute task arrangements that have already become obsolete.

Dynamic planning, by contrast, allows the Agent to adjust subsequent steps based on execution results.

For example:

  • The original plan uses a certain data source.
  • During execution, the data source is found to be inaccessible.
  • The Agent evaluates other available data sources.
  • It reschedules the data collection task.
  • It updates dependencies and continues execution.

Real-world systems usually adopt a hybrid approach:

Overall goals and key constraints remain stable, while the specific execution plan can be adjusted dynamically.

V. Persistent State: Enabling Tasks to Continue Across Sessions

One of the most important technical issues for long-running tasks is how to persist execution state.

If an Agent has been running for several hours and the service then restarts, the system must know:

  • What is the current task?
  • Which steps have been completed?
  • Which steps are currently executing?
  • Which steps failed?
  • What data has been collected?
  • What should be executed next?
  • Are there any unprocessed external events?

This information cannot be stored only in the model's conversation context.

1. Task State Structure

A simple task state can be represented using JSON:

{
  "task_id": "task_20261121_001",
  "goal": "完成竞品分析报告",
  "status": "running",
  "current_stage": "data_analysis",
  "progress": 0.65,
  "completed_tasks": [
    "competitor_discovery",
    "feature_collection",
    "price_collection"
  ],
  "pending_tasks": [
    "market_analysis",
    "report_generation"
  ],
  "failed_tasks": [],
  "retry_count": 0,
  "checkpoint_version": 12,
  "updated_at": "2026-11-21T10:30:00Z"
}

Several concepts need to be distinguished here:

  • task_id: Unique identifier for the task.
  • status: Overall lifecycle status of the task.
  • current_stage: Current execution stage.
  • progress: Overall progress estimate.
  • completed_tasks: Subtasks that have been completed.
  • pending_tasks: Subtasks waiting to be executed.
  • failed_tasks: Subtasks that failed execution.
  • checkpoint_version: Checkpoint version.

In real-world engineering, it is also necessary to store subtask inputs and outputs, dependencies, execution records, resource consumption, and version information.

2. The Difference Between Task Status and Execution Status

Task status indicates what stage the entire task is in.

For example:

Status Meaning
pending Waiting to start
running Currently executing
paused Manually paused
waiting Waiting for external conditions
blocked Blocked by dependencies or permissions
failed Task failed
completed Completed
cancelled Cancelled

Subtasks may have their own independent statuses:

  • pending
  • ready
  • running
  • succeeded
  • retrying
  • failed
  • skipped
  • cancelled

The overall task status cannot simply be equated with the status of any single subtask.

For example, the failure of one subtask does not necessarily mean the entire task fails immediately. The system can decide, based on the task policy, whether to retry, skip, degrade, or wait for manual handling.

3. State Persistence Mechanism

Typically, a database can be used to store task status.

For example:

CREATE TABLE agent_tasks (
    task_id VARCHAR(128) PRIMARY KEY,
    goal TEXT NOT NULL,
    status VARCHAR(32) NOT NULL,
    current_stage VARCHAR(128),
    progress DECIMAL(5, 4) DEFAULT 0,
    checkpoint_version BIGINT DEFAULT 0,
    created_at TIMESTAMP NOT NULL,
    updated_at TIMESTAMP NOT NULL
);

Subtasks can be stored separately:

CREATE TABLE agent_subtasks (
    subtask_id VARCHAR(128) PRIMARY KEY,
    task_id VARCHAR(128) NOT NULL,
    name VARCHAR(255) NOT NULL,
    status VARCHAR(32) NOT NULL,
    dependencies JSON,
    input_data JSON,
    output_data JSON,
    retry_count INT DEFAULT 0,
    FOREIGN KEY (task_id) REFERENCES agent_tasks(task_id)
);

Production environments should also consider:

  • Transactional consistency of status updates.
  • Optimistic locking or version number control.
  • Task locking during concurrent execution by multiple Workers.
  • Auditing of execution records and status changes.
  • Separate storage of large task results and metadata.

4. Checkpoint Mechanism

Checkpoint is a key mechanism for long-running Agents.

It means saving a recoverable task snapshot at a certain execution point.

A checkpoint typically includes:

  • The current task status.
  • The current execution stage.
  • Completed subtasks.
  • References to intermediate results.
  • The next execution plan.
  • Retry count.
  • Execution version.
  • Necessary context summary.

A checkpoint does not necessarily need to save the entire conversation history. A more reasonable approach is to save structured state and store large files, datasets, and logs in separate storage.

flowchart TD
    A["Task Start"] --> B["Read Task State"]
    B --> C["Execute Current Step"]
    C --> D["Generate Execution Result"]
    D --> E["Validate Execution Result"]
    E --> F{"Is the result valid?"}
    F -->|"No"| G["Record Error and Recover"]
    G --> C
    F -->|"Yes"| H["Update Task State"]
    H --> I["Write Checkpoint"]
    I --> J{"Is the task complete?"}
    J -->|"No"| K["Schedule Next Stage"]
    K --> C
    J -->|"Yes"| L["Save Final Result"]

    style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style B fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style C fill:#EAF3EC,stroke:#83A995,color:#315D49
    style D fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style E fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style F fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style G fill:#F7EAE7,stroke:#C98D7C,color:#754438
    style H fill:#EAF3EC,stroke:#83A995,color:#315D49
    style I fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style J fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style K fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style L fill:#DCEFE5,stroke:#4F8B70,color:#24563F

Key principle: ensure the result is reliable before advancing the task state.

If the execution result has already been produced but the state has not yet been saved, the system may execute it again.

Therefore, state updates and result persistence must be designed with clear consistency boundaries.

6. Context Management: Breaking Through the Model Context Window Limit

Long-running tasks may generate a large amount of information:

  • User requirements and constraints.
  • Conversation history.
  • Tool call records.
  • Intermediate analysis results.
  • File contents.
  • Task plans.
  • Failure reasons.
  • Data returned by external systems.

This content cannot be placed in the model context without limit.

Even if the model supports a large context window, that does not mean all historical content should be passed in repeatedly.

1. The Difference Between Context and Memory

Type Primary role Lifecycle
Current context Supports current model reasoning Single-use or short-term
Working memory Stores important information for the current stage Current task stage
Task state Stores task progress and execution position Entire task lifecycle
Long-term memory Stores reusable experience and knowledge Cross-task
Historical logs Records the complete execution process Retained according to audit policy

Pay special attention:

Memory is not the same as state, and state is not the same as context.

For example:

  • “Price collection has been completed” belongs to task state.
  • “A certain data source often has access restrictions” is reusable experience.
  • The three data summaries currently being analyzed are working memory.
  • The content the model actually sees in this call is the current context.

2. Context Compression

The goal of context compression is not simply to delete old messages, but to extract information that remains important for subsequent execution.

For example, the raw execution record may contain dozens of tool calls.

After compression, it can save:

Task: Complete a competitive analysis report

Current stage:
Competitor identification, feature collection, and price collection are complete.

Key results:
5 competitors identified; feature data completeness 92%; price data completeness 88%.

Known issues:
Competitor C's price page is inaccessible; official historical public data is being used temporarily.

Outstanding items:
1. Supplement price verification for Competitor C.
2. Complete market trend analysis.
3. Generate the final report.

Constraints:
All price data must record the source and collection time.
External reports must not be published without human approval.

This way, the Agent does not need to repeatedly read the entire history.

3. Context Construction Strategy

For each model call, the context can be dynamically constructed based on the current stage:

  1. Read the task goal and core constraints.
  2. Read the current task state.
  3. Read the current subtask and its dependencies.
  4. Retrieve relevant historical results.
  5. Obtain necessary files or external data.
  6. Inject relevant experience and rules.
  7. Control the context length and call the model.
flowchart TD
    A["Prepare Model Invocation"] --> B["Read Task Goal"]
    B --> C["Read Current State"]
    C --> D["Retrieve Relevant Memories"]
    D --> E["Load Necessary Historical Results"]
    E --> F["Extract Key Constraints"]
    F --> G["Context Compression and Sorting"]
    G --> H["Check Token Budget"]
    H --> I{"Does It Meet the Context Budget?"}
    I -->|"No"| J["Further Summarization and Trimming"]
    J --> H
    I -->|"Yes"| K["Build Model Input"]
    K --> L["Execute Model Inference"]

    style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style B fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style C fill:#EAF3EC,stroke:#83A995,color:#315D49
    style D fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style E fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style F fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style G fill:#EAF3EC,stroke:#83A995,color:#315D49
    style H fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style I fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style J fill:#F7EAE7,stroke:#C98D7C,color:#754438
    style K fill:#EAF3EC,stroke:#83A995,color:#315D49
    style L fill:#DCEFE5,stroke:#4F8B70,color:#24563F

Context management also needs to pay attention to information timeliness. For data that may change, such as prices, inventory, and status, it should be re-queried when needed rather than relying indefinitely on historical memory.

7. Autonomous Execution and Scheduling Mechanisms

A long-running Agent should not keep occupying model invocation resources while waiting for the next step.

It needs task scheduling capabilities.

1. Why Is a Scheduler Needed?

Suppose the Agent needs to collect competitor product prices once every day at 9 a.m.

If a continuous loop approach is used:

  • The Agent keeps running.
  • It checks the current time at intervals.
  • When the specified time arrives, it performs the collection.

This approach wastes computing resources.

A more reasonable approach is to use an external scheduler:

  • Create a scheduled task.
  • Trigger an event when the execution time arrives.
  • Resume the corresponding task.
  • Execute the current stage.
  • Save the result and schedule the next execution.

2. Common Scheduling Types

Scheduling Method Use Case
Time-based scheduling Execute hourly, daily, or weekly
Delayed scheduling Continue after waiting for a period of time
Event-driven Triggered when a message, file, or business event is received
Conditional scheduling Execute after a certain condition is met
Dependency-based scheduling Execute after the prerequisite task is completed
Manual triggering User approval or manual resumption
Retry scheduling Re-execute according to policy after failure

3. Autonomous Execution Loop

The Agent can execute tasks in a bounded loop, with each round responsible for only one stage or a set of controlled operations.

flowchart TD
    A["Scheduler wakes the Agent"] --> B["Load task state"]
    B --> C["Check task constraints and budget"]
    C --> D["Select the currently executable task"]
    D --> E["Create an action plan for this round"]
    E --> F["Execute tool or model operation"]
    F --> G["Verify execution result"]
    G --> H{"Manual approval required?"}
    H -->|"Yes"| I["Pause and wait for approval"]
    I --> J["Receive approval result"]
    J --> K{"Approved?"}
    K -->|"No"| L["Cancel or replan"]
    K -->|"Yes"| M["Update task state"]
    H -->|"No"| M
    L --> N["Save checkpoint"]
    M --> N
    N --> O{"Completed or needs to wait?"}
    O -->|"Continue"| D
    O -->|"Wait"| P["Release runtime resources"]
    O -->|"Completed"| Q["Output final result"]
    P --> R["Wait for next wake-up"]
    R --> A

    style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style B fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style C fill:#EAF3EC,stroke:#83A995,color:#315D49
    style D fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style E fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style F fill:#EAF3EC,stroke:#83A995,color:#315D49
    style G fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style H fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style I fill:#F7EAE7,stroke:#C98D7C,color:#754438
    style J fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style K fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style L fill:#F7EAE7,stroke:#C98D7C,color:#754438
    style M fill:#EAF3EC,stroke:#83A995,color:#315D49
    style N fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style O fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style P fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style Q fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style R fill:#F5F8F4,stroke:#B5CBBB,color:#40594A

4. Event-Driven and Autonomous Execution

A long-running Agent can be triggered by events and does not have to actively poll at all times.

Common events include:

  • A scheduled task becomes due.
  • The user sends a new instruction.
  • A new record appears in the database.
  • A file upload completes.
  • An external API returns a result.
  • Manual approval is completed.
  • A dependency task completes successfully.
  • The monitoring system detects an anomaly.

Event-driven architectures typically use message queues, event buses, or task scheduling services.

For example:

Event sources
  - Timer
  - User action
  - External API
  - Business system
        |
        v
Event bus
        |
        v
Task router
        |
        v
Load task state
        |
        v
Agent execution
        |
        v
Save results and checkpoints

In the actual article, the process relationships should be expressed using Mermaid. In engineering practice, events may be delivered repeatedly, so idempotent handling and event deduplication must be designed.

VIII. Exception Recovery: Enabling the Agent to Continue After Failure

Long-running tasks inevitably encounter exceptions.

For example:

  • Model API timeout.
  • External data source unavailable.
  • Tool call failure.
  • File write failure.
  • Database connection interruption.
  • Subtask dependency failure.
  • The model produces a result that does not meet requirements.
  • The execution process is unexpectedly terminated.

If an Agent has no exception recovery mechanism, a single sporadic error can cause the entire task to terminate.

1. Common Exception Types

Exception Type Typical Cause Handling Strategy
Transient network exception Network fluctuation Exponential backoff retry
API rate limiting Request rate too high Wait for the rate-limit window
Model call failure Timeout or service error Retry or switch models
Tool execution failure Invalid parameters, insufficient permissions Fix parameters or request approval
Data anomaly Missing data, format errors Data validation and completion
Dependency failure Prerequisite task not completed Block downstream tasks
Resource exhaustion Token, memory or cost limit exceeded Pause or degrade
State inconsistency Concurrent writes or process interruption Restore checkpoint and verify results

2. Retry Mechanisms

The simplest retry approach is a fixed interval:

import time

def retry_task(task, max_retries=3, delay=2):
    for attempt in range(max_retries):
        try:
            return task()
        except Exception:
            if attempt == max_retries - 1:
                raise

            time.sleep(delay)

But production environments usually require more sophisticated strategies.

Exponential Backoff:

delay_n = \min(delay_{max}, delay_{base} \times 2^n)

For example:

  • Wait 1 second after the first failure.
  • Wait 2 seconds after the second failure.
  • Wait 4 seconds after the third failure.
  • Wait 8 seconds after the fourth failure.

You can also add random jitter to prevent large numbers of tasks from retrying at the same time.

Things to note:

  • Only retry exceptions that are suitable for retrying.
  • Parameter errors should usually be corrected rather than resubmitted.
  • Insufficient permissions cannot be solved by repeated retries.
  • For operations with side effects, idempotency must be considered.
  • After exceeding the maximum number of retries, the task should move to manual handling or a failed state.

3. Resuming from Checkpoints

The core of resuming from a checkpoint is: restore the most recent reliable checkpoint and determine which tasks have already been completed.

You cannot simply continue from the point of the last model call, because model calls and external tool operations may have side effects.

For example:

  • The payment interface has already succeeded, but the process crashes before saving the result.
  • After the system restarts, the payment is executed again.
  • The user may therefore be charged twice.

Therefore, resuming from a checkpoint must be combined with execution records, idempotency keys, and verification against external results.

4. Failure Recovery Process

flowchart TD
    A["Task anomaly detected"] --> B["Identify anomaly type"]
    B --> C{"Is it a temporary anomaly?"}
    C -->|"Yes"| D["Check retry count"]
    D --> E{"Exceeded retry limit?"}
    E -->|"No"| F["Perform backoff wait"]
    F --> G["Resume task execution"]
    G --> H["Verify execution result"]
    H --> I{"Successful?"}
    I -->|"Yes"| J["Update status and checkpoint"]
    I -->|"No"| A
    E -->|"Yes"| K["Escalate to manual handling"]
    C -->|"No"| L{"Can it be fixed automatically?"}
    L -->|"Yes"| M["Adjust plan or execution parameters"]
    M --> G
    L -->|"No"| K
    K --> N["Record failure reason and context"]
    N --> O["Wait for manual decision or terminate"]

    style A fill:#F7EAE7,stroke:#C98D7C,color:#754438
    style B fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style C fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style D fill:#EAF3EC,stroke:#83A995,color:#315D49
    style E fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style F fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style G fill:#EAF3EC,stroke:#83A995,color:#315D49
    style H fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style I fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style J fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style K fill:#F7EAE7,stroke:#C98D7C,color:#754438
    style L fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style M fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style N fill:#EAF3EC,stroke:#83A995,color:#315D49
    style O fill:#F5F8F4,stroke:#B5CBBB,color:#40594A

9. Autonomous Decision-Making and Boundary Control for Long-Cycle Agents

Autonomous execution does not mean that an Agent can perform any operation without restriction.

A truly reliable autonomous Agent must operate under constraints on goals, permissions, resources, and risks.

1. Levels of Autonomous Decision-Making

The degree of autonomy can be divided into four levels:

Level Decision-Making Method Example
L1 Execute a fixed workflow Collect data according to predefined steps
L2 Select an execution path Choose the collection method based on the data situation
L3 Dynamically adjust the plan Reschedule tasks after a failure
L4 Autonomously manage goals Continuously optimize the execution strategy within constraints

The higher the degree of autonomy, the more robust permission control and audit mechanisms are required.

2. Define Task Boundaries

At task startup, the following should be clearly defined:

  • Which systems are allowed to be accessed?
  • Which data is allowed to be read?
  • Which files are allowed to be modified?
  • Is sending emails allowed?
  • Is publishing content allowed?
  • Are billable operations allowed?
  • What is the budget cap?
  • When must the task end at the latest?
  • Which actions require human approval?

These constraints should be stored as structured policies rather than merely placed in the Prompt.