The panorama of AI agent growth is shifting quick. We’ve moved past prototyping single-turn chatbots. Immediately, organizations are deploying refined, autonomous brokers to deal with long-horizon duties: automating workflows, conducting deep analysis, and sustaining advanced codebases.
That ambition instantly runs right into a bottleneck: context.
As brokers run longer, the quantity of knowledge they should monitor—chat historical past, device outputs, exterior paperwork, intermediate reasoning—explodes. The prevailing “answer” has been to lean on ever-larger context home windows in basis fashions. However merely giving brokers extra space to stick textual content cannot be the only scaling technique.
To construct production-grade brokers which might be dependable, environment friendly, and debuggable, the business is exploring a brand new self-discipline:
Context engineering — treating context as a first-class system with its personal structure, lifecycle, and constraints.
Based mostly on our expertise scaling advanced single- or multi-agentic techniques, we designed and advanced the context stack in Google Agent Growth Package (ADK) to help that self-discipline. ADK is an open-source, multi-agent-native framework constructed to make lively context engineering achievable in actual techniques.
The scaling bottleneck
A big context window will assist context-related issues however will not tackle all context-related issues. In observe, the naive sample—append every part into one large immediate—collapses underneath a three-way strain:
- Value and latency spirals: Mannequin price and time-to-first-token develop shortly with context measurement. “Shoveling” uncooked historical past and verbose device payloads into the window makes brokers prohibitively gradual and costly.
- Sign degradation (“misplaced within the center”): A context window flooded with irrelevant logs, stale device outputs, or deprecated state can distract the mannequin, inflicting it to fixate on previous patterns moderately than the fast instruction. To make sure sturdy decision-making, we should maximize the density of related info.
- Bodily limits: Actual-world workloads—involving full RAG outcomes, intermediate artifacts, and lengthy dialog traces—ultimately overflow even the biggest fastened home windows.
Throwing extra tokens on the drawback buys time, but it surely doesn’t change the form of the curve. To scale, we have to change how context is represented and managed, not simply how a lot of it we are able to cram right into a single name.
The design thesis: context as a compiled view
Within the earlier era of agent frameworks, context was handled like a mutable string buffer. ADK is constructed round a special thesis: Context is a compiled view over a richer stateful system.
In that view:
- Periods, reminiscence, and artifacts (recordsdata) are the sources– the complete, structured state of the interplay and its information.
- Flows and processors are the compiler pipeline – a sequence of passes that remodel that state.
- The working context is the compiled view you ship to the LLM for this one invocation.
When you undertake this psychological mannequin, context engineering stops being immediate gymnastics and begins wanting like techniques engineering. You might be pressured to ask commonplace techniques questions: What’s the intermediate illustration? The place can we apply compaction? How can we make transformations observable?
ADK’s structure solutions these questions by way of three design ideas:
- Separate storage from presentation: We distinguish between sturdy state (Periods) and per-call views (working context). This lets you evolve storage schemas and immediate codecs independently.
- Express transformations: Context is constructed by named, ordered processors, not ad-hoc string concatenation. This makes the “compilation” step observable and testable.
- Scope by default: Each mannequin name and sub-agent sees the minimal context required. Brokers should attain for extra info explicitly by way of instruments, moderately than being flooded by default.
ADK’s tiered construction, its relevance mechanisms, and its multi-agent handoff semantics—is actually an utility of this “compiler” thesis and these three ideas:
- Construction – a tiered mannequin that separates how info is saved from what the mannequin sees.
- Relevance – agentic and human controls that determine what issues now.
- Multi-agent context – specific semantics for handing off the proper slice of context between brokers.
The subsequent sections stroll by every of those pillars in flip.
1. Construction: The tiered mannequin
Most early agent techniques implicitly assume a single window of context. ADK goes the opposite approach. It separates storage from presentation and organizes context into distinct layers, every with a particular job:
- Working context – the fast immediate for this mannequin name: system directions, agent id, chosen historical past, device outputs, non-compulsory reminiscence outcomes, and references to artifacts.
- Session – the sturdy log of the interplay: each person message, agent reply, device name, device end result, management sign, and error, captured as structured Occasion objects.
- Reminiscence – long-lived, searchable data that outlives a single session: person preferences, and previous conversations.
- Artifacts – giant binary or textual information related to the session or person (recordsdata, logs, photographs), addressed by title and model moderately than pasted into the immediate.
1.1 Working context as a recomputed view
For every invocation, ADK rebuilds the Working Context from the underlying state. It begins with directions and id, pulls in chosen Session occasions, and optionally attaches reminiscence outcomes. This view is ephemeral (thrown away after the decision), configurable (you may change formatting with out migrating storage), and model-agnostic.
This flexibility is the primary win of the compiler view: you cease hard-coding “the immediate” and begin treating it as a derived illustration you may iterate on.
1.2 Flows and processors: context processing as a pipeline
When you separate storage from presentation, you want equipment to “compile” one into the opposite. In ADK, each LLM-based agent is backed by an LLM Stream, which maintains ordered lists of processors.
A (simplified) SingleFlow would possibly appear like:
These flows are ADK’s equipment to compile context. The order issues: every processor builds on the outputs of the earlier steps. This offers you pure insertion factors for customized filtering, compaction methods, caching, and multi-agent routing. You might be not rewriting large “immediate templates”; you’re simply including or reordering processors.
1.3 Session and occasions: structured, language-agnostic historical past
An ADK Session represents the definitive state of a dialog or workflow occasion. Concretely, it acts as a container for session metadata (IDs, app names), a state scratchpad for structured variables, and—most significantly—a chronological checklist of Occasions.
As a substitute of storing uncooked immediate strings, ADK captures each interplay—person messages, agent replies, device calls, outcomes, management indicators, and errors—as strongly-typed Occasion data. This structural alternative pays three distinct benefits:
- Mannequin agnosticism: You possibly can swap underlying fashions with out rewriting the historical past, because the storage format is decoupled from the immediate format.
- Wealthy operations: Downstream elements like compaction, time-travel debugging, and reminiscence ingestion can function over a wealthy occasion stream moderately than parsing opaque textual content.
- Observability: It supplies a pure floor for analytics, permitting you to examine exact state transitions and actions.
The bridge between this session and the working context is the contents processor. It performs the heavy lifting of remodeling the Session into the historical past portion of the working context by executing three important steps:
- Choice: It filters the occasion stream to drop irrelevant occasions, partial occasions, and framework noise that should not attain the mannequin.
- Transformation: It flattens the remaining occasions into
Content materialobjects with the right roles (person/assistant/device) and annotations for the particular mannequin API getting used. - Injection: It writes the formatted historical past into
llm_request.contents, guaranteeing downstream processors—and the mannequin itself—obtain a clear, coherent conversational hint.
On this structure, the Session is your floor fact; the working context is merely a computed projection which you can refine and optimize over time.
1.4 Context compaction and filtering on the session layer
For those who hold appending uncooked occasions indefinitely, latency and token utilization will inevitably spiral uncontrolled. ADK’s Context Compaction function assaults this drawback on the Session layer.
When a configurable threshold (such because the variety of invocations) is reached, ADK triggers an asynchronous course of. It makes use of an LLM to summarize older occasions over a sliding window—outlined by compaction intervals and overlapping measurement—and writes the ensuing abstract again into the Session as a brand new occasion with a “compaction” motion. Crucially, this permits the system to prune or de-prioritize the uncooked occasions that had been summarized.
As a result of compaction operates on the Occasion stream itself, the advantages cascade downstream:
- Scalability: Periods stay bodily manageable even for very long-running conversations.
- Clear views: The
contentsprocessor robotically works over a historical past that’s already compacted, requiring no advanced logic at question time. - Decoupling: You possibly can tune compaction prompts and methods with out touching a single line of agent code or template logic.
This creates a scalable lifecycle for lengthy contexts. For strictly rule-based discount, ADK gives a sibling operation—Filtering—the place prebuilt plugins can globally drop or trim context primarily based on deterministic guidelines earlier than it ever reaches the mannequin.
1.5 Context caching
Trendy fashions help context caching (prefix caching), which permits the inference engine to reuse consideration computation throughout calls. ADK’s separation of “Session” (storage) and “Working Context” (view) supplies a pure substrate for this optimization.
The structure successfully divides the context window into two zones:
- Secure prefixes: System directions, agent id, and long-lived summaries.
- Variable suffixes: The most recent person flip, new device outputs, and small incremental updates.
As a result of ADK flows and processors are specific, you may deal with cache-friendliness as a tough design constraint. You possibly can order your pipeline to maintain continuously reused segments steady on the entrance of the context window, whereas pushing extremely dynamic content material towards the tip. To implement this rigor, we launched static instruction, a primitive that ensures immutability for system prompts, guaranteeing that the cache prefix stays legitimate throughout invocations.
It is a prime instance of context engineering performing as techniques work throughout the complete stack: you aren’t solely deciding what the mannequin sees, however optimizing how usually the {hardware} has to re-compute the underlying tensor operations.
2. Relevance: Agentic administration of what issues now
As soon as the construction is established, the core problem shifts to relevance: Given a tiered context structure, what particular info belongs within the mannequin’s lively window proper now?
ADK solutions this by a collaboration between human area data and agentic decision-making. Relying solely on hard-coded guidelines is cost-effective however inflexible; relying solely on the agent to browse every part is versatile however prohibitively costly and unstable.
An optimum Working Context is a negotiation between the 2. Human engineers outline the structure—the place information lives, how it’s summarized, and what filters apply. The Agent then supplies the intelligence, deciding dynamically when to “attain” for particular reminiscence blocks or artifacts to fulfill the fast person request.
2.1 Artifacts: externalizing giant state
Early agent implementations usually fall into the “context dumping” entice: putting giant payloads—a 5MB CSV, an enormous JSON API response, or a full PDF transcript—immediately into the chat historical past. This creates a everlasting tax on the session; each subsequent flip drags that payload alongside, burying important directions and inflating prices.
ADK solves this by treating giant information as Artifacts: named, versioned binary or textual content objects managed by an ArtifactService.
Conceptually, ADK applies a deal with sample to giant information. Giant information lives within the artifact retailer, not the immediate. By default, brokers see solely a light-weight reference (a reputation and abstract) by way of the request processor. When—and solely when—an agent requires the uncooked information to reply a query, it makes use of the LoadArtifactsTool. This motion briefly hundreds the content material into the Working Context.
Crucially, ADK helps ephemeral growth. As soon as the mannequin name or process is full, the artifact is offloaded from the working context by default. This turns “5MB of noise in each immediate” right into a exact, on-demand useful resource. The information may be large, however the context window stays lean.
2.2 Reminiscence: long-term data, retrieved on demand
The place Artifacts deal with discrete, giant objects, ADK’s Reminiscence layer manages long-lived, semantic data that extends past a single session—person preferences, previous choices, and area info.
We designed the MemoryService round two ideas: reminiscence have to be searchable (not completely pinned), and retrieval needs to be agent-directed.
The MemoryService ingests information—usually from completed Periods—right into a vector or key phrase corpus. Brokers then entry this data by way of two distinct patterns:
- Reactive recall: The agent acknowledges a data hole (“What’s the person’s dietary restriction?”) and explicitly calls the
load_memory_toolto go looking the corpus. - Proactive recall: The system makes use of a pre-processor to run a similarity search primarily based on the most recent person enter, injecting seemingly related snippets by way of the
preload_memory_toolearlier than the mannequin is even invoked.
This method replaces the “context stuffing” anti-pattern with a “memory-based” workflow. Brokers recall precisely the snippets they want for the present step, moderately than carrying the burden of each dialog they’ve ever had.
3. Multi-agent context: who sees what, when
Single-agent techniques battle with context bloat; multi-agent techniques amplify it. If a root agent passes its full historical past to a sub-agent, and that sub-agent does the identical, you set off a context explosion. The token depend skyrockets, and sub-agents get confused by irrelevant conversational historical past.
Each time an agent invokes one other agent, ADK permits you to explicitly scope what the callee sees—possibly simply the most recent person question and one artifact—whereas suppressing a lot of the ancestral historical past.
3.1 Two multi-agent interplay patterns
At a excessive degree, ADK maps multi-agent interactions into two distinct architectural patterns.
The primary is Brokers as Instruments. Right here, the foundation agent treats a specialised agent strictly as a operate: name it with a centered immediate, get a end result, and transfer on. The callee sees solely the particular directions and vital artifacts—no historical past.
The second is Agent Switch (Hierarchy). Right here, management is totally handed off to a sub-agent to proceed the dialog. The sub-agent inherits a view over the Session and might drive the workflow, calling its personal instruments or transferring management additional down the chain.
3.2 Scoped handoffs for agent switch
Handoff conduct is managed by knobs like include_contents on the callee, which decide how a lot context flows from the foundation agent to a sub-agent. Within the default mode, ADK passes the complete contents of the caller’s working context—helpful when the sub-agent genuinely advantages from the whole historical past. In none mode, the sub-agent sees no prior historical past; it solely receives the brand new immediate you assemble for it (for instance, the most recent person flip plus a few device calls and responses). Specialised brokers get the minimal context they want, moderately than inheriting a large transcript by default.
As a result of a sub-agent’s context can be constructed by way of processors, these handoff guidelines plug into the identical circulation pipeline as single-agent calls. You don’t want a separate multi-agent equipment layer; you’re simply altering how a lot upstream state the present context compiler is allowed to see.
3.3 Translating conversations for agent switch
Basis fashions function on a set function schema: system, person, and assistant. They don’t natively perceive “Assistant A” vs. “Assistant B.”
When ADK transfers management, it should usually reframe the present dialog so the brand new agent sees a coherent working context. If the brand new agent merely sees a stream of “Assistant” messages from the earlier agent, it should hallucinate that it carried out these actions.
To forestall this, ADK performs an lively translation throughout handoff:
- Narrative casting: Prior “Assistant” messages could also be re-cast as narrative context (e.g., modifying the function or injecting a tag like
[For context]: Agent B stated...) moderately than showing as the brand new agent’s personal outputs. - Motion attribution: Software calls from different brokers are marked or summarized so the brand new agent acts on the outcomes with out complicated the execution with its personal capabilities.
Successfully, ADK builds a contemporary Working Context from the sub-agent’s perspective, whereas preserving the factual historical past within the Session. This ensures correctness, permitting every agent to imagine the “Assistant” function with out misattributing the broader system’s historical past to itself.
Conclusion
As we push brokers to sort out longer horizons, “context administration” can not imply “string manipulation.” It have to be handled as an architectural concern alongside storage and compute.
ADK’s context structure—tiered storage, compiled views, pipeline processing, and strict scoping—is our reply to this problem. It encapsulates the rigorous techniques engineering required to maneuver brokers from attention-grabbing prototypes to scalable, dependable manufacturing techniques.







