-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
The root agent is not passing the session to the child agents ( while checking the session id under the invocation context ) when the child agents are used as AgentTools. However, session transfer works correctly when using sub_agents.
Is it expected behaviour to support session transfer in such cases? If not, we should document this in Explicit Invocation - AgentTool.
I'm happy to update the documentation once the expected behaviour is confirmed.
Attached is the complete code for reference
MultiAgentSessionTransfer copy.txt
Code snippet.
agent1 = Agent(
model="gemini-2.0-flash",
name="bmw_agent",
instruction="You are a helpful assistant that talks about bmw cars",
generate_content_config=types.GenerateContentConfig(max_output_tokens=2048),
tools=[get_car_price], # Pass the function directly as a list item
before_tool_callback=tool_call_back_cars
)
agent2 = Agent(
model="gemini-2.0-flash",
name="mercedes_agent",
instruction="You are a helpful assistant who talk about Mercedes cars ",
generate_content_config=types.GenerateContentConfig(max_output_tokens=2048),
tools=[get_car_price], # Pass the function directly as a list item
before_tool_callback=tool_call_back_cars
)
# --- 2. Create the SequentialAgent ---
# This agent orchestrates the pipeline by running the sub_agents in order.
car_pilot = SequentialAgent(
name="car_pilot",
sub_agents=[agent1, agent2],
description="You are a helpful assistant who talk about cars, delegated among sub agents",
)
from google.adk.tools import agent_tool
agent1_tool = agent_tool.AgentTool(agent=car_pilot)
root_agent = Agent(
model="gemini-2.0-flash",
name="car_agent",
instruction="You are a helpful assistant who talk about cars",
generate_content_config=types.GenerateContentConfig(max_output_tokens=2048),
tools=[agent1_tool] # The session id of the parent will not be passed to child when using agents as tools
#sub_agents=[car_pilot] # The session id of the parent will be passed to child when using sub agents
)
return root_agent
The code first prints the Runner session ID:
Starting conversation with agent...
Runner session id: test_session_001
Later, when we ask a question like “What is the price of BMW X1?”, it triggers the tool_callback_cars. Inside this callback, I print the session ID from the invocation context.
tool called <google.adk.tools.function_tool.FunctionTool object at 0x12df23470> with session id 97a8d4ba-0acf-435d-b208-6b958fb93d3e
Expected response
Starting conversation with agent...
Runner session id: test_session_001
tool called <google.adk.tools.function_tool.FunctionTool object at 0x12df23470> with session id test_session_001