[Python] Google ADK Agent Delegation: Why Does GPT-4o Fail at Multi-Agent Coordination While...

Discussão em 'Python' iniciado por Stack, Julho 28, 2025.

  1. Stack

    Stack Membro Participativo

    System Architecture & Flow


    I've implemented a multi-agent system using Google's Agent Development Kit (ADK) with HTTP-based Agent-to-Agent (A2A) communication:

    ┌─────────────────┐ HTTP/A2A ┌─────────────────┐
    │ Orchestrator │◄────────────────►│ Data Processor │
    │ (Port 10022) │ │ (Port 10020) │
    └─────────┬───────┘ └─────────────────┘
    │
    │ HTTP/A2A
    │
    ▼
    ┌─────────────────┐
    │ Task Executor │
    │ (Port 10021) │
    └─────────────────┘

    Implementation Details


    Base Agent Class using Google ADK:

    class BaseAgent(ABC):
    def _create_agent(self) -> Agent:
    # Model configuration (the key difference)
    if using_gemini:
    gemini_model = Gemini(model="gemini-2.0-flash")
    gemini_model._api_client = Client(api_key=settings.gemini_api_key)
    model = gemini_model
    else:
    # LiteLLM wrapper for OpenAI
    model = LiteLlmModel(model="gpt-4o", api_key=settings.openai_api_key)

    agent_params = {
    "model": model,
    "name": self.config.name,
    "instruction": self._get_instruction(),
    "tools": self._get_tools()
    }

    # Configure sub-agents for orchestrator
    sub_agents = self._get_sub_agents()
    if sub_agents:
    agent_params["sub_agents"] = sub_agents

    return Agent(**agent_params)


    Orchestrator Configuration with delegation syntax:

    def _get_instruction(self) -> str:
    return """
    You are an agent coordinator that MUST delegate tasks using @agent_name syntax.

    DELEGATION RULES:
    - Analysis requests → @data_processor [request]
    - Automation requests → @task_executor [request]
    - Complex requests → BOTH agents

    EXACT FORMAT:
    @data_processor Please analyze the sales data
    @task_executor Please create automation workflows
    """

    def _get_sub_agents(self) -> List[RemoteA2aAgent]:
    return [
    RemoteA2aAgent(
    name="data_processor",
    agent_card="http://127.0.0.1:10020/.well-known/agent.json"
    ),
    RemoteA2aAgent(
    name="task_executor",
    agent_card="http://127.0.0.1:10021/.well-known/agent.json"
    )
    ]

    The Problem: Model-Dependent Delegation Behavior


    For the request: "Evaluate our sales data and create automated reporting"

    ❌ With GPT-4o/GPT-4o-mini (FAILS)


    Agent Calls Made:

    HTTP Request: GET http://127.0.0.1:10021/.well-known/agent.json # Only task_executor
    Successfully resolved remote A2A agent: task_executor
    HTTP Request: POST http://127.0.0.1:10021 # Only calls one agent


    Response:

    {
    "response": "To analyze your sales data and create reporting, I recommend following these steps:\n1. Gather your data...\n2. Use analytics tools...\n[Provides direct solution instead of delegating]",
    "status": "success"
    }


    Problem: GPT models ignore delegation instructions and provide direct solutions, or only delegate to one agent even for complex dual-requirement requests.

    ✅ With Gemini 2.0-flash (WORKS PERFECTLY)


    Agent Calls Made:

    HTTP Request: GET http://127.0.0.1:10020/.well-known/agent.json # data_processor
    Successfully resolved remote A2A agent: data_processor
    HTTP Request: POST http://127.0.0.1:10020

    HTTP Request: GET http://127.0.0.1:10021/.well-known/agent.json # task_executor
    Successfully resolved remote A2A agent: task_executor
    HTTP Request: POST http://127.0.0.1:10021


    Response:

    {
    "response": "@data_processor Please analyze our sales data to identify key metrics, trends, and performance insights.\n\n@task_executor Please create an automated reporting system based on the data analysis to generate regular reports.",
    "status": "success"
    }


    Success: Gemini correctly generates the @agent_name delegation syntax, and Google ADK automatically processes these commands to make HTTP calls to both specialist agents.

    Evidence of Model-Specific Behavior

    Logging Comparison


    GPT-4o Logs:

    LiteLLM completion() model= gpt-4o; provider = openai
    # Only fetches one agent card, provides direct solutions


    Gemini 2.0-flash Logs:

    google.adk.models.google_llm.Gemini
    # Fetches multiple agent cards, follows delegation patterns

    Delegation Pattern Recognition

    Request Type GPT-4o Behavior Gemini 2.0-flash Behavior
    "Analyze sales data" ✅ Correctly delegates to data_processor ✅ Correctly delegates to data_processor
    "Create automation" ✅ Correctly delegates to task_executor ✅ Correctly delegates to task_executor
    "Analyze data AND create automation" ❌ Only calls task_executor OR provides direct solution ✅ Correctly calls BOTH agents with @agent_name syntax
    Core Question


    Why do GPT models fail at multi-agent delegation while Gemini models excel at it in Google ADK?

    Specific Sub-Questions:


    1. Framework Training Differences: Is Gemini specifically trained on Google ADK delegation patterns (@agent_name syntax) while GPT models are not?


    2. Instruction Following Behavior: Why do GPT models tend to "solve problems directly" instead of following delegation instructions, even with explicit prompts?


    3. Integration Level: Does Google ADK's delegation mechanism rely on model-specific features that are native to Gemini but foreign to OpenAI models?


    4. Delegation Syntax Recognition: Is the @agent_name syntax a Google-specific pattern that Gemini understands natively but GPT models interpret as mere text formatting?
    Technical Hypothesis


    Gemini Advantage Theory:

    • Native Integration: Gemini was designed for Google's AI ecosystem and understands ADK delegation patterns
    • Training Data: Gemini models were exposed to Google ADK documentation and @agent_name syntax during training
    • Framework Optimization: Google ADK + Gemini = optimized delegation processing, while ADK + OpenAI = compatibility layer issues

    GPT Limitation Theory:

    • General Purpose Design: GPT models are trained for general conversation, not specific agent orchestration patterns
    • Solution-Oriented Behavior: GPT models are incentivized to provide complete answers rather than delegate
    • Syntax Interpretation: GPT treats @agent_name as text formatting rather than functional commands
    Configuration Details


    Current Working Setup (Gemini):

    # .env configuration
    GEMINI_DEFAULT_MODEL=gemini-2.0-flash
    GEMINI_API_KEY=your_api_key

    # Agent configuration
    gemini_model = Gemini(model="gemini-2.0-flash")
    gemini_model._api_client = Client(api_key=settings.gemini_api_key)


    Previous Failing Setup (GPT):

    # .env configuration
    OPENAI_DEFAULT_MODEL=gpt-4o
    OPENAI_API_KEY=your_api_key

    # Agent configuration via LiteLLM
    model = LiteLlmModel(model="gpt-4o", api_key=settings.openai_api_key)


    Has anyone else experienced this model-dependent delegation behavior with Google ADK? Is this a known limitation of using non-Google models with Google's agent framework, or are there specific configuration patterns that make GPT models work properly with ADK delegation?

    The HTTP infrastructure works perfectly with both models - the issue is purely in the delegation decision-making and execution at the LLM level.

    Continue reading...

Compartilhe esta Página