* Deleted redundant files. * Deleted redundant files. * Deleted redundant files. * Deleted redundant files. * Deleted redundant files. * Deleted redundant files. * Delete .gitignore Deleted redundant files. * Delete .gitignore Deleted redundant files. * Delete .gitignore * Delete .gitignore * Delete .gitignore * Revert changes to .gitignore * Revert changes to .gitignore * Revert changes to .gitignore * Revert changes to .gitignore * Revert changes to .gitignore * Revert changes to .gitignore * Add MCP Tools TS example * Removed unnecessary changes * Removed extra slashes * Added the custom agent sample. * Corrected an error in the package.json file. * Updated custom-agent.md * Made small fixes. * Add Session TS examples * Added the typescript code snippets for multi agent. * added the code sample for loop agent * Added the code sample for loop agent * Added the code sample for parallel agent * Fixed a few issues and bugs * Added the code sample for sequential agent * Renamed run back to runAsync * Updated the capital agent code sample. * Corrected the snippet * Renamed run() to runAsync() * Add Runtime TS examples * Fixed the snippets after library updates. * Fixed the sample code after library changes. * Added final touchups and fixes. * Updated the code based on recent library changes. * Updated package.json * Updated package.json * Updated package.json * Updated the code with runAsync and package.json * Updated the typescript sample. * Updated after_tool_callback.ts with runAsync * Updated after_model_callback.ts * Updated before_model_callback.ts * Updated before_tool_callback.ts * Created before_agent_callback.ts * Update before_agent_callback.ts Changed the condition * Update before_model_callback.ts Changed the condition * Update after_model_callback.ts Changed the condition * Update after_tool_callback.ts Changed the condition * Update after_agent_callback.ts Changed the condition * Update callback_basic.ts Changed the condition * Update storyflow_agent.ts Changed the condition * Update sequential_agent_code_development_agent.ts Changed the condition * Updated before_agent_callback.ts * Removed unnecessary comment. * Updated comment * Renamed run to runAsync * Added artifact code snippets. * Fixed .link-checker-config.json * Added tsconfig.json * Update .gitignore with node modules files * Added 7 typescript code snippets * Cleaned up and corrected the snippets for plugins * Update index.md Undid the changes in artifacts/index.md * Escaped properly. * Add Long Running Function Tool TS examples * Resolved code review feedback * Fixed the code sample per git comments. * Fixed the code per git comments. * Fixed the md file per git comments. * Fixed the issues per git comments. * Fixed issues per github comments. * Fixed the issues per PR comments. * Fixed issues per PR comments. * Added a code sample for HITL * Fixed the indentations in the typescript code * Used createPartFromBase64 when appropriate. * Switched to use createUserContent. * docs: Add JavaScript Quickstart, short unified format * Added a simulated user delay to the code sample. * Made some cosmetic improvements * Added the code snippet with HITL with policy * Made cosmetic modifications to multi-agents.md * Added more tutorial for the HITL with policy * Modularized the main function and added helper functions. * Resolved code review feedback * Resolved code review feedback * Resolved code review feedback * Fixed minor things in the typescript code per PR comments. * Fixed the import for Event and used createEventActions. * Simplified functionResponse code. * Corrected the Event import and used createEventActions. * Updated ADK versions in package.json. * Final review of all changes & Add Safety TS example * Make tsconfig.json files consistent * Generated the API Reference for typescript * Resolved code review feedback * feat: Add Typescript API reference to docs This commit adds the generated TypeDoc documentation for the Typescript ADK to the documentation site. It also updates the main API reference page to include a link to the new Typescript API reference. * docs: update TypeScript quickstart * docs: Add version tags for Build Agents topics - add version tags - move TS content to second position (after Python) * docs: Add MCP Toolbox for databases TS SDK Documentation * Update mcp-toolbox-for-databases.md * use typescript code block * minor changes * Update mcp-toolbox-for-databases.md * Auto generated the typescript API reference. * Added the TS code snippets for context. * Fixed TS code snippets for context. * Modified the sample based on the comment. * docs: adding TypeScript language tags (2 of 3) - Update all Run Agents section topics - change all TS tags to v0.2.0 per eng agreement * docs: Add TypeScript language support tags, Components (3 of 3) - add TS language support tags - re-order TS examples to be second - minor fixes: remove trailing spaces * Added callback samples for typescript to the markdown files. * Updated adk version in quickstart * Updated google/adk version for typescript. --------- Co-authored-by: manchan <manchan@google.com> Co-authored-by: Mandy Chan <75594070+slothwriter@users.noreply.github.com> Co-authored-by: Joe Fernandez <joefernandez@google.com> Co-authored-by: Joe Fernandez <joefernandez@users.noreply.github.com> Co-authored-by: Twisha Bansal <58483338+twishabansal@users.noreply.github.com>
3.9 KiB
Introduction to Conversational Context: Session, State, and Memory
Meaningful, multi-turn conversations require agents to understand context. Just
like humans, they need to recall the conversation history: what's been said and
done to maintain continuity and avoid repetition. The Agent Development Kit
(ADK) provides structured ways to manage this context through Session,
State, and Memory.
Core Concepts
Think of different instances of your conversations with the agent as distinct conversation threads, potentially drawing upon long-term knowledge.
-
Session: The Current Conversation Thread- Represents a single, ongoing interaction between a user and your agent system.
- Contains the chronological sequence of messages and actions taken by the
agent (referred to
Events) during that specific interaction. - A
Sessioncan also hold temporary data (State) relevant only during this conversation.
-
State(session.state): Data Within the Current Conversation- Data stored within a specific
Session. - Used to manage information relevant only to the current, active conversation thread (e.g., items in a shopping cart during this chat, user preferences mentioned in this session).
- Data stored within a specific
-
Memory: Searchable, Cross-Session Information- Represents a store of information that might span multiple past sessions or include external data sources.
- It acts as a knowledge base the agent can search to recall information or context beyond the immediate conversation.
Managing Context: Services
ADK provides services to manage these concepts:
-
SessionService: Manages the different conversation threads (Sessionobjects)- Handles the lifecycle: creating, retrieving, updating (appending
Events, modifyingState), and deleting individualSessions.
- Handles the lifecycle: creating, retrieving, updating (appending
-
MemoryService: Manages the Long-Term Knowledge Store (Memory)- Handles ingesting information (often from completed
Sessions) into the long-term store. - Provides methods to search this stored knowledge based on queries.
- Handles ingesting information (often from completed
Implementations: ADK offers different implementations for both
SessionService and MemoryService, allowing you to choose the storage backend
that best fits your application's needs. Notably, in-memory implementations
are provided for both services; these are designed specifically for local
testing and fast development. It's important to remember that all data
stored using these in-memory options (sessions, state, or long-term knowledge)
is lost when your application restarts. For persistence and scalability beyond
local testing, ADK also offers cloud-based and database service options.
In Summary:
Session&State: Focus on the current interaction – the history and data of the single, active conversation. Managed primarily by aSessionService.- Memory: Focuses on the past and external information – a searchable
archive potentially spanning across conversations. Managed by a
MemoryService.
What's Next?
In the following sections, we'll dive deeper into each of these components:
Session: Understanding its structure andEvents.State: How to effectively read, write, and manage session-specific data.SessionService: Choosing the right storage backend for your sessions.MemoryService: Exploring options for storing and retrieving broader context.
Understanding these concepts is fundamental to building agents that can engage in complex, stateful, and context-aware conversations.