Skip to content

AgentTool: option to propagate parent conversation history to child session #6019

Description

@GiulioCMSanto

🔴 Required Information

Is your feature request related to a specific problem?

The problem is the following: AgentTool starts the child agent with a blank session. The child only sees args["request"], which is a string generated by the parent LLM and, therefore, that is rephrased. This means the following:

  • The child has no idea what the user actually said in prior turns.
  • Emphasis and constraints can get lost in the parent's rephrasing (For example, imagine the user said something like "MUST have 2 bedrooms, won't compromise" can become "find apartment with 2 bedrooms").
  • This also impact LLM-oriented Confirmation flows and multi-turn extraction tasks, because the child can't reference earlier messages.

Today the only workaround is subclassing AgentTool and manually injecting parent events into the child session — multiple people have done this independently (see #3878, where a contributor built a ContextAwareAgentTool and noted "For a long-term solution, we need a new pattern to be established in ADK").

PS: Although sub_agents share conversation context, they have fundamentally different dynamics — a sub-agent takes over the conversation via transfer_to_agent and the parent is out of the loop until control returns. AgentTool is the opposite: the parent calls the child, gets a result, and continues its own reasoning. It's a tool call, not a handoff. These are two distinct interaction patterns, and the tool-call pattern would benefit from optionally having conversation history available without changing its control-flow semantics.

Describe the Solution You'd Like

A new opt-in boolean on AgentTool:

AgentTool(agent=my_agent, propagate_conversation_history=True)

When True, user/model text events from the parent session are copied into the child's ephemeral session before execution. Same pattern as the existing propagate_grounding_metadata and include_plugins flags.

Key constraints:

  • Defaults to False — existing behavior unchanged.
  • Excludes function_call/function_response events (they'd reference tools the child doesn't have).
  • Creates fresh Event objects (no state_delta leakage).
  • Filters out thought parts.

Impact on your work

We have production agents where a parent routes to specialized tool agents for extraction tasks. Without conversation context, the tool agents consistently misclassify user intent. The subclass workaround works but breaks on ADK upgrades. A first-class parameter would let us remove fragile internal-API dependencies.

Willingness to contribute

Yes — I have a working implementation with tests and will open a PR right away.


🟡 Recommended Information

Describe Alternatives You've Considered

Alternative Why it doesn't work
sub_agents (handoff) Transfers full control to the child — parent can never route again. Incompatible with AgentTool's call-and-return contract.
mode='chat' Has unresolved scheduler bugs (#5780), only applies to LlmAgent callers, and changes semantics (multi-turn vs. single-turn with context).
Persistent sessions (PR #2849, closed) Solves a different problem (cross-invocation caching). We only need current-call context injection — no lifecycle or cleanup concerns.
Subclass workaround Brittle — duplicates framework internals, breaks on upstream refactors.

Proposed API / Implementation

The implementation is ~30 lines of new code, following the propagate_grounding_metadata pattern exactly:

  1. New kwarg on AgentTool.__init__ and _TaskAgentTool.__init__
  2. A small _inject_conversation_history helper
  3. A 3-line call site in run_async after create_session

No changes to _SingleTurnAgentTool, AgentToolConfig, or from_config (matching precedent).

Additional Context

Related issues:

Precedent:

  • d689a04f — propagate_grounding_metadata addition
  • 777dba30 — include_plugins addition

Activity

  1. added
    core[Component] This issue is related to the core interface and implementation
    on Jun 8, 2026
  2. added theissue type on Jun 8, 2026
  3. adk-bot commented on Jun 8, 2026

    @adk-bot
    Collaborator

    GitHub Issue #6019 Analysis: AgentTool: option to propagate parent conversation history to child session

    Executive Summary

    1. What is broken? Standard AgentTool runs start wrapped child agents with an entirely blank event history. Consequently, the child agent cannot see the user's prior conversation context/constraints and relies only on the rephrased query parameter (args["request"] or structured schema properties).
    2. Is there a linked PR that fixes this issue? None
    3. Recommendation: Should Fix (Medium/Low Priority). This is a highly requested feature and a very elegant, non-breaking improvement that mirrors the existing propagate_grounding_metadata and include_plugins architectural patterns. Since it defaults to False, standard behavior remains pristine.
    Detailed Analysis

    1. Root Cause Analysis ("What is broken?")

    When an AgentTool is invoked via AgentTool.run_async, it creates a fresh, isolated InMemorySessionService child session.
    During this, only the current invocation's query is packaged as a types.Content object and passed as new_message to the child's runner.run_async function:

    • Line references: agent_tool.py:L264-276

    Because of this design, the child is blinded to user constraints or requirements specified in previous turns of the parent conversation, unless developers subclass AgentTool to manually extract and transplant events—a workaround that is fragile across ADK upgrades.

    Proposed Solution Code

    A module-level helper in agent_tool.py can cleanly filter and inject the history:

    def _inject_conversation_history(
        tool_context: ToolContext,
        session: Session,
    ):
      """Injects conversation history from the parent session into the child session."""
      from ..events.event import Event
    
      parent_session = tool_context.session
      if not parent_session or not parent_session.events:
        return
    
      for parent_event in parent_session.events:
        # Exclude function_call/function_response events
        if (
            parent_event.get_function_calls()
            or parent_event.get_function_responses()
        ):
          continue
    
        # Skip event if content is None or empty
        if not parent_event.content or not parent_event.content.parts:
          continue
    
        # Filter out thought parts
        filtered_parts = [
            p for p in parent_event.content.parts if not getattr(p, 'thought', False)
        ]
        if not filtered_parts:
          continue
    
        # Create fresh Event object to avoid mutating parent event or leaking state_delta
        new_event = Event(
            author=parent_event.author,
            content=types.Content(
                role=parent_event.content.role,
                parts=filtered_parts,
            ),
        )
        session.events.append(new_event)

    And wired in AgentTool.__init__ agent_tool.py:L123-136 and _TaskAgentTool.__init__ agent_tool.py:L381-396 as:

    propagate_conversation_history: bool = False

    2. Existing Pull Requests ("Is there a linked PR that fixes this issue?")

    • Linked PR: None
    • PR URL: N/A
    • Analysis: No active or merged PR has been submitted addressing this issue in this repository yet.

    3. Recommendation

    • Recommendation: Should Fix (Medium/Low Priority)
    • Rationale:
      • User Impact & Workflows: Highly positive. It replaces unstable inheritance hacks with a clean, native option config.
      • Architecture Alignment: Perfectly aligns with current AgentTool paradigms, mimicking propagate_grounding_metadata and respecting isolation by default.
      • Complexity: Tiny and low-risk (~30 lines of addition). Since default is False, there is zero risk of regression.

    Summary of Work Done

    • Retrieved and inspected GitHub Issue AgentTool: option to propagate parent conversation history to child session #6019.
    • Located exact definition sites of AgentTool, _TaskAgentTool, and Event.
    • Traced the execution flow of AgentTool.run_async and analyzed the parent context's available events.
    • Validated that no matching PR exists.
    • Formulated the clean injection logic targeting agent_tool.py and prepared a premium structured report in full compliance with the read-only guidelines.
  4. GiulioCMSanto commented on Jun 8, 2026

    @GiulioCMSanto
    Author

    Link to the PR: #6020

  5. sanketpatil06 commented on Jun 9, 2026

    @sanketpatil06

    Hi @GiulioCMSanto , Thanks for bringing this and taking time to raise a PR. Your request is currently being reviewed, and we will let you know if anything further is needed. We appreciate your contribution.

  6. added
    needs review[Status] The PR/issue is awaiting review from the maintainer
    on Jun 9, 2026
  7. godwin3737 commented on Jun 15, 2026

    @godwin3737
    Contributor

    @GiulioCMSanto , @sanketpatil06 To prevent potential token overflow or context-window issues in longer sessions/histories, I've left a few suggestions to introduce an optional "max_history_messages" configuration parameter. This allows users to cap the injected history to the most recent N eligible turns.

    I've also appended a unit test to verify the capping logic and parameter forwarding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

core[Component] This issue is related to the core interface and implementationneeds review[Status] The PR/issue is awaiting review from the maintainer

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions