Google: Manage Agent Memory and State
Learn to use session state so LLM agents keep context, inject stored values into instructions, and control how long each value persists.
In an LLM agent, the conversation history is readable only by the model, so the agent’s own code has no direct way to reach exact values such as a user’s preferences. You work with session state, a dictionary the agent writes to and your code reads directly. You use it to keep context, place stored values into the agent’s instructions, and decide how long each value lasts and who may access it, so the agent can give each user a personalized experience.
What You Will Achieve
- Store the values an agent needs to remember and read them back in code
- Judge when stored state gives better programmatic control than the conversation history
- Write agent instructions that adapt to each user’s stored preferences
- Choose a state namespace that controls how long a value persists and who can access it
Program Overview
Session State Versus Conversation History
Why conversation history alone falls short for programmatic control, and how session state holds exact values that the agent’s code can read.
- Limits of conversation history for programmatic control
- Session state as a dictionary
- Code-level access to exact values
Dynamic Agent Instructions
Stored state values are injected into agent instructions, so the agent’s behavior changes with the data it holds.
- Injecting state values into instructions
- Templating with {var} placeholders
State Namespaces, Persistence, and Reading List
Namespaces set how long each state value persists and who can access it, and a reading list closes the course.
- Why not all state should persist equally
- Persistence and access scope of state values
- Reading list
Certificate Awarded (Paid)
Job Outlook
Session state and namespaces are used wherever LLM agents need to keep context, track user preferences or pass data between steps in code.
Good for: Developers who already build basic LLM agents and want them to keep context and user preferences across a conversation.
Keep in mind: Each of the three parts pairs one problem with its solution and three quiz questions, so the course stays tightly focused on how agents handle state.
Bottom line: A tightly scoped look at session state, templated instructions and namespaces for agents that need to keep track of their users.
Frequently Asked Questions
What is session state in an agent?
Session state is a dictionary where the agent stores data it needs to remember. Unlike the conversation history, which only the model reads, it gives your code direct access to exact values.
How do stored values get into agent instructions?
The course uses {var} templating: placeholders in the agent's instructions are filled with values from session state, so the same agent behaves differently depending on the data it currently holds.
What do state namespaces control?
Namespaces decide how long a state value persists and who can access it. The lesson starts from the point that not all state should persist equally, then shows how namespaces handle that.
Please log in to report a problem with this page.


There are no reviews yet.