Session/State usage confusion #3874
Replies: 1 comment 1 reply
-
|
Response from ADK Answering Agent (experimental, answer may be inaccurate) TLDR: You can manage the conversation state using Hi Manasa! It sounds like you're running into a very common and important challenge in agent development: maintaining conversational context. ADK is designed to handle this through its Understanding Sessions and State
How to Solve Your "Yes/No" ProblemHere is a step-by-step approach to link your user's "Yes/No" feedback to the agent's previous response: 1. Save the Agent's Response to the State You can configure your "Q agent" to automatically save its response to the session state by using the For example, when you define your agent: from adk.agents import LlmAgent
# Your "Q Agent"
q_agent = LlmAgent(
# ... other parameters
output_key="last_agent_response"
)Now, after this agent runs, its final response will be stored in 2. Access the Previous Response in a Tool Next, when the user provides feedback ("Yes" or "No"), you need a tool that can process this feedback. This tool can access the stored response from the state to understand the context. To access the state, your tool function should accept a from adk.tools import tool
from adk.tools.tool_context import ToolContext
@tool
def process_user_feedback(feedback: str, tool_context: ToolContext) -> str:
"""Processes the user's feedback based on the last agent response."""
# Retrieve the last response from the session state
last_response = tool_context.state.get("last_agent_response")
if last_response is None:
return "I'm sorry, I don't remember what I said before."
if feedback.lower() == "yes":
# User confirmed the previous response. Proceed with next action.
# You can now store this confirmed information in your DB.
return f"Great! I have recorded that you confirmed: '{last_response}'"
elif feedback.lower() == "no":
# User denied the previous response. Handle accordingly.
return "My apologies. What would you like me to do instead?"
else:
return "I didn't understand the feedback."Your root agent would then be configured to use this State in a Multi-Agent SetupSince you have a root agent and a Q agent, it's important to know that the I hope this helps clear up your confusion! Let us know if you have more questions. [1] https://google.github.io/adk-docs/get-started/about/ |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Guys,
My agent treats each user message as an independent query instead of recognizing that a Yes/No response is feedback on the previous agent response—how do I implement state management to link multi-turn interactions?
For now, it is only two turn, FLOW: user -> root agent -> my Q agent -> answer back to root agent -> user feedback (Yes/No) and then I have to store this entire (each) iteration in db (this is also done in the Q agent). So basically want my root agent to just direct user questions to the agent, without any implementation in itself. HELP!
I'm a little confused around this concept and I posting a question here as I simultaneously also research it.
TIA :-)
Beta Was this translation helpful? Give feedback.
All reactions