DEV Community

Vincent Tuan for Coryntas

Posted on • Originally published at coryntas.com

Long-Running AI Agents Accumulate Context Debt

An illustrative reporting agent prepares a monthly operating review. It queries finance, CRM, support, and the data warehouse; compares this month with prior periods; investigates material changes; drafts explanations; collects owner comments; and revises the report over several days.

By the third revision, its context contains raw query results, discarded hypotheses, repeated instructions, old owner comments, and the current draft. The most important correction—a finance owner rejecting the original revenue explanation—now competes with everything that came before it.

The agent has not run out of intelligence. It has accumulated context debt: temporary execution material has become permanent reasoning input.

The context window is a working surface, not the system of record

Keeping every intermediate result in the model context feels safe because nothing is lost. In practice, relevance declines as a run grows:

  • large tool responses consume tokens;
  • old instructions conflict with newer decisions;
  • repeated summaries introduce small distortions;
  • rejected hypotheses remain close to accepted findings; and
  • the current deliverable becomes harder to distinguish from earlier drafts.

A larger context window delays this problem. It does not define which state is authoritative, which evidence is recoverable, or which decisions should survive a restart.

A long-running workflow needs at least four storage roles.

1. Working context

The current objective, immediate constraints, selected evidence, and next executable step belong here. This set should be small enough that every item can affect the next decision.

2. Durable task state

Completed checkpoints, owners, approvals, deadlines, open exceptions, and permitted next actions should live outside the prompt. This state must survive model calls, worker restarts, and handoffs.

3. Evidence storage

Raw source results should be retained with stable identifiers, timestamps, and access controls. The agent can reload them when a later step needs inspection without injecting every record into every prompt.

4. Deliverable state

The current report, plan, ticket, or other business artifact needs its own version history. Reviewer changes should update this artifact without turning the entire conversation transcript into the only record of what changed.

Moving material out of the prompt is not deletion. It is putting information where the runtime can retrieve it deliberately.

Compaction should preserve decisions, not merely shorten text

A generic conversation summary may retain the topic while losing the operational fact that matters: who rejected an explanation, which source replaced it, and whether the correction applies to one metric or the entire report.

A useful checkpoint is structured. For example:

{
  "task_id": "monthly-review-2026-07",
  "objective": "Produce an approved operating review",
  "checkpoint": "finance-variance-reviewed",
  "accepted_findings": [
    {
      "metric": "net_revenue_retention",
      "explanation": "Two enterprise downgrades",
      "evidence_refs": ["warehouse:q_184", "crm:acct_72"]
    }
  ],
  "rejected_findings": [
    {
      "explanation": "FX movement",
      "rejected_by": "finance-owner",
      "decided_at": "2026-08-03T09:20:00Z"
    }
  ],
  "open_questions": ["Confirm support-cost allocation"],
  "allowed_next_actions": ["analyze_support_costs", "request_owner_review"]
}
Enter fullscreen mode Exit fullscreen mode

The exact schema will vary. The important part is separating decisions from the tokens that produced them.

Each checkpoint should answer:

  1. What remains in model context?
  2. What moves to durable state?
  3. Which raw evidence can be recovered later?
  4. Which actions are valid from this state?

Compaction, subtask isolation, and progressively loaded instructions are mechanisms for enforcing those choices. They are not substitutes for a state model.

Subtasks need isolation and a shared contract

The reporting workflow can separate finance variance analysis, sales pipeline changes, and support-volume analysis. Each subtask receives only the systems, definitions, and period relevant to its work.

Isolation reduces interference, but it creates an integration problem. The coordinating agent cannot safely reconcile three polished narratives that use different definitions.

A shared result contract might require every subtask to return:

  • metric identifier and reporting period;
  • current and comparison values;
  • explanation and confidence;
  • authoritative source references;
  • unresolved issues; and
  • requested decisions or approvals.

This contract does more than improve formatting. It gives the coordinator a stable boundary for validation, comparison, and retry.

If one subtask fails, the runtime can rerun that unit without replaying the entire workflow. If a reviewer corrects a metric definition, the system can invalidate only the findings that depend on it.

Resuming is a first-class operation

A long-running agent should be tested from checkpoints, not only from the beginning.

At resume time, the runtime should be able to reconstruct:

  • the current objective and accepted deliverable version;
  • completed and pending steps;
  • active owners and deadlines;
  • the latest authoritative decisions;
  • evidence references needed for the next step; and
  • the permissions that are still valid.

This last item matters because authority can change while a workflow is paused. A task approved yesterday may require a new check before an agent performs the action today.

A resume test is therefore more than loading a saved prompt. It verifies that the workflow can rebuild the minimum trustworthy working set from durable state.

Context debt has an operating cost

External state introduces storage, retention, and access-control decisions. Compaction can omit a detail that later becomes important. Subtask isolation increases orchestration complexity. Reloading evidence can add latency.

Those are measurable tradeoffs. Useful signals include:

  • context size by workflow stage;
  • repeated retrieval of the same evidence;
  • compaction corrections by reviewers;
  • checkpoint resume failures;
  • stale decisions used after a restart;
  • evidence reload latency; and
  • cost per accepted deliverable.

Some work should pause instead of compacting. If reviewers fundamentally change the objective, starting a new version with an explicit handoff may be safer than asking the agent to reinterpret a long and contradictory history.

Finish with a record another run can trust

The completed report should retain its reporting period, metric definitions, reviewer decisions, evidence references, and unresolved caveats. Next month's agent can use the accepted artifact as a comparison without inheriting all of the execution debris that created it.

Context debt appears when a system confuses memory with accumulation. Long-running agents need a maintained working set and a durable operating record—not an endlessly growing prompt.

How are you separating working context from durable task state in your long-running agents?


This article was adapted for the DEV community from Long-Running Agents Accumulate Context Debt, originally published by Coryntas.

Top comments (0)