Skip to content

Context Management in Agent Harnesses

How agents stay effective over long tasks: what to keep in context, what to summarise, and what to store outside.

Editorial team 1 min read

Every step adds tool calls and results to an agent's context. On long tasks the context fills up, costs rise and quality can drop. Managing it is a core harness job.

What Consumes Context

  • System instructions and tool definitions.
  • Conversation history.
  • Tool results — often the largest part: file contents, search results, logs.

Techniques

  • Truncate tool output: return summaries or the relevant portion, with a way to fetch more.
  • Clear old results: once a tool result has been used, older verbose results can be removed or shortened.
  • Compaction: summarise the history so far and continue from the summary when context gets full.
  • External memory: write notes, plans and progress to files the agent can re-read.
  • Sub-agents: delegate a sub-task to a separate agent with fresh context and receive back only its conclusion.

Just-in-Time Retrieval

Rather than loading everything up front, give the agent tools to find information when needed — search, list files, read a section.

Preserve What Matters

When compacting, keep the goal, key decisions, constraints, unresolved problems and current state. Losing these causes repeated work and errors.

Measure

Test long tasks specifically; context problems often only appear after many steps.

More in Agent harnesses

All Agent harnesses guides →
Agent harnesses Guide · 2 min

What Is an Agent Harness?

The software around a language model that turns it into an agent: the loop, tools, context, permissions and memory.

Agent harnesses 2 min read 27 Sep 2025

Agent harnesses Guide · 1 min

The Agent Loop Explained

The core cycle every agent runs: think, call a tool, observe the result, repeat — and how the loop knows when to stop.

Agent harnesses 1 min read 26 Sep 2025

Agent harnesses Guide · 1 min

Designing Tools for AI Agents

How to write tools agents use well: clear names, precise descriptions, sensible inputs and informative outputs.

Agent harnesses 1 min read 25 Sep 2025

Agent harnesses Guide · 1 min

Permissions and Approval in Agent Harnesses

Controlling what agents can do on their own: allow lists, approval prompts, forbidden actions and escalation.

Agent harnesses 1 min read 23 Sep 2025