> ## Documentation Index
> Fetch the complete documentation index at: https://traceroot.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Google ADK

> Auto-instrument Google Agent Development Kit agents, workflows, tools, and runners

Automatically capture agent runs, workflow graphs, tool executions, and the underlying Gemini calls within the [Google Agent Development Kit (ADK)](https://github.com/google/adk-python).

## Install

> [tab] Python
>
> ```bash theme={null}
> pip install traceroot google-adk
> ```

## Set up

> [tab] Python
>
> ```python theme={null}
> import traceroot
> from traceroot import Integration
>
> traceroot.initialize(integrations=[Integration.GOOGLE_ADK])
> ```

## Usage

Once initialized, ADK agent runs, tool calls, and Gemini calls are captured automatically:

```python theme={null}
import asyncio
import traceroot
from traceroot import Integration
from google.adk import Agent
from google.adk.runners import InMemoryRunner
from google.genai import types

traceroot.initialize(integrations=[Integration.GOOGLE_ADK])


def get_weather(city: str) -> dict:
    """Get current weather for a city."""
    return {"status": "success", "city": city, "temp": 72, "condition": "sunny"}


# ADK resolves the Gemini API key from GOOGLE_API_KEY in the environment.
agent = Agent(
    name="assistant",
    model="gemini-3.8-flash",
    description="Helpful assistant with access to tools.",
    instruction="You are a helpful AI assistant. Use tools when needed.",
    tools=[get_weather],
)


async def main():
    runner = InMemoryRunner(agent=agent, app_name="traceroot-adk-demo")
    await runner.session_service.create_session(
        app_name="traceroot-adk-demo",
        user_id="demo-user",
        session_id="demo-session",
    )

    # The full run, including tool calls and Gemini calls, is traced
    async for event in runner.run_async(
        user_id="demo-user",
        session_id="demo-session",
        new_message=types.Content(
            role="user",
            parts=[types.Part(text="What's the weather in Tokyo?")],
        ),
    ):
        if event.is_final_response() and event.content and event.content.parts:
            print(event.content.parts[0].text)


if __name__ == "__main__":
    asyncio.run(main())
    traceroot.flush()
```

### Usage with the ADK CLI

If you run your agent with `adk run` or `adk web`, initialize traceroot at the top of `agent.py`:

```python theme={null}
# my_agent/agent.py
import traceroot
from traceroot import Integration
from google.adk import Agent

traceroot.initialize(integrations=[Integration.GOOGLE_ADK])


def get_current_time(city: str) -> dict:
    """Returns the current time in a specified city."""
    return {"status": "success", "city": city, "time": "10:30 AM"}


root_agent = Agent(
    model="gemini-3.8-flash",
    name="root_agent",
    description="Tells the current time in a specified city.",
    instruction="Use the 'get_current_time' tool to answer.",
    tools=[get_current_time],
)
```

> [!NOTE]
>
> `adk web` and `adk api_server` install their own OpenTelemetry tracer provider before `agent.py` loads. From `traceroot` 0.3.0, `@observe` spans are traced alongside ADK's spans in these modes. On 0.2.0, ADK's spans still arrive but `@observe` spans are dropped; use `adk run` or your own runner instead.

### Usage with Workflows

ADK 2.x runs agents, tools, and plain Python functions as nodes of a graph `Workflow`. Each workflow run, node, fan-out, and join is traced:

```python theme={null}
import asyncio
import traceroot
from traceroot import Integration
from google.adk import Agent, Event, Workflow
from google.adk.runners import InMemoryRunner
from google.adk.workflow import JoinNode
from google.genai import types

traceroot.initialize(integrations=[Integration.GOOGLE_ADK])


def record_city(node_input: str):
    """Store the city in session state and pass it on to both branches."""
    city = node_input.strip()
    return Event(output=city, state={"city": city})


def get_weather(city: str) -> dict:
    """Get current weather for the city in session state."""
    return {"city": city, "temp": 72, "condition": "sunny"}


suggest_food = Agent(
    name="suggest_food",
    model="gemini-3.8-flash",
    instruction="In one sentence, name a signature local dish to try in {city}.",
)

# START -> record_city -> (get_weather, suggest_food in parallel) -> gather
workflow = Workflow(
    name="city_brief",
    edges=[("START", record_city, (get_weather, suggest_food), JoinNode(name="gather"))],
)


async def main():
    runner = InMemoryRunner(agent=workflow, app_name="traceroot-adk-workflow")
    await runner.session_service.create_session(
        app_name="traceroot-adk-workflow",
        user_id="demo-user",
        session_id="demo-session",
    )

    # The workflow run and every node in it are traced
    output = None
    async for event in runner.run_async(
        user_id="demo-user",
        session_id="demo-session",
        new_message=types.Content(role="user", parts=[types.Part(text="Tokyo")]),
    ):
        if event.output is not None:
            output = event.output
    # The last output is the joined result, keyed by branch name
    print(output)


if __name__ == "__main__":
    asyncio.run(main())
    traceroot.flush()
```

> [!NOTE]
>
> Workflow and node spans need the first `traceroot` release after 0.2.0. On 0.2.0, only the `Agent` nodes of a workflow appear.

## Verify

Run your code and confirm the trace arrives:

1. **In the traceroot UI**: Navigate to **Tracing > Traces** in [traceroot Cloud](https://app.traceroot.ai). You should see a trace with root span `invocation [<app>]`, or `invoke_workflow <name>` for workflow runs (requires a `traceroot` release newer than 0.2.0).
2. **Via the CLI**: Run `traceroot traces list` to inspect your recent traces from the terminal.

## What gets captured

| Attribute | Description |
| - | - |
| Runner calls | An `invocation [<app>]` span per runner call |
| Workflow runs | An `invoke_workflow <name>` span per workflow run |
| Workflow nodes | An `invoke_node <name>` span per function or join node; `Agent` nodes appear as agent runs |
| Agent runs | An `agent_run [<agent>]` agent span per agent and sub-agent run |
| LLM calls | A `call_llm` span per Gemini call with model, request, and response |
| Tool calls | A tool span per tool call, named after the tool, with input arguments and result |
| Tokens & Cost | Input, output, and reasoning token counts per LLM call; cost for models in the pricing table, including `gemini-3.8-flash` |
| Sessions & users | The ADK session id as `session.id` and user id as `user.id` on every span |
| Latency | Duration per agent run and per span |

## Limitations

* Model aliases such as `gemini-flash-latest` are not priced; pin a concrete model ID (such as `gemini-3.8-flash`) to capture token costs.
* `adk web` and `adk api_server` install their own OpenTelemetry tracer provider before `agent.py` loads; traceroot >= 0.3.0 is recommended when using these modes.

## Run the example

Clone the repo and run a complete agent end-to-end.

> [card] [Agent](https://github.com/traceroot-ai/traceroot/tree/main/examples/python/google-adk-agent)
>
> Run the Python agent example

> [card] [Workflow](https://github.com/traceroot-ai/traceroot/tree/main/examples/python/google-adk-workflow)
>
> Run the Python workflow example

## Next steps

> [card] [Python SDK Reference](https://traceroot.ai/docs/tracing/python-sdk.md)
>
> Explore the full Python SDK reference and instrumentation options.

> [card] [Cost Tracking](https://traceroot.ai/docs/tracing/cost-tracking.md)
>
> Learn how traceroot calculates token costs and tracks model spend.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.