Skip to content

Parent Agent Session Information Not Passed to AgentTool #2130

Closed

Description

@jobmthomas12

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

Activity

  1. added
    core[Component] This issue is related to the core interface and implementation
    on Jul 23, 2025
  2. condorcet commented on Jul 31, 2025

    @condorcet
    Contributor

    As I understand, the issue connected with how Agent is tool works internally. It creates their own in memory session manager and session https://github.com/google/adk-python/blob/main/src/google/adk/tools/agent_tool.py#L137

    So, fundamentally agent as a tool is not the same as delegating flow of execution to sub_agent, it's just the way to "mimic" tool using Agent.

    Also I think another side-effect of this that we need to declare args of Agent as a a tool (e.g. with input_schema of Agent) to understand how we should call Agent as a tool properly from main flow.

    Maybe I wrong, ready to hear clarification how we should use Agent as a tool properly :)

  3. added this to the 08/11 FixIt Week milestone on Aug 8, 2025
  4. akshaypachpute-1998 commented on Aug 20, 2025

    @akshaypachpute-1998
    Contributor

    Hi @jobmthomas12 , I believe the calling agent, not the AgentTool, should be responsible for managing the conversation history. Passing the full history could include a lot of irrelevant information. Instead, the calling agent should pass only the necessary context.

    This approach leads to the following workflow, which I find acceptable:

    The root agent delegates a task to the AgentTool.
    The AgentTool determines that information is missing from the input and requests it.
    Control returns to the root agent, which then prompts the user for the missing information (rather than pulling it from its own context).
    If the user responds with a prompt like "use the previous settings," the root agent retrieves the relevant context and passes it to the AgentTool.
    Limited context makes it easy and fast for sub-agent/ agent tool.

  5. locked and limited conversation to collaborators on Nov 8, 2025
  6. converted this issue into a discussion #3456 on Nov 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

core[Component] This issue is related to the core interface and implementation

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions