# Gate Google ADK tools

Add approvals to a Google ADK agent with a before_tool_callback, so each gated tool call is authorized and verified on its exact arguments, with a person's approval when your policy asks, before it runs.

Use `provenanceauth-google-adk` to add approvals to an agent built with Google's Agent Development Kit (ADK). Its `before_tool_callback` authorizes and verifies each listed tool call on its exact arguments before the tool runs, and waits for a person when your [policy](https://provenanceauth.com/docs/concepts/policies.md) asks for one.

**Before you begin:** install the package, and export the sandbox account key.

```bash
export PROVENANCE_API=https://sandbox-api.provenanceauth.com
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
```

**This package isn't on PyPI yet.** Until then, every request in these docs runs over HTTP against the [sandbox](https://provenanceauth.com/docs/get-started/sandbox.md).

With access to the private Provenance repository, which your Provenance contact grants, install from it:

```bash
git clone https://github.com/michaelnbane-jpg/provenance.git provenance
pip install ./provenance/python/sdk ./provenance/python/google-adk-provenance
```

**Availability:** the package is available to beta customers. It supports `google-adk` 1.20 to 2.x.

## 1. Add the callback

`provenance_before_tool` returns a `before_tool_callback`. List the tools to gate by name:

**Python**

```python
import os
from google.adk.agents import LlmAgent
from provenanceauth_google_adk import provenance_before_tool
from provenanceauth import Provenance

prov = Provenance(os.environ["PROVENANCE_KEY"], base_url=os.environ["PROVENANCE_API"])

def pay_invoice(invoice: str, amount: float, payee: str) -> dict:
    """Pay a supplier invoice."""
    return {"status": "paid", "invoice": invoice}

agent = LlmAgent(
    name="billing",
    model="gemini-2.5-flash",
    instruction="Pay supplier invoices.",
    tools=[pay_invoice],
    before_tool_callback=provenance_before_tool(
        tools=["pay_invoice"],
        client=prov,
        device_id="dev_00000000000000000000000000000001",
    ),
)
```

Each call is bound to the ADK session id as the agent session. By default the action description is the tool name and the canonical JSON of its arguments, and the payload is `{ "tool", "input" }`.

## 2. Read the outcome

| Outcome | What happens |
| --- | --- |
| Verified | The callback returns `None`, and the tool runs with the arguments that were verified |
| Denied | The callback returns `{"status": "denied", "reason": …}`, which ADK uses as the tool's result instead of running it |
| Waiting for approval | The callback waits for the person, up to `timeout_ms` (default 2 minutes), then lets the tool run or denies it |

The reason is a sentence the model reads, such as "The person declined this action." If the person hasn't answered when the wait ends, it says "Waiting for approval (appr_…)", and the next call with the same arguments reuses the token that opened the approval. Tools you don't list run as usual.

## 3. Show the wait with tool confirmation

Pass `confirmation=True` to use ADK's tool confirmation as the waiting screen. When a call is still waiting, the callback asks the client to confirm, with a hint naming the approval. When the person's client confirms, ADK runs the callback again, and the tool runs only if Provenance now says the person approved:

```python
before = provenance_before_tool(
    tools=["pay_invoice"],
    client=prov,
    device_id="dev_00000000000000000000000000000001",
    timeout_ms=0,
    confirmation=True,
)
```

## 4. Pass the rest of the options

Pass a dict of tool name → options as `tools` to set the options below for one tool, or pass them to `provenance_before_tool` for every tool:

- `context` (function): Facts for your [policy](https://provenanceauth.com/docs/concepts/policies.md), read at verify.
- `run_id` (string): An [agent-team run](https://provenanceauth.com/docs/mandate/guides/halt-a-run.md) to bind each call to.
- `mandate_token` (string): A grant to authorize under.
- `agent_id` (string): The registered agent making the calls.
- `timeout_ms` (number): How long to wait for the person. `0` answers at once.

## Errors you might see

| Symptom | Cause | Fix |
| --- | --- | --- |
| A listed tool always runs | The name doesn't match the tool's `name` | Use the function's name, or a trailing `*` for a prefix. |
| The model reads "Waiting for approval" | The person hadn't answered within `timeout_ms` | Raise `timeout_ms`, or turn on `confirmation`. |

## See also

- [Framework integrations](https://provenanceauth.com/docs/mandate/guides/framework-integrations.md)
- [Step-up approval](https://provenanceauth.com/docs/mandate/guides/step-up-approval.md)
