> Documentation index: https://metorial.com/llms.txt. Every page is available as Markdown by adding .md to its URL.

# Add Metorial tools to a Google ADK agent in Python
URL: https://metorial.com/docs/build/frameworks/google-adk

Connect with metorial.connect(adapter=metorial_google_adk(), providers=[...]) and pass session.tools() to a Google ADK Agent, then run it with a Runner.

---

This guide takes you from an empty folder to a Google ADK agent that searches the web through Metorial. Connect with `metorial.connect(adapter=metorial_google_adk(), providers=[...])`, pass `session.tools()` to `Agent`, and run it with a `Runner`.

**What you'll learn**

* How to create an API key and a provider deployment from the CLI
* How to pass Metorial tools to a Google ADK `Agent`
* How to see the tool calls the agent made

**Before you start**

* [Install the CLI and sign in](https://metorial.com/docs/build/sandboxes#install-the-tools)
* A Gemini API key
* Python 3.10 or later

## Set up Metorial with the CLI

### 1. Find your instance

An instance is one environment of a project. List yours and note the ID of the one the agent should use:

```bash
metorial-admin instance list
```

### 2. Create an API key

```bash
metorial-admin api-keys create \
  --type instance_access_token_secret \
  --instance-id <instance-id> \
  --name my-agent
```

Copy the secret from the output. It starts with `metorial_sk_` and is shown only once.

### 3. Deploy a provider

Metorial Search is a built-in web search provider that needs no credentials.

```bash
metorial-admin providers deployments create \
  --provider-id metorial-search \
  --name "Metorial Search"
```

Copy the deployment ID from the output. It starts with `pde_`.

### 4. Export the values

```bash
export METORIAL_API_KEY="metorial_sk_..."
export METORIAL_PROVIDER_DEPLOYMENT_ID="pde_..."
export GOOGLE_API_KEY="..."
```

## Build the agent

### 1. Create the project

```bash
mkdir my-agent && cd my-agent
python3 -m venv .venv
source .venv/bin/activate
pip install metorial google-adk
```

### 2. Write the agent

Save this as `agent.py`. The adapter ships with the `metorial` package and turns every tool in the session into an async Python function, which ADK wraps as a function tool.

```python
import asyncio
import os

from google.adk.agents import Agent
from google.adk.runners import Runner
from google.adk.sessions import InMemorySessionService
from google.genai import types
from metorial import Metorial, metorial_google_adk

APP_NAME = "metorial-research"
USER_ID = "user-1"
SESSION_ID = "session-1"


async def main():
    metorial = Metorial(api_key=os.environ["METORIAL_API_KEY"])

    session = await metorial.connect(
        adapter=metorial_google_adk(),
        providers=[
            {"provider_deployment_id": os.environ["METORIAL_PROVIDER_DEPLOYMENT_ID"]}
        ],
    )

    tools = session.tools()
    print("Metorial tools:", ", ".join(tool.__name__ for tool in tools))

    agent = Agent(
        model="gemini-flash-latest",
        name="research_assistant",
        description="Answers questions with facts found on the web.",
        instruction="Use the Metorial tools to answer the question.",
        tools=tools,
    )

    session_service = InMemorySessionService()
    await session_service.create_session(
        app_name=APP_NAME,
        user_id=USER_ID,
        session_id=SESSION_ID,
    )
    runner = Runner(agent=agent, app_name=APP_NAME, session_service=session_service)

    message = types.Content(
        role="user",
        parts=[
            types.Part(
                text="Search the web for the latest news about AI agents and summarize the top 3 stories."
            )
        ],
    )

    async for event in runner.run_async(
        user_id=USER_ID,
        session_id=SESSION_ID,
        new_message=message,
    ):
        if event.is_final_response() and event.content and event.content.parts:
            print(event.content.parts[0].text)


asyncio.run(main())
```

### 3. Run it

```bash
python agent.py
```

> **Note:** The adapter passes only each tool's required parameters to ADK, so the model cannot set optional ones. The ADK session holds the conversation. The Metorial session holds the tools.

## Check it worked

The first line lists the tools, then the agent prints its summary. Metorial prefixes each tool with the provider name and adds `metorial_connection_status`, a diagnostic tool, to every session.

```text
Metorial tools: metorial_connection_status, metorial_search_getWebContent, metorial_search_webSearch
<a summary of three news stories>
```

List the tool calls Metorial recorded for the deployment:

```bash
metorial-admin sessions tool-calls list \
  --provider-deployment-id $METORIAL_PROVIDER_DEPLOYMENT_ID \
  --limit 5
```

## Use other apps and each user's own account

Find a provider and deploy it the same way, then add its deployment ID to `providers`. One session can hold several.

```bash
metorial-admin providers list --search gmail
metorial-admin providers deployments create --provider-id <provider-id> --name "Gmail"
```

Apps such as Gmail need a sign-in. Pass the user's provider auth config as `provider_auth_config_id` next to `provider_deployment_id`. [Let each user connect their own account](https://metorial.com/docs/build/sdk/oauth) shows how to get one for each user.

## Troubleshooting

### `Invalid API key status=401`

The SDK raises this `AuthenticationError` when the key is wrong. Check that `METORIAL_API_KEY` holds the full secret and belongs to the instance where you created the deployment.

### `ValueError: api_key is required`

`METORIAL_API_KEY` is empty in the shell that runs the script.

### `Provider requires an auth config to be provided`

A provider deployment in the session needs a sign-in and got no provider auth config. Add the user's `provider_auth_config_id` to that entry.

## Next steps

* [Let each user connect their own account](https://metorial.com/docs/build/sdk/oauth): per-user OAuth for Slack, Gmail, GitHub and other apps
* [Limit the tools an agent can use](https://metorial.com/docs/build/guides/limit-agent-tools): serve only some of a provider's tools
* [Using with Google](https://metorial.com/docs/build/providers/google): Metorial tools with the Gemini SDK, without ADK
* [The Google ADK example on GitHub](https://github.com/metorial/metorial-python/tree/main/examples/google-adk)