> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-docs-hivemind-launch.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Google ADK

> Trace an agent built with Google's Agent Development Kit (ADK) using Weave.

<Note>
  Weave for Agents is in public preview. Features, APIs, and the Agents view UI may change before general availability.
</Note>

[Google's Agent Development Kit (ADK)](https://google.github.io/adk-docs/) is a flexible, model-agnostic Python framework for building and orchestrating agents. While optimized for Gemini, ADK supports any model and supports both simple tasks and complex multi-agent workflows. Weave automatically traces agents built with ADK, including each agent invocation, sub-agent handoff, model call, and tool call. Weave displays the captured data in the **Agents** view of your project.

## Trace Google ADK agents with Weave

The Weave SDK autopatches with Google ADK, allowing you to capture traces from your ADK agents with minimal set up. This doc shows how to initialize Weave and then run a multi-turn research agent built with Google ADK so that Weave captures every agent invocation, model call, and tool call across the session.

### Prerequisites

* A W\&B account and [API key](https://wandb.ai/authorize) set as a `WANDB_API_KEY` environment variable
* A [Google API key](https://aistudio.google.com/apikey) for Gemini
* Python 3.10+

### Install packages

Install the following packages in your developer environment:

```bash theme={null}
pip install weave google-adk requests
```

### Initialize Weave in your code

Add `weave.init` to the project, along with your W\&B team and project names, and then build an agent the way you normally would. The following code creates a `research_assistant` agent that uses `gemini-2.5-flash` and a `wikipedia_search` tool, then runs three questions through a single ADK session while Weave captures the trace.

```python lines theme={null}
import asyncio
import requests
import weave
from google.adk.agents import Agent
from google.adk.runners import InMemoryRunner
from google.genai import types

weave.init("<your-team>/<your-project-name>")

def wikipedia_search(query: str) -> dict:
    """Search Wikipedia for a topic and return its title and intro paragraph.

    Args:
        query: The topic to search for.

    Returns:
        A dictionary with the article title and intro extract.
    """
    r = requests.get(
        "https://en.wikipedia.org/w/api.php",
        params={
            "action": "query", "generator": "search", "gsrsearch": query, "gsrlimit": 1,
            "prop": "extracts", "exintro": True, "explaintext": True, "format": "json",
        },
        headers={"User-Agent": "weave-demo"},
    ).json()
    page = next(iter(r["query"]["pages"].values()))
    return {"title": page["title"], "extract": page["extract"]}

agent = Agent(
    name="research_assistant",
    model="gemini-2.5-flash",
    instruction=(
        "You are a research assistant. Use the wikipedia_search tool to look up "
        "topics when needed, and cite the article titles you used."
    ),
    tools=[wikipedia_search],
)

async def main():
    runner = InMemoryRunner(agent=agent, app_name="research-app")
    session = await runner.session_service.create_session(
        app_name="research-app", user_id="user-1"
    )

    questions = [
        "Who founded Anthropic?",
        "What is Claude (the AI assistant)?",
        "Summarize what we discussed in one sentence.",
    ]

    for question in questions:
        print(f"USER: {question}")
        async for event in runner.run_async(
            user_id="user-1",
            session_id=session.id,
            new_message=types.Content(
                role="user",
                parts=[types.Part(text=question)],
            ),
        ):
            if event.is_final_response() and event.content:
                print(f"AGENT: {event.content.parts[0].text}\n")

asyncio.run(main())
```

The example runs three turns in a single ADK session. The first two turns trigger Wikipedia lookups, and the third uses the prior conversation context to produce a summary without a tool call.

### See your agent traces in the Agents view

`weave.init()` prints a link to your project when it runs. Open the **Agents** view to inspect:

* A row in the **Agents** tab for `research_assistant`
* A single session containing three turns
* Each turn rendered as an `invoke_agent` span with nested model calls and tool calls
* The full input, model, output, token usage, and Wikipedia results at each step

For details on viewing Agents data in Weave, see [View agent activity](/weave/guides/tracking/view-agent-activity).
