Google ADK: Selective History Pruning with include_contents='none' vs 'default'
A hands-on tutorial for ADK's include_contents switch: when an agent should see full history, when it should see none, and how to split the two across sub-agents.
Published on • December 4, 2026
AI Assistant

Every ADK LlmAgent faces one question before it ever runs: how much of the past does the model get to see? The default answer is “the relevant conversation history” — which for a long session means every event in session.events becomes contents in the request. That is correct for a chat assistant and quietly wrong for a batch extractor that must not be swayed by turn 42, or a sub-agent that should behave identically no matter how chatty the parent has been.
ADK gives you a single parameter for this: include_contents, with two values, 'default' and 'none'. It is the cheapest form of context management in the framework — no summarizer, no token counter, no extra model call — but that also means it is the easiest one to apply in the wrong place. Turn it off on a planner and it forgets the goal; leave it on for a stateless classifier and you pay for history you did not want.
This tutorial builds the same small task three ways — full history, no history, and a hybrid where the orchestrator keeps history while a stateless worker gets none — then verifies what the model actually received.
Prerequisites
pip install google-adk(Python; the parameter also exists in TypeScript, Go, Java, and Kotlin)- A Google AI Studio
GEMINI_API_KEYor Vertex AI credentials - Comfort with
Runner,InMemorySessionService, andsession.state
1. What “contents” means in ADK
A Session carries two different kinds of context:
| Store | Holds | Sent to the model? |
|---|---|---|
session.events | The chronological log: user messages, agent replies, tool calls, tool results | Yes — this becomes the request contents under include_contents='default' |
session.state | Key-value scratchpad: flags, counters, output_key results | Only what you inject explicitly ({key} templating in instruction) |
include_contents controls only the first row. Setting it to 'none' does not erase history — events stay in the session for later turns, evaluation, and the UI. It only stops that history from being serialized into the next model call.
2. The two values, verbatim
From the LlmAgent reference:
'default'(default): the agent receives the relevant conversation history.'none': the agent receives no priorcontents— it operates solely on its current instruction plus input provided in the current turn. Useful for stateless tasks or enforcing a specific context.
The parameter is spelled include_contents in Python, includeContents in TypeScript, IncludeContents.NONE / IncludeContentsDefault in Java and Go, and includeContents = IncludeContents.NONE in Kotlin.
3. Step 1 — a sessionful agent (the default)
from google.adk import Agent
from google.adk.runners import Runner
from google.adk.sessions import InMemorySessionService
from google.genai import types
APP_NAME, USER_ID = "history_demo", "u1"
# Remembers prior turns: correct for a conversational assistant.
chat_agent = Agent(
name="chat_agent",
model="gemini-flash-latest",
instruction="You are a support agent. Use earlier turns to stay consistent.",
include_contents="default", # explicit, but identical to omitting it
)
session_service = InMemorySessionService()
runner = Runner(
agent=chat_agent,
app_name=APP_NAME,
session_service=session_service,
)
async def bootstrap(session_id: str) -> None:
await session_service.create_session(
app_name=APP_NAME, user_id=USER_ID, session_id=session_id
)
async def turn(session_id: str, text: str) -> str:
content = types.Content(role="user", parts=[types.Part(text=text)])
async for event in runner.run_async(
user_id=USER_ID, session_id=session_id, new_message=content
):
if event.is_final_response() and event.content:
return event.content.parts[0].text
return ""
Ask “my order is late” then “what did I just say?” — the second answer cites the first turn, because both turns’ events were serialized into contents.
4. Step 2 — the stateless variant
# Sees ONLY the current turn: identical output for identical input, regardless of history.
extractor = Agent(
name="extractor",
model="gemini-flash-latest",
instruction=(
"Extract the order id and issue type from the message. "
"Ignore anything else — you have no conversation history."
),
include_contents="none",
output_key="last_extraction", # result lands in session.state instead of memory
)
The distinction matters in three concrete situations:
- Reproducibility — a classifier whose answer depends on turn 17 is untestable.
'none'makes the input a pure function of the current message. - Cost — every event you drop is input tokens you do not pay for, and on Gemini those tokens would otherwise be re-read every turn.
- Prompt-injection containment — history is untrusted user text. A worker that never reads history cannot be steered by an earlier injected instruction.
Note what 'none' does not remove: the instruction, tools, and anything you inject via {state_key} templating still arrive. Stateful memory lives on the state side of the table in §1.
5. Step 3 — the hybrid: stateful orchestrator, stateless worker
This is the pattern worth copying. The parent keeps the conversation; the child performs a mechanical task on one input.
from google.adk import Agent
# Deterministic worker: same input, same processing, no history leakage.
def normalize_ticket(message: str) -> dict:
"""Normalize a raw support message into a structured ticket."""
return {"ticket": message.strip().lower(), "chars": len(message)}
classifiers = Agent(
name="ticket_normalizer",
model="gemini-flash-latest",
instruction="Normalize the single message you are given. Return the tool result.",
tools=[normalize_ticket],
include_contents="none", # the worker must not see the chat log
)
coordinator = Agent(
name="coordinator",
model="gemini-flash-latest",
instruction=(
"Route the user's latest message. First delegate to ticket_normalizer on "
"the raw text, then reply using the session state `normalized`."
),
include_contents="default", # the parent keeps the conversation
sub_agents=[classifiers], # exposed to the parent as an inline tool
)
Because the parent serializes history and the child does not, the child’s behavior is pinned down while the parent still resolves pronouns (“send it to the warehouse”) across turns. Push state, not history, across the boundary — a callback on the parent writing session.state["normalized"] via output_key or EventActions.state_delta is the channel the docs recommend.
6. Step 4 — verify what the model actually saw
Do not trust the parameter name; inspect the request. A before_model_callback receives the LlmRequest that is about to be sent:
from google.adk.models import LlmRequest
from google.adk.agents import CallbackContext
def audit_contents(callback_context: CallbackContext, llm_request: LlmRequest):
contents = llm_request.contents or []
print(
f"[{callback_context.agent_name}] contents messages: {len(contents)} "
f"| history visible: {len(contents) > 1}"
)
return None # return None to let the call proceed unchanged
audited_worker = Agent(
name="audited_worker",
model="gemini-flash-latest",
instruction="Normalize the message you receive.",
include_contents="none",
before_model_callback=audit_contents,
)
For a non-prompt view, adk web and the Trace tab show the raw Request sent to the model for every event — the fastest way to confirm that a worker really received a single turn rather than forty.
7. Choosing per agent
| Agent role | Recommended value | Why |
|---|---|---|
| Primary chat / planner | 'default' | Needs prior turns to resolve references and track goals |
Workflow node (SequentialAgent, LoopAgent, graph node) | 'none' | Single-turn by design; it should act on the current input only |
| Classifier, extractor, normalizer | 'none' | Deterministic, testable, injection-resistant |
Sub-agent exposed via AgentTool | 'none' usually, 'default' if it must recall the dialogue | Bound the blast radius of history |
Anything injecting state via {key} | Either — templating is independent of contents | State and history are separate channels |
One caveat from the Go reference: agents running as single-turn workflow nodes behave as if IncludeContents were none. From Go v2.4.0 onward you can set IncludeContentsDefault explicitly to keep history in those nodes — so the effective value can be imposed by the execution mode, not just your constructor argument.
Checklist
- Decide per agent whether history is signal or noise; do not inherit the default by accident.
- Set
include_contents='none'explicitly on classifiers, extractors, and workflow nodes. - Keep
'default'on the agent that owns the conversation with the user. - Move cross-boundary information through
session.state(output_key,state_delta), not through copied history. - Remember
'none'is a read filter — events remain insession.eventsfor replay and evaluation. - Confirm
{key}templating still works with'none': state injection is a separate mechanism. - Verify with a
before_model_callbackcountingllm_request.contents, or the Trace tab inadk web. - Re-run your evals after flipping the switch — expected trajectories change when history disappears.
- Check your execution mode: single-turn workflow nodes may ignore
'default'on some SDKs.
Conclusion
include_contents is a one-line switch with a large blast radius: 'default' buys conversational continuity at the cost of tokens and unpredictability, 'none' buys determinism and cost control at the cost of memory. Neither is a global setting — the useful design move is to assign the value per agent, so the agent that talks to the user remembers and the agents that do mechanical work do not.
Start by auditing what each of your agents currently receives. A before_model_callback that prints len(llm_request.contents) usually reveals two or three agents silently re-reading history they were never meant to use — and each of those turns is both a cost line and an injection surface.