How to pass the session information to remote a2a agent #2956
-
I wanted to share the session from my root agent to sub agents. Im building a mutliagent system where a supervisor hands off to multiple remote sub agents. Whenever the supervisor creates the adk sessions is not passed to the subagents so the sub agents doesn't know what's happening perviously. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
@adk-bot can you please help |
Beta Was this translation helpful? Give feedback.
-
Response from ADK Answering Agent (experimental, answer may be inaccurate) TLDR: You don't pass the session object directly to remote agents. Instead, the supervisor agent should extract the necessary data from its session state and pass that data as arguments when calling the remote agent. The remote agent then uses this data within its own, separate session. Hello! That's a great question about architecting a multi-agent system with ADK. There's a key distinction in how session information is shared between agents running in the same process versus agents running remotely. 1. Local Sub-Agents (Same Process)When you have a parent agent that orchestrates sub-agents locally (e.g., using For example:
2. Remote Sub-Agents (Agent-to-Agent - A2A)For remote agents, the architecture is different. The ADK provides the Agent-to-Agent (A2A) communication protocol for this purpose. You would expose your sub-agents as an In this model, the remote agent is treated like a tool. The supervisor doesn't share its entire session object. Instead, the correct pattern is:
Here is a conceptual example of how the supervisor might work: # In your supervisor agent's code
from google.adk.agents import InvocationContext, RemoteA2aAgent
async def run(self, context: InvocationContext):
# 1. Get relevant history from the supervisor's session state.
conversation_history = context.session.state.get("history", [])
user_request = context.get_last_user_content()
# 2. Format the data and pass it as an argument to the remote agent.
# The RemoteA2aAgent is configured to connect to your remote sub-agent's server.
result = await self.invoke_sub_agent(
"my_remote_sub_agent", # The name of the RemoteA2aAgent instance
f"Given this history: {conversation_history}, please handle this request: {user_request}"
)
# 3. Use the result from the remote agent.
response_text = result.content.parts[0].text
# ... create and return a final response This approach ensures that your agents are self-contained and communicate through well-defined interfaces, which is a robust pattern for building distributed multi-agent systems. [1] Session State Documentation |
Beta Was this translation helpful? Give feedback.
-
@ShyamGurunath thank you for reaching to us. please ignore the bot answer above. session is just a place where historical events and state are saved in ADK. two agents are not sharing the session but share the context. we already send historical events information as context to remote subagent : you should not worried about the context. |
Beta Was this translation helpful? Give feedback.
@ShyamGurunath thank you for reaching to us. please ignore the bot answer above. session is just a place where historical events and state are saved in ADK. two agents are not sharing the session but share the context. we already send historical events information as context to remote subagent :
adk-python/src/google/adk/agents/remote_a2a_agent.py
Line 354 in 6b49391
you should not worried about the context.