adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

Root agent not consistently transferring to subagents, instead directly calling tools

Open poornatejaMV opened this issue 1 year ago • 7 comments

I am facing an issue with subagent transfer behavior in a multi-agent setup.

Context:

  • Lets assume, I have a root agent A, which has subagents B, C, D.
  • Subagent C has further subagents E, F, G.
  • Subagent E has access to tools a, b, c (and so on for other subagents).

Problem:

  • During the initial conversation, the root agent (A) correctly transfers requests to subagents (B, C, D) as per the instructions.

  • However, in subsequent requests:

    • The root agent often does not transfer to the intended subagent.
    • Instead, it tries to directly call tools (e.g., a) that are only available to subagents.
    • Sometimes it even attempts to call a new/unknown tool.

Expected Behavior:

  • After the first successful transfer, the root agent should consistently transfer subsequent requests to the appropriate subagent (B, C, or D) instead of directly invoking subagent-only tools.
  • Tool calls should always be restricted to the subagent that owns them.

Steps to Reproduce:

  1. Create a root agent with multiple subagents (nested).
  2. Assign unique tool access to subagents (not root).
  3. Start a conversation → observe that the root agent transfers correctly.
  4. Continue the conversation → root agent sometimes skips subagent transfer and tries to directly call subagent tools.

Troubleshooting Attempts:

  • Added transfer-to-agent tool in the root agent.
  • Flattened the hierarchy (e.g., instead of C → E, F, G, directly configured them as root-level subagents: B, E, F, G, D).
  • Tried toggling disallow_transfer_to_parent = false/true (both variations).
  • Despite these changes, the issue persists.

Additional Notes:

  • This behavior seems inconsistent, occurring most of the time after the first transfer.
  • Could be related to how conversation context or delegation is being maintained.

poornatejaMV avatar Sep 22 '25 06:09 poornatejaMV

facing same issue

ssingh5bmcd avatar Sep 23 '25 07:09 ssingh5bmcd

Facing the same issue here

sivakumar-d3v avatar Sep 24 '25 06:09 sivakumar-d3v

instead of using the subagents use agent tools for example:

Lets assume, you have a root agent A, which has agent_tools: B, C, D. agent_tool C has further agent_tools E, F, G. agent_tool E has access to tools a, b, c

CODE EXAMPLE

import datetime
import json
from google.adk.agents import Agent
from google.adk.tools import google_search, ToolContext
from google.adk.tools.agent_tool import AgentTool
from pathlib import Path

REMINDERS_FILE = Path(__file__).parent / "reminders.json"

def save_remainder(tool_context: ToolContext, title: str, description: str, time: str):
    """Saves a reminder to a JSON file, appending it to existing reminders.

        This tool is used to schedule or save a reminder for the user. It captures
        the title, a detailed description, and the specific time for the reminder.

        Args:
            title: The main subject or title of the reminder (e.g., "Doctor's Appointment").
            description: A detailed description of what the user needs to be reminded about.
            time: The exact date and time for the reminder in ISO format (e.g., '2024-10-26T10:00:00').
        """
    new_reminder = {
        "title": title,
        "description": description,
        "time": time,  # Use ISO format for standard serialization
        "created_at": datetime.datetime.now().isoformat(),
        "created_by": tool_context._invocation_context.user_id
    }
    print("-".join(["-" for x in range(15)]))
    print(f"user_content: {tool_context.user_content}")
    print(f"user_id: {tool_context._invocation_context.user_id}")
    print("-".join(["-" for x in range(15)]))
    reminders = []
    # Read existing reminders if the file exists
    if REMINDERS_FILE.exists():
        with open(REMINDERS_FILE, "r") as f:
            try:
                reminders = json.load(f)
            except json.JSONDecodeError:
                # Handle case where file is empty or corrupt
                pass

    # Append the new reminder
    reminders.append(new_reminder)

    # Write the updated list back to the file
    with open(REMINDERS_FILE, "w") as f:
        json.dump(reminders, f, indent=4)

    return f"Success: The reminder '{title}' has been set for {time}."


remind_me_agent = Agent(
    name= "remind_me",
    model = "gemini-2.5-pro",
    description="A specialized agent that helps users set, manage, and save reminders for future events or tasks.",
    instruction=(
        "You are a reminder assistant. Your primary function is to capture the details of a reminder "
        "and use the `save_reminder` tool. You must extract a clear 'title', 'description', and a specific 'time' "
        "from the user's request before calling the tool. If any piece of information is missing, "
        "ask the user for clarification."
    ),
    tools=[
        save_remainder
    ]
)

internet_search_agent = Agent(
    name= "internet_search_agent",
    model = "gemini-2.5-flash-lite",
    description="you can search internet to answer user queries",
    instruction=(
        "use `google_search` tool to search internet"
    ),
    tools=[
        google_search
    ]
)


root_agent = Agent(
    name= "personal_assistant",
    model = "gemini-2.5-pro",
    description= (
        "You are a highly capable and friendly personal assistant. "
        "Your goal is to help users with their tasks and questions efficiently. "
        "You have access to a variety of tools to find information"
    ),
    instruction= "First, understand the user's intent. If it's a general question, use `internet_search_agent`. "
        "If the user wants to set a reminder, delegate the task to the `remind_me` agent. "
        "Be helpful and clear in your responses.",
    tools=[
        AgentTool(internet_search_agent),
        AgentTool(remind_me_agent)
    ]
)

akshaypachpute-1998 avatar Sep 25 '25 11:09 akshaypachpute-1998

refer: https://cloud.google.com/blog/products/ai-machine-learning/build-multi-agentic-systems-using-google-adk

akshaypachpute-1998 avatar Sep 25 '25 11:09 akshaypachpute-1998

@speedstorm1 - Could I be assigned to this?

speedstorm1 avatar Oct 28 '25 06:10 speedstorm1

Thanks for reaching out, @poornatejaMV .

As @akshaypachpute-1998 has mentioned, (and is mentioned in the article at https://cloud.google.com/blog/products/ai-machine-learning/build-multi-agentic-systems-using-google-adk), using agents as tools is a better approach for this use case, as it supports more dynamic switching between agents. This should make it so that the correct request transferring you see before the first transfer will persist throughout.

speedstorm1 avatar Oct 28 '25 17:10 speedstorm1

if we use as Agent tool latency will increase and subagents doesnt no what the user intention its totally depend on main agent , if main agent done any wrong entire system fails , @Jacksunwei

vk4433 avatar Jan 16 '26 13:01 vk4433