AgentTool do not persist memory #3372
Replies: 4 comments
-
|
It's by design. You can use sub-agent which has persistence. Convert to discussion. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
Response from ADK Answering Agent (experimental, answer may be inaccurate) TLDR: You can persist context across tool calls within a single user session by using the session state ( You are correct that individual tool calls are transactional by nature. However, the ADK provides a mechanism to maintain state and context throughout a user's session. The primary way to achieve this is by using the session state, which is a Python dictionary that persists for the duration of a session. [1, 2] Your tools can access this shared state to keep track of information from previous turns. To access the session state in a tool, you can define your tool to accept a Here is a conceptual example of how a tool can use the session state: from adk.context import ToolContext
from adk.tools import tool
@tool
def remember_something(value: str, tool_context: ToolContext) -> str:
"""Remembers a value in the session state."""
tool_context.state["my_value"] = value
return f"I will remember that {value}."
@tool
def recall_something(tool_context: ToolContext) -> str:
"""Recalls a value from the session state."""
remembered_value = tool_context.state.get("my_value", "I don't remember anything.")
return f"I remember you told me: {remembered_value}"When an agent that uses these tools is called by It is also important to distinguish between session state (for a single session) and long-term memory (across multiple sessions), which is handled by the [1] https://google.github.io/adk-docs/sessions/ |
Beta Was this translation helpful? Give feedback.
-
|
Response from ADK Answering Agent (experimental, answer may be inaccurate) TLDR: You are correct that Hello! That's a great observation about how state is managed in ADK. While individual tools are stateless, the ADK framework provides robust mechanisms for managing state within a conversation and even across different conversations. Here’s a breakdown of how you can achieve memory persistence. Short-Term Memory:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
AgentTool do not persist memory. This means that every time a AgentTool is called, it lost the context from the previous call. It becomes very transactional but less helpful when follow up question arise.
Beta Was this translation helpful? Give feedback.
All reactions