Course Introduction and ADK Overview
Introduce course objectives, the ADK ecosystem, terminology, and the roles engineers and product teams play when building stateful, personalised agents.
Content
Stateful vs stateless agents
Versions:
Watch & Learn
AI-discovered learning video
Stateful vs Stateless Agents — The Difference That Changes Everything
"Is my agent remembering too much, or not remembering enough?" — The question that keeps product managers up at night.
You're already familiar with ADK from the previous module (we covered "What is ADK?" and the course roadmap). Now we zoom in on a core architectural decision you'll make again and again: stateful vs stateless agents. This choice shapes personalization, scaling, privacy, and how human your agent feels.
Quick primer (no repeats — building on what you know)
We won't rehash ADK basics, but keep this in mind: ADK gives you primitives for agent orchestration, model calls, and memory connectors. The big question now is how you use those primitives to store and reuse information over time.
What does "state" mean in an agent?
- State = any information the agent keeps between interactions that affects future behavior.
- Examples: user preferences, conversation history, inferred user goals, authentication tokens, or a to-do list the agent is managing.
Two extremes
- Stateless agent: Treats each request as independent — no memory of previous interactions.
- Stateful agent: Keeps and updates information across interactions — can personalize, continue a task, or recall facts.
Why this matters for ADK-based projects
- Personalization: Want the agent to remember that Sara prefers short answers? You need state.
- Complex tasks: Multi-step flows (book a trip, manage a bank transfer) usually need state to track progress.
- Scaling & cost: Stateless systems are simpler and cheaper per request. Stateful systems add storage, indexing, and retrieval costs.
- Privacy & compliance: Storing user data introduces regulatory risk; stateless may reduce attack surface.
"Choosing between stateful and stateless is choosing what kind of relationship you want between your user and the agent: casual encounter or long-term friendship."
Real-world analogies (because metaphors hit neurons)
- Stateless = a barista who only knows your order if you tell them each time.
- Stateful = the barista who remembers you like oat milk and the time you asked for a quiet table.
Both are useful. The coffee shop that remembers allergies is great — until it leaks your whole coffee history to a marketing firm.
Patterns of statefulness in ADK (practical categorizations)
- Session-state
- Short-lived, tied to a conversation session. Good for chat flows and form-filling.
- Storage options: in-memory in the runtime, short TTL cache, or ADK session store.
- Long-term memory
- Persistent user profile, preferences, historical facts. Used for personalization across days/weeks.
- Storage options: databases, vector stores for embeddings, user profile tables.
- Ephemeral/transient state
- Useful for single multi-step tasks (e.g., checkout). Cleared after completion.
- Derived state
- Inferred attributes (e.g., "user prefers async communication"). Stored after validation.
Stateless vs Stateful: Side-by-side comparison
| Aspect | Stateless | Stateful |
|---|---|---|
| Complexity | Low | High |
| Scalability | High (easy to scale horizontally) | Lower (requires coordinated storage) |
| Personalization | Poor | Excellent |
| Cost | Low per request | Higher (storage + retrieval) |
| Privacy risk | Lower | Higher |
| Latency | Lower (no retrieval step) | Higher (need lookup + context prep) |
When to prefer stateless (short checklist)
- You're building simple Q&A or utility endpoints.
- Each request has a complete context (e.g., forms, explicit fields).
- You need maximal throughput and minimal infra complexity.
- You want to minimize long-term data retention for privacy reasons.
When to prefer stateful
- You need continuity: multi-step tasks, conversational context, or personalization.
- You want the agent to reduce friction by remembering preferences or past actions.
- You're building an assistant that must behave like an ongoing collaborator.
Implementation approaches (high-level ADK-friendly examples)
Stateless handler (pseudocode)
handleRequest(request):
// request contains all context (user message, form fields, auth)
response = callModel(request.content)
return response
No memory reads/writes, minimal orchestration.
Stateful handler (pseudocode with ADK memory primitives)
handleRequest(request):
user_state = memory.read(user_id=request.userId)
context = stitch(request.content, user_state.recent_messages)
model_output = callModel(context)
updated_state = updateState(user_state, model_output)
memory.write(user_id=request.userId, updated_state)
return model_output
Notes: "memory" could be an ADK memory connector talking to Redis, a SQL DB, or a vector store for embeddings.
Common pitfalls and practical tips
- Too much memory: Dumping entire chat logs into the prompt causes high token costs. Use summarization or selective retrieval.
- No memory hygiene: Old or contradictory facts confuse the model. Implement pruning and consistency checks.
- Privacy neglect: Always store PII with consent, encryption, and retention policies.
- Synchronous bottlenecks: Avoid blocking UX while long retrievals or costly re-rankings run. Use async updates or cached summaries.
Practical techniques: chunking + embedding + similarity search for long-term memory; session caches for short-term state; compact summaries to control token budgets.
Decision flow: Quick guide to choose
- Does the agent need to remember past interactions to accomplish tasks? Yes → stateful. No → stateless.
- Is personalization optional but valuable? Consider hybrid: session state + minimal long-term profile.
- Are privacy/regulatory constraints strict? Lean stateless or encrypted, consented stateful storage.
Hybrid approaches — best of both worlds
Often the right answer is hybrid:
- Keep core conversational flow stateless for speed.
- Store a small, curated user profile (preferences, IDs) in stateful storage.
- Use on-demand retrieval of long-term memory only when confidence or similarity thresholds are met.
This is where ADK shines: it lets you wire memory connectors, summarizers, and retrieval layers into the call graph so you can experiment with hybrids rapidly.
Closing: Key takeaways
- Stateful = memory, personalization, and complexity. Stateless = simplicity, scale, and fewer privacy headaches.
- Use session state for short flows, long-term memory for personalization, and ephemeral state for single tasks.
- Prefer hybrid strategies: small persistent profiles + selective retrievals to balance cost, UX, and privacy.
"Think of state as the agent's diary. If you want a trustworthy assistant, write useful things in the diary — but lock it up and decide how long to keep each entry."
Next steps in the course
We'll apply these ideas in the lab: wiring ADK memory connectors, building a small stateful assistant, and then refactoring it into a stateless version to compare costs and UX. Bring your curiosity and your worst data-leak nightmares — we’ll handle both.
Comments (0)
Please sign in to leave a comment.
No comments yet. Be the first to comment!