Back to all articles
ai automationAI Agents

From Copilots to Delegates: Designing Software for Long-Running AI Agents

Active-session copilots suggest edits; long-running autonomous delegates execute multi-step workflows. Moving from copilots to delegates requires durable execution, event-sourced state machines, and structured task checkpointing.

August 20, 2026
12-14 min read
Digital Elliptical Engineering (Principal AI Architect)
delegate_timeline.exe
Copilot Paradigm
USER SESSIONActive Browser Tab
User: Write a Python script to...
Assistant: Here is a suggestion...
Sync Request/ResponseTTL: Session end
Delegate ParadigmDURABLE TASK RUNNING
Task Detached
Context Assembly
Execution Loop
Safety Gate
Result Returned
Task ID: dsk_983274_a
Durable Engine: Event-Sourced Loop
Uptime: 04h 32m 11s

Executive Summary

  • Copilots are synchronous interfaces bound to an active HTTP/Websocket session; delegates are asynchronous systems running on durable event buses.
  • Long-running tasks must survive server restarts and network drift through deterministic event sourcing and transaction logs.
  • A delegate's state is an immutable sequence of planning, tool execution, and verification events.
  • Tool boundaries must enforce strict parameters, execution budgets, and cryptographically signed checkpoint state.
  • Human approval gates are not UI overrides; they are native step-up states in the execution machine.

The session boundary: Copilots vs Delegates

Inline coding assistants and conversational chatbots operate under a synchronous session model. The user types a query, the system holds the connection open, issues a prompt to a language model, and returns a single stream of text. The state of this interaction is ephemeral, living and dying with the active HTTP request or WebSocket connection.

Autonomous delegates break this session model. A delegate is tasked with a high-level goal—such as resolving a repository issue or reconciling monthly vendor invoices—that may require dozens of model reasoning loops, external API calls, and sandboxed test executions. These tasks can run for minutes, hours, or even days.

To build reliable delegates, we cannot rely on persistent runtime memory. Server upgrades, network timeouts, and container recycling will inevitably terminate long-running processes. We must shift from memory-bound session loops to durable background execution systems.

Structural differences: Copilot vs Delegate

FeatureDimensionCopilot ParadigmDelegate Paradigm
Execution ContextSynchronous active sessionAsynchronous background worker
State ManagementInMemory chat historyImmutable event ledger on disk
Failure ModeStream disconnection, prompt retryProcess termination, state recovery
External Tool UseRead-only context lookupState-mutating API/Shell operations
Human InteractionContinuous interactive chatStep-up challenge/approval gates

Structuring event-sourced state machines

In a traditional software architecture, an agent is often written as a simple loop: while task not complete, select tool, run tool, update context. If the server restarts mid-loop, the state of the agent is lost, and the next run starts from scratch, wasting tokens and risking duplicate mutations.

Instead of storing the current state of the agent as a mutable database row, we should store it as an immutable sequence of historic events. This is the event sourcing pattern. When a background worker resumes a task, it reconstructs the agent's state by replaying these events from the database.

Every phase transition—creating a plan, selecting a tool, receiving tool outputs, encountering schema validation errors, and receiving human confirmation—is appended to this journal. This architecture ensures total auditability and guarantees that side effects are executed exactly once.

Event-sourced agent execution timeline

Task Created
Plan DAG Generated
Tool Execution Initiated
State Snapshot Serialized
Worker Crashed & Restarted
Replay & Resume Execution

A durable agent reconstructs state by replaying immutable history, allowing execution to resume from the last successful checkpoint.

Checkpointing and serialization contracts

Replaying every single model generation and tool execution from scratch on restart is computationally expensive and slow. To optimize recovery, the system must write periodic state checkpoints. A checkpoint represents a flattened snapshot of the agent's working memory, active environment tokens, and planned execution graph.

When designing these checkpoints, strict serialization is mandatory. The entire state envelope must be serialized into strongly-typed schemas (such as Pydantic models in Python or TypeScript interfaces) and saved to a durable transaction database like PostgreSQL or Redis.

This boundary forces the agent to serialize its internal memory state explicitly at the end of every tool step. By persisting this boundary on disk, we separate the stateless LLM reasoning worker from the stateful execution engine.

Avoid raw string serialization

Serializing working context as unstructured markdown strings or unstructured logs will cause parsing failures on replay. Enforce structured JSON schemas at every boundary checkpoint.

Code contract for durable agent task

A durable agent task must define explicit interfaces for state serialization, execution phases, and replay triggers. The example below details a TypeScript schema for an event-sourced agent loop that can be suspended and resumed across processes.

AgentTaskState.ts
TypeScript Interface
export interface AgentTaskEvent { id: string; taskId: string; timestamp: string; eventType: "PLAN_CREATED" | "TOOL_CALLED" | "TOOL_COMPLETED" | "APPROVAL_REQUESTED" | "TASK_FINISHED"; payload: Record<string, any>; } export interface AgentTaskCheckpoint { taskId: string; sequenceNumber: number; updatedAt: string; state: { memory: Array<{ role: string; content: string }>; activePlan: string[]; completedSteps: string[]; pendingApprovals: string[]; }; } export interface DurableAgentWorker { runTask(taskId: string): Promise<void>; suspendTask(taskId: string, reason: string): Promise<void>; resumeTask(taskId: string): Promise<void>; }

Failure isolation and timeout circuit breakers

Long-running agents execute actions inside external systems. Mutating tools, such as running a shell command or making a third-party API post request, are major failure vectors. A network drop, an infinite loop in generated code, or an API rate limit will block a stateless agent loop.

We isolate these failures using three patterns: Ephemeral sandboxing, Timeout circuit breakers, and Exponential backoff retry with jitter.

Mutating shell commands must execute inside ephemeral container sandboxes (such as Docker or firewalled Kubernetes pods) to prevent system-level damage. Every tool execution must have a strict timeout budget (e.g., maximum 30 seconds). If a tool fails or times out, the circuit breaker trips, the failure is written to the event log, and the agent is forced to re-plan or request assistance.

Integrating human approval gates

High-stakes actions—like issuing payments, deleting data, or merging code to production—must not be executed autonomously. We require Human-in-the-Loop (HITL) authorization.

An approval gate is not an afterthought implemented at the UI layer. It is a core state transition in the agent's event loop. When a task reaches a protected tool step, the execution loop suspends itself, serializes the current checkpoint, writes an `APPROVAL_REQUESTED` event, and alerts the human supervisor.

Once the human approves or rejects the payload, the supervisor writes a signed `APPROVAL_GRANTED` event. The task queue picks up the suspended task, replays the audit trail, verifies the cryptographic signature of the approval event, and resumes execution.

Step-up approval sequence

1
Agent identifies a high-risk tool call (e.g., write database)
2
Worker suspends execution loop and serializes checkpoint state
3
Event queue writes an 'APPROVAL_REQUESTED' event and raises a notification
4
Human supervisor reviews the proposed payload and issues a signed approval
5
Asynchronous worker reloads checkpoint, verifies approval signature, and triggers the tool

Operational deployment checklist

Verify these architectural boundaries before deploying autonomous delegates to production environments.

Production readiness checks

1State & Replay
  • All memory variables are serialized to database checkpoints
  • Replay engine is tested to reconstruct agent state deterministically
  • Idempotency keys are forced on all outgoing mutating tools
2Security & Sandbox
  • Mutating tool execution is isolated in unprivileged Docker/gVisor sandboxes
  • Network egress is restricted to whitelisted domains
  • System instructions are structurally separated from untrusted data payloads
3Governance
  • Human approval gates are written to the database event log
  • Global kill-switch instantly revokes worker session credentials
  • Token burn limits are enforced at the organization and tenant level
Decision path

Migrate your AI workflows from copilots to durable delegates

Bring your active conversational interfaces. We will help you design asynchronous task queues, state serialization schemas, and secure execution boundaries for long-running agents.

Schedule an agent architecture session

Keep Reading