Observing agents built with Google ADK

The Google Agent Development Kit (ADK) is a framework for building, orchestrating, and deploying intelligent agent-based applications. It provides a structured and scalable way to define agent workflows, integrate tools and external services, and manage agent reasoning and execution. ADK is designed to support production-ready AI agents by providing abstractions for task coordination, tool invocation, and interaction with large language models.

Monitoring Google ADK applications with Instana provides comprehensive end-to-end observability into agent-driven workflows. By instrumenting ADK applications, you can capture detailed execution paths across agent orchestration logic, tool invocations, external service calls, and the underlying infrastructure.

Prerequisites

Make sure that the following prerequisites are met:

  • Python 3.8 or later is installed.

  • A Google API key for accessing Gemini models, see Google AI Studio.

  • Instana is configured for your application, see Getting started.

Instrumenting Google ADK applications

To instrument your Google ADK application with Instana observability, complete the following steps:

  1. Install the required packages for Google ADK:

    pip install google-adk traceloop-sdk
  2. Create a new Google ADK agent project:

    adk create test_agent

    This creates a project with the following structure, where agent.py contains the core control logic for the agent:

    Figure 1. Agent file structure
    Agent file structure
  3. Set your Google API key in the .env file:

    GOOGLE_API_KEY=<your-google-api-key>

    To create or manage your API keys, visit Google AI Studio.

  4. Update the agent.py file with the following code to create a multi-agent application with OpenLLMetry instrumentation:

    from google.adk.agents.llm_agent import Agent
    from traceloop.sdk import Traceloop
    
    # Initialize OpenLLMetry with app name
    Traceloop.init(app_name="multi_agent_adk_app")
    
    # Tool implementations
    def get_current_time(city: str) -> dict:
        """Returns the current time for a given city."""
        return {"city": city, "time": "10:30 AM"}
    
    def get_weather(city: str) -> dict:
        """Returns the current weather for a given city."""
        return {"city": city, "weather": "Sunny", "temperature": "30°C"}
    
    
    # Time Agent
    time_agent = Agent(
        name="time_agent",
        model="gemini-2.0-flash-exp",
        description="Provides the current time for a city.",
        instruction=(
            "You provide the current time for a given city. "
            "Use the get_current_time tool to fetch the information."
        ),
        tools=[get_current_time],
    )
    
    # Weather Agent
    weather_agent = Agent(
        name="weather_agent",
        model="gemini-2.0-flash-exp",
        description="Provides the current weather for a city.",
        instruction=(
            "You provide the current weather details for a given city. "
            "Use the get_weather tool to fetch the information."
        ),
        tools=[get_weather],
    )
    
    # Root Agent orchestrating other agents
    root_agent = Agent(
        name="root_agent",
        model="gemini-2.0-flash-exp",
        description="Orchestrates multiple agents to answer user queries.",
        instruction=(
            "You are a coordinating agent. Based on the user request, "
            "delegate tasks to the appropriate agent (time_agent or weather_agent) "
            "and combine the responses into a single answer."
        ),
        sub_agents=[time_agent, weather_agent],
    )

    This example creates three agents:

    • time_agent: Provides current time for cities

    • weather_agent: Provides weather information for cities

    • root_agent: Orchestrates the other agents to handle user requests

  5. Start the Google ADK agent:

    adk run test_agent

    The agent will start and wait for user input. You can interact with it by asking questions like "What's the weather in New York?" or "What time is it in London?"

  6. View data in Instana.

    After running your application and interacting with the agents, data will appear in the Instana Gen AI observability dashboard:

    Figure 2. Response to user request
    Response to user request
    Figure 3. Traces in Instana
    Traces in Instana

    The dashboard shows:

    • Agent orchestration flow

    • Tool invocations (get_current_time, get_weather)

    • LLM interactions with Gemini models

    • Response times and token usage

Troubleshooting

For common issues such as traces not appearing or connection errors, see Troubleshooting.

Google API key errors

Issue: Authentication errors when you run the agent.

To troubleshoot this issue, try the following steps:

  1. Verify your Google API key is correctly set in the .env file

  2. Ensure the API key has access to Gemini models

  3. Check that the .env file is in the project root directory