AI Engineer · Published 2026-05-10

How we solved Context Management in Agents — Sally-Ann Delucia

Open on YouTube ↗

Summary

Overview

  • Speaker: Sally-Ann Delucia
  • Channel: AI Engineer
  • Main topic: Context Management and Memory Strategies for AI Agents
  • Purpose: To share practical engineering and product lessons on managing context windows, memory, and multi-agent delegation in production AI applications. Sally-Ann Delucia, Head of Product at Arize, shares hard-won lessons from building and scaling the AI agent Alyx over nearly a year. She explores the evolution from prompt engineering to context engineering, detailing why naive context strategies like truncation or LLM summarization fail, and outlines practical solutions including smart truncation, memory stores, sub-agents for offloading heavy tasks, and long-session evaluations.

Topic Map

Introduction and What is Alyx

  • Explanation: Introduction of the speaker and Alyx, an AI harness built on top of Arize's observability platform with over 40 skills and advanced planning.
  • Key claims:
    • Building successful AI agents is extremely difficult.
    • Alyx is an AI harness used to build AI applications.
  • Examples:
    • Alyx features include prompt optimization, data generation, augmentation, and annotations.
  • Terminology:
    • AI harness
    • Alyx
    • Arize
  • Why it matters: Establishes the speaker's first-hand experience and context for the engineering challenges discussed.

The Problem: Context Engineering over Prompt Engineering

  • Explanation: Citing Andrej Karpathy's concept of context engineering, the speaker explains that context is the new engineering problem because LLMs require the right context to perform optimally.
  • Key claims:
    • The stack is changing from prompt engineering to context engineering.
    • Too much or too little context hurts performance and increases costs.
  • Examples:
    • Agent traces in observability platforms multiply rapidly as user interaction grows.
  • Terminology:
    • Context engineering
    • Prompt engineering
    • Token limit
  • Why it matters: Frames context management as a critical product and UX problem, not just a technical token-limit challenge.

The Vicious Loop and Failed Strategies

  • Explanation: Discussion of the vicious loop where agent spans grow, hit context limits, fail, and retry with the same bloated data, as well as why naive truncation and LLM summarization failed.
  • Key claims:
    • Naive truncation causes agents to forget everything and break reasoning.
    • LLM summarization is too inconsistent, lacks control over importance, and is unreliable.
  • Examples:
    • Taking the first 100 characters of a long context blob caused follow-up questions to look like new conversations.
  • Terminology:
    • Naive truncation
    • LLM summarization
    • Context limit
  • Why it matters: Demonstrates what does not work when trying to fit growing conversation history into model windows.

Escaping the Loop: Smart Truncation and Memory

  • Explanation: Presenting the working solution used in Alyx combining smart truncation (keeping head and tail, removing duplicates) with an external memory store.
  • Key claims:
    • Context decides what the model sees; memory decides what survives.
    • Smart truncation preserves the head and tail while retrieving middle content by ID from memory.
  • Examples:
    • Keeping latest results, avoiding system prompt resets, and truncating the middle of long tool calls.
  • Terminology:
    • Smart truncation
    • Memory store
    • Head and tail strategy
  • Why it matters: Provides a robust, reproducible pattern for handling context growth in conversational agents.

Handling Long Sessions and Sub-Agents

  • Explanation: Addressing the challenges of long user sessions and introducing sub-agents to offload data-intensive tasks like search.
  • Key claims:
    • Users rarely restart chats, causing conversations and failures to appear late.
    • Not all context belongs in the same agent; sub-agents offload heavy tasks.
  • Examples:
    • Search tasks involving multiple queries and intermediate reasoning are delegated to sub-agents, returning only results to the main conversation.
  • Terminology:
    • Long-session evals
    • Sub-agents
    • Trace stack
  • Why it matters: Shows how architectural partitioning (sub-agents) solves scaling issues in complex AI workflows.

What We're Still Figuring Out

  • Explanation: Open challenges in agent context management including massive contexts hitting provider limits, true long-term memory, and principled context selection heuristics.
  • Key claims:
    • Huge contexts still break provider limits when agents operate on agent data.
    • Real long-term memory across sessions and surfaces is still hard and unbuilt.
  • Examples:
    • Users moving across different application surfaces expecting continuous memory.
  • Terminology:
    • Long-term memory
    • Context budget
    • Context quality metrics
  • Why it matters: Highlights the frontier of agent architecture and research areas for AI engineers.

Key Points

Context engineering replaces prompt engineering

  • Explanation: Choosing strategically what the model sees matters more than just prompt wording or staying under token limits.
  • Evidence: Karpathy's quote on context engineering and observed agent failure modes when context is poorly curated.
  • Practical implication: Engineers must design sophisticated context retrieval and filtering mechanisms rather than dumping raw conversation histories.

Naive approaches like truncation and summarization fail

  • Explanation: Dropping characters breaks reasoning, and LLM summarization is too inconsistent and unreliable.
  • Evidence: First-hand development trials with Alyx where agents completely forgot context or generated erratic summaries.
  • Practical implication: Avoid relying solely on basic programmatic cutoffs or asking LLMs to summarize context dynamically without structural control.

Smart truncation paired with external memory works

  • Explanation: Keeping the head and tail of conversations while storing intermediate tool calls and messages in an ID-addressable memory store provides balance.
  • Evidence: Successful production deployment in Alyx where agents can pull context by ID when needed.
  • Practical implication: Implement hybrid architectures where short-term active context is pruned smartly and long-term context is stored externally.

Sub-agents offload heavy workflows

  • Explanation: Delegating complex, data-heavy tasks (like search) to sub-agents keeps the main conversation context small and clean.
  • Evidence: Reduction of context bloat and failure rates in Alyx after introducing specialized sub-agents.
  • Practical implication: Use multi-agent hierarchies where sub-agents handle data-intensive operations and return only distilled summaries.

Frameworks, Models & Processes

Smart Truncation + Memory Strategy

  • How it works: Combines selective message retention in the active prompt with an external memory store accessed via unique IDs.
  • Components:
    • Head retention (initial context)
    • Tail retention (recent messages)
    • Middle truncation (removed from prompt, stored in memory)
    • ID-based retrieval mechanism
  • When to use: When building conversational agents with long chat sessions and heavy tool-call history.

Examples & Case Studies

Applying naive character truncation (first 100 characters) to agent context.

  • Illustrates: The failure mode of over-truncation.
  • Lesson: The agent forgot everything, and follow-up questions were treated as entirely new conversations.

Delegating search tasks with multiple queries and intermediate reasoning to separate sub-agents.

  • Illustrates: The effectiveness of architectural offloading.
  • Lesson: Keeping heavy data out of the main conversation keeps the primary agent performant and error-free.

Actionable Takeaways

  • Immediate:
    • Stop relying on naive truncation or raw LLM summarization for context windows.
    • Implement head-and-tail context retention with ID-based memory retrieval.
    • Offload data-intensive tasks to sub-agents to keep main conversation context lightweight.
  • Strategic:
    • Context management is fundamentally a product and UX problem, not just an engineering one.
    • Build long-session evaluations (e.g., testing the 11th turn after loading 10) to catch context bugs early.
    • Recognize that agents do not fail because of prompts; they fail because of context.
  • Questions to investigate:
    • How can we build true long-term memory across disjoint sessions and application surfaces?
    • What are principled context budgets and clear quantitative metrics for context quality?
    • How can we prevent provider limits from breaking multi-agent systems operating on extensive trace data?

Claims Worth Verifying

  • Context engineering is more impactful than prompt engineering for agent success. (conceptual)
  • Smart truncation combined with external memory eliminates context overflow loops in production agents. (architectural)

Notable Quotes

"The best context strategy is the one that lets your agent remember what matters and forget what doesn't." "Context management is a product + UX problem, not just an engineering one." "Context decides what the model sees. Memory decides what survives." "Agents don't fail because of prompts. They fail because of context."

Compressed Summary

  • Context engineering replaces prompt engineering as the critical bottleneck in AI agents.
  • Naive truncation and raw LLM summarization fail due to loss of reasoning and inconsistency.
  • Smart truncation (head + tail + memory store) successfully manages active conversation bloat.
  • Sub-agents isolate data-heavy workflows like search, keeping main agent context small.
  • Long-session evaluations are essential for catching context degradation bugs before users do.
  • Keywords: context engineering, smart truncation, memory store, sub-agents, agent architecture
  • Core insight: AI agents fail due to poor context management rather than prompts, requiring structured head-tail truncation, external memory, and sub-agent delegation to succeed in production.

Core insights

6
Mental Modelmedium noveltymoderate evidence

The binding constraint in agent quality is shifting from prompt wording to context selection: what the model sees (and what it does not see) must be engineered deliberately, because too much or too little context both degrade performance and raise cost.

Why it matters

Treats context management as a primary design problem on par with model choice or tool definitions, not an afterthought when hitting token limits.

Generalization

Any agent that consumes conversation history, tool outputs, or retrieved documents needs an explicit context policy rather than raw pass-through.

The stack is changing from prompt engineering to context engineering.
Open source video
Too much or too little context hurts performance and increases costs.
Open source video
Failure Modemedium noveltystrong evidence

Simple context-reduction techniques backfire in agent loops: naive truncation severs reasoning threads and makes follow-ups look like new conversations, while LLM summarization is too inconsistent and cannot be steered by importance.

Why it matters

Engineers reaching for the easiest token-reduction fix will introduce subtle, hard-to-debug reasoning failures instead of solving context growth.

Generalization

Any truncation or compression layer must preserve reasoning-critical anchors (system prompt, recent intent, active tool state) rather than arbitrary boundaries.

Naive truncation causes agents to forget everything and break reasoning.
Open source video
LLM summarization is too inconsistent, lacks control over importance, and is unreliable.
Open source video
Mechanismmedium noveltystrong evidence

A robust production pattern is smart truncation plus an external memory store: keep the head (initial context) and tail (recent messages), remove the middle, store it by ID, and let the agent retrieve middle content when needed.

Why it matters

Provides a concrete, implementable design for long-lived agents that avoids both the reasoning loss of naive truncation and the inconsistency of summarization.

Generalization

Conversational agents should separate what the model currently sees from everything that ever happened; the prompt is a curated view over an addressable history.

Smart truncation preserves the head and tail while retrieving middle content by ID from memory.
Open source video
Keeping latest results, avoiding system prompt resets, and truncating the middle of long tool calls.
Open source video
Architecturemedium noveltystrong evidence

Not all context belongs in the main agent's window; sub-agents can absorb data-heavy tasks (e.g., search) and return only distilled results, keeping the primary conversation small and clean.

Why it matters

Shows that context management is not only about pruning messages but also about architectural partitioning of work across agent boundaries.

Generalization

When a task requires many intermediate queries or large tool outputs, delegate to a child agent whose full trace is not loaded into the parent context.

Not all context belongs in the same agent; sub-agents offload heavy tasks.
Open source video
Search tasks involving multiple queries and intermediate reasoning are delegated to sub-agents, returning only results to the main conversation.
Open source video
Empirical Resultmedium noveltymoderate evidence

Real user sessions are long and rarely restarted, so context-related failures show up late; evaluation must therefore include long-session scenarios rather than only single-turn or short-context tests.

Why it matters

Standard short-turn evals can miss the primary failure mode of production agents, which is gradual context degradation over a session.

Generalization

Agent evaluation should explicitly model session length, context growth, and late-appearing failures as first-class test dimensions.

Users rarely restart chats, causing conversations and failures to appear late.
Open source video
Long-session evals
Open source video
Predictionhigh noveltymoderate evidence

At the frontier, very large contexts and true long-term memory remain unsolved: agent-on-agent traces can exceed provider limits, and users expect continuous memory across application surfaces that current systems do not provide.

Why it matters

Identifies the next set of hard problems for agent infrastructure, where off-the-shelf solutions do not exist.

Generalization

Agent platforms should plan for context hierarchies and cross-session memory rather than assuming the model's window will eventually suffice.

Huge contexts still break provider limits when agents operate on agent data.
Open source video
Real long-term memory across sessions and surfaces is still hard and unbuilt.
Open source video

Deep dives

4

Context quality metrics for selective retention decisions in agent conversations

Research question

What measurable properties of a conversation segment predict whether discarding it from the active context window will degrade downstream agent task performance?

Why

Without a proxy for importance, teams are forced into heuristics like head/tail truncation or summarization, both of which underperform on long sessions; a metric would enable principled retention and retrieval.

Too much or too little context hurts performance and increases costs.
Open source video
Smart truncation preserves the head and tail while retrieving middle content by ID from memory.
Open source video
Source video

Hierarchical context distillation for agent-on-agent traces

Research question

How can agent traces be compressed or distilled hierarchically when the traces are generated by other agents, so that parent agents can reason over aggregated outcomes without exceeding provider context limits?

Why

Agent-on-agent traces can exceed model provider limits even when individual agent contexts stay small; current smart truncation and memory store do not solve this cross-agent trace growth.

Huge contexts still break provider limits when agents operate on agent data.
Open source video
Source video

Long-session evaluation methodology for context degradation

Research question

What is the minimal set of long-session evaluation scenarios needed to reliably reproduce context-degradation failures in production agents?

Why

Standard short-turn evals miss the dominant production failure mode of context bloat, because users rarely restart chats and failures appear late.

Users rarely restart chats, causing conversations and failures to appear late.
Open source video
Long-session evals
Open source video
Source video

Deterministic mid-context retrieval vs LLM summarization for agent memory

Research question

Under what task conditions does an ID-addressable memory store with head/tail truncation outperform LLM summarization in preserving task-relevant information across long conversations?

Why

LLM summarization is inconsistent and uncontrollable, while smart truncation is deterministic but risks discarding important middle content if retrieval is imperfect; a controlled comparison would settle the tradeoff.

LLM summarization is too inconsistent, lacks control over importance, and is unreliable.
Open source video
Source video

Article ideas

4

Context Engineering Is the New Full-Stack Problem

Agent quality is now determined by a context policy layer—what stays, what is retrieved, and what is delegated—not by prompt wording alone.

Angle

Argue from the failure of naive truncation and summarization to the need for an explicit context architecture in agent harnesses.

Source video

Stop Summarizing Your Agent's Memory

LLM summarization is the wrong default for agent memory because it sacrifices control and reproducibility; an external memory store with smart truncation gives you deterministic, auditable context.

Angle

Comparative engineering essay showing why deterministic head/tail + ID retrieval beats probabilistic summarization.

Source video

Your Agent's Context Window Is a UX Contract

Long-session UX—what users remember and expect the agent to remember—should drive context retention decisions, making context management a product requirement rather than a token optimization.

Angle

Product/UX lens on context engineering, emphasizing that session continuity is a user expectation.

Source video

Sub-Agents Are Your Context Budget

The real reason to delegate to sub-agents is not task decomposition but context isolation: it forces the parent to operate on distilled results, reducing bloat and cost while improving reliability.

Angle

Architectural opinion piece arguing that sub-agents are a context-budget mechanism, not just a scaling tool.

Source video

Project ideas

4

HeadTail Memory Agent Harness

movement-lab

A harness that keeps the first 10% and last 20% of conversation tokens and retrieves the middle by ID will maintain task success above 85% over 50-turn sessions, while naive last-N truncation drops below 50%.

Proof of concept

Build a minimal agent runtime with a message store and two context policies: naive last-N truncation and head/tail + ID retrieval. Run a 50-turn multi-step benchmark.

Measurement

Task success rate at turn 50; retrieval hit rate; total tokens consumed.

Source video

Sub-Agent Context Isolation Benchmark

movement-lab

Delegating multi-query search tasks to a sub-agent reduces parent context size by at least 40% and reduces end-to-end failure rate by 20% compared to a monolithic agent, with no loss in answer quality.

Proof of concept

Implement a monolithic search agent and a parent/sub-agent version; run a suite of 100 information-gathering tasks; measure parent context length and task success.

Measurement

Parent context token count; failure rate; answer quality (LLM-as-judge or human label).

Source video

Long-Session Context Eval Suite

beyond-evals

A 50-turn eval suite will surface at least twice as many context-related failures as the same suite evaluated at turn 1 and turn 5.

Proof of concept

Create an eval harness that can run agent tasks up to 50+ turns, injecting realistic user sessions, and compare failure rates across turn lengths.

Measurement

Context-related failure rate by turn number; regression precision (failure cases reproducible).

Source video

Cross-Surface Memory Store

new

An ID-addressable memory store with user identity can answer questions about facts from a previous conversation on a different surface with at least 70% precision without explicit continuation.

Proof of concept

Build a small memory service, expose it to two chat surfaces, store conversation events with user IDs, and query after a new session begins.

Measurement

Retrieval precision/recall for cross-session facts; qualitative continuity score.

Source video

Architectural implications

4

Context is treated as a first-class engineering surface, not a token-limit problem.

Before

Engineering focused on prompt wording, model selection, and staying under token limits.

After

Teams need a context policy layer that filters, retains, and retrieves what the model sees.

Consequence

Agent harnesses and runtimes must own context curation, with observability into what was included and why.

Source video

History is split between an active prompt and an external memory store.

Before

Conversation history is replayed in full or cut off when it grows.

After

A slim prompt keeps head and tail, while middle messages and tool calls live in an ID-addressable store that can be pulled on demand.

Consequence

Memory becomes an infrastructure component with retrieval semantics, not just a model parameter.

Source video

Sub-agents are a mechanism for context isolation.

Before

A single agent accumulates all tool traces and intermediate reasoning in its context.

After

Heavy, multi-step tasks are delegated to sub-agents that return only distilled results.

Consequence

The main agent's context window stays small, and failure isolation shifts to a trace stack spanning parent and child agents.

Source video

Evaluation must span long sessions because degradation is late-onset.

Before

Evals are mostly single-turn or short scenarios.

After

Long-session evals are needed to catch context-related failures.

Consequence

Testing cost increases, but catches the dominant production failure mode of context bloat.

Source video

Tradeoffs and failure modes

3

Naive truncation

Benefit

Reduces tokens and fits more conversation into the window cheaply.

Cost or risk

Forgets prior intent and breaks multi-turn reasoning; follow-ups appear as new conversations.

Naive truncation causes agents to forget everything and break reasoning.
Open source video
Source video

LLM summarization

Benefit

Compresses context without arbitrary cutoffs.

Cost or risk

Outputs are inconsistent, cannot be controlled for importance, and are unreliable for downstream reasoning.

LLM summarization is too inconsistent, lacks control over importance, and is unreliable.
Open source video
Source video

Keeping everything in context

Benefit

No information loss and no retrieval machinery.

Cost or risk

Agent traces grow until provider limits are hit, especially when agents operate on agent-generated data.

Huge contexts still break provider limits when agents operate on agent data.
Open source video
Source video

Open questions

3

How should agents handle contexts that exceed provider limits, particularly when agents operate on agent-generated data?

Why unresolved

Even with smart truncation and an external memory store, huge contexts still break provider limits.

Research direction

Hierarchical context distillation, context budgets, and quality metrics to decide what must stay in-window.

Source video

What are the right heuristics for deciding which middle content to keep, truncate, or retrieve?

Why unresolved

The speaker lists principled context selection heuristics as still being figured out.

Research direction

Design and measure context quality metrics; benchmark candidate selection policies on long-session evals.

Source video

How can true long-term memory be built across sessions and application surfaces?

Why unresolved

Current systems lack persistent memory; users moving across surfaces expect continuity that does not exist.

Research direction

Cross-session memory stores with explicit identity and retrieval, plus evaluations for continuity.

Source video

Key claims

8
predictionVerification needed

The stack is changing from prompt engineering to context engineering.

Evidence

The stack is changing from prompt engineering to context engineering.

Question

What fraction of production agent teams now have dedicated context-selection strategies rather than relying on prompt wording?

Source video
causalVerification needed

Too much or too little context hurts performance and increases costs.

Evidence

Too much or too little context hurts performance and increases costs.

Question

Can a controlled study quantify optimal context size per task type?

Source video
causalVerification needed

Naive truncation causes agents to forget everything and break reasoning.

Evidence

Naive truncation causes agents to forget everything and break reasoning.

Question

At what truncation thresholds or patterns does degradation first appear?

Source video
comparativeVerification needed

LLM summarization is too inconsistent, lacks control over importance, and is unreliable.

Evidence

LLM summarization is too inconsistent, lacks control over importance, and is unreliable.

Question

Compared to smart truncation, how much variance does LLM summarization introduce in task outcomes?

Source video
factualVerification needed

Smart truncation with an external memory store works in production.

Evidence

Smart truncation preserves the head and tail while retrieving middle content by ID from memory.

Question

What are the retrieval-success rates when the agent requests middle content by ID?

Source video
causalVerification needed

Sub-agents reduce context bloat and failure rates.

Evidence

Reduction of context bloat and failure rates in Alyx after introducing specialized sub-agents.

Question

By how much did context size and failure rates change in the Alyx rollout?

Source video
factualVerification needed

Users rarely restart chats, causing conversations and failures to appear late.

Evidence

Users rarely restart chats, causing conversations and failures to appear late.

Question

What is the observed session-length distribution for production agents?

Source video
factualVerification needed

Huge contexts still break provider limits when agents operate on agent data.

Evidence

Huge contexts still break provider limits when agents operate on agent data.

Question

Under what agent-on-agent workloads do provider limits bind first?

Source video

Connections

5