Metadata-Version: 2.4
Name: recusal-google-adk
Version: 0.2.2
Summary: Recusal gate for Google ADK: judge every tool call in a before-tool callback or a runner plugin, refuse before it runs, and optionally put each decision on a hash-chained audit log.
Project-URL: Homepage, https://recusal.io
Project-URL: Documentation, https://github.com/philpaz/recusal/tree/main/adapters/google-adk
Project-URL: Repository, https://github.com/philpaz/recusal
Project-URL: Issues, https://github.com/philpaz/recusal/issues
Project-URL: Changelog, https://github.com/philpaz/recusal/blob/main/CHANGELOG.md
Author-email: Philip Paz <philip.paz@gmail.com>
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: agent-governance,ai-agents,google-adk,guardrails,recusal,tool-use
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Security
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: google-adk<3,>=2.14.0
Requires-Dist: recusal<1,>=0.17.1
Description-Content-Type: text/markdown

<p align="center">
  <a href="https://recusal.io">
    <picture>
      <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/philpaz/recusal/main/assets/banner-gate-strip.png">
      <img alt="recusal, deterministic governance for AI agents" src="https://raw.githubusercontent.com/philpaz/recusal/main/assets/banner-gate-strip-light.png" width="880">
    </picture>
  </a>
</p>

# recusal-google-adk

[![Website](https://img.shields.io/badge/website-recusal.io-2453c4)](https://recusal.io)
[![PyPI](https://img.shields.io/pypi/v/recusal-google-adk)](https://pypi.org/project/recusal-google-adk/)
[![CI](https://github.com/philpaz/recusal/actions/workflows/ci.yml/badge.svg)](https://github.com/philpaz/recusal/actions/workflows/ci.yml)
[![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/philpaz/recusal/badge)](https://scorecard.dev/viewer/?uri=github.com/philpaz/recusal)
![python](https://img.shields.io/badge/python-3.11%2B-blue)
![license](https://img.shields.io/badge/license-Apache--2.0-green)

The [Recusal](https://github.com/philpaz/recusal) gate for
[Google ADK](https://google.github.io/adk-docs/): every tool call an agent proposes is
judged by your policy before the tool runs, and a refused call never runs.

**New to Recusal?** It checks each tool call an AI agent proposes against your policy and
refuses the unsafe or unapproved ones before the tool runs. No model makes that decision.
A policy is a plain Python function: it is given the tool's name and its arguments and
returns a list of findings. An empty list lets the call run; a failing finding refuses it
and gives the reason.
[Writing a policy](https://github.com/philpaz/recusal#write-the-policy-two-postures-one-principle)
covers the two postures, allowlist and deny-list.

<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/philpaz/recusal/main/assets/gate-position.svg">
    <img alt="Before the tool runs. An agent proposes a tool call. Recusal, your policy with no model in it, decides. With no objection the tool runs. On a failing finding, or when the policy itself raises, the call is refused: the tool never runs and the reason goes back to the model. Every decision can be written to a hash-chained audit log, if you pass one." src="https://raw.githubusercontent.com/philpaz/recusal/main/assets/gate-position-light.svg" width="880">
  </picture>
</p>

This is a separate distribution from `recusal`. The kernel has zero runtime dependencies
and a frozen compatibility perimeter; this package carries the ADK dependency and its own
version, so an ADK release never forces a release of the kernel.

Install it from PyPI:

```bash
pip install recusal-google-adk
```

Requires Python 3.11+ (the ADK's minimum), `recusal>=0.17.1` and `google-adk>=2.14.0`. It
is tested on every pull request against exactly `google-adk==2.14.0` with
`google-genai==2.34.0`, and weekly against the newest releases.

The package ships inline types (`py.typed`) for your editor and type checker.

## Use

```python
from google.adk.agents import LlmAgent
from recusal import Finding
from recusal_google_adk import gated_agent


def policy(tool_name, tool_input):
    sql = tool_input.get("sql", "")
    if tool_name == "run_sql" and sql.lstrip().upper().startswith("DELETE"):
        return [Finding.fail("no_deletes", severity="CRITICAL", message="DELETE is not allowed")]
    return []


agent = gated_agent(LlmAgent(name="assistant", model=model, tools=[run_sql]), policy)
```

`gated_agent` returns a copy of the agent with the gate appended as the last before-tool
callback, and gates its `sub_agents` and the agent behind every `AgentTool` the same way.
A refused call is answered to the model as `{"error": reason}`. The tool does not run. A
policy that raises refuses the call (fail closed).

The gate prepares the invocation (defaults completed, values validated against the
function's types whatever the ADK's own validation setting), judges a detached copy, and
the tool runs with exactly what was judged, apart from the parameters the ADK fills itself
(see below). A parameter whose default is `None` and that the call leaves out or sets to
`null` is judged as `None`, and runs as `None`: it is written into the call when a wrapper
on the way declares another default for it. A decorator whose own code fills or changes an
argument (`kwargs.setdefault(...)`) is the tool's code, which no gate reads. A value that
does not validate against its type (`"abc"` for an `int`) is refused, naming the parameter.
When a `None` has to be written into the call (a wrapper declares another default) and the
ADK's `FUNCTION_TOOL_ARG_VALIDATION` is on, a parameter not declared `Optional` is refused,
since the ADK would refuse the `None`. A wrapper with its own default over a
`pydantic.validate_call` function that rejects `None` fails the call; nothing runs.

For an app whose agents you do not build yourself, `RecusalPlugin(policy)` is the same
gate as a runner plugin, given to the app:
`InMemoryRunner(app=App(name="shop", root_agent=agent, plugins=[RecusalPlugin(policy)]))`
(`from google.adk.apps import App`). Plugin
callbacks run before any agent's own, so the plugin judges a call only when nothing it
cannot see runs after it. If the executing agent has another before-tool callback, or a
later plugin overrides `before_tool_callback`, it refuses the call and names the fix. A
plugin is handed tool calls only, so before a run starts it checks every agent in the
tree, from the root (a continued session can start at a sub-agent and transfer anywhere),
with the same rules `gated_agent` applies, and refuses the whole run when one of them can
execute something no callback sees: a `code_executor`, a provider-side tool, a toolset, a
`task` or `single_turn` sub-agent, or an agent class it does not know. It also refuses a
run whose `RunConfig` sets `support_cfc`, which gives the agent the model provider's code
execution.

## Put every decision on the record

```python
from recusal.audit import AuditLog
from recusal_google_adk import audited_agent

log = AuditLog(path="decisions.jsonl")
agent = audited_agent(LlmAgent(name="assistant", model=model, tools=[run_sql]), policy, log)
```

`audited_plugin(policy, log)` is the plugin form. Each call a gate sees, allowed or
refused, is one hash-chained entry labeled `google_adk.before_tool_callback` with the
ADK's function call id and a SHA-256 fingerprint of the arguments (never the arguments).
If the log cannot be written the call is refused. Check the log with
`recusal audit verify decisions.jsonl`.

The audited forms are the plain ones with a recording passed in, so there is one decision
path.

## What the gate refuses, and what it does not see

- **`gated_agent` raises at construction** (and `is_gated` is `False`) for an agent that
  can run something the callback never sees: an agent with a `code_executor` (model-written
  code runs outside the tool path), an `LlmAgent` subclass, an agent class it does not know
  how to gate, and any tool that is not a function, a `FunctionTool` or a plain
  `AgentTool`. That includes the built-in tools the model provider runs on its own side
  (`google_search`, `url_context`, `VertexAiSearchTool` and the like), which never reach a
  callback, tools declared in `generate_content_config`, and toolsets (MCP, OpenAPI),
  whose tools it cannot judge. Two ADK tools that run locally are accepted:
  `preload_memory` (it only adds memory to the model request) and `load_artifacts`
  (whose calls the gate refuses, since it cannot judge them). An agent in `task` mode is
  refused: the gate cannot judge how it finishes its task.
- **`gated_agent` cannot see how you run the agent.** It is handed the agent, not the
  `RunConfig`: do not set `support_cfc`, which gives the agent the model provider's code
  execution. `RecusalPlugin` sees the run and refuses it.
- **Refused before the policy runs:** a `FunctionTool` whose class or object replaces any
  method on its run path (preparing, filtering, confirming or calling), or whose function
  was replaced after it was built; a signature that cannot be judged by name, including a
  `functools.wraps` wrapper that adds a parameter of its own or names one the function it
  wraps also takes; an unknown or missing
  parameter; arguments that do not validate, or that validating again would change.
- **A decorated tool whose wrappers cannot all be read.** Whether a tool's signature can
  be judged is the kernel's answer: its walk (`recusal.invocation`) reads every callable
  a call reaches, and refuses what it cannot follow to the end. The gate gives each of
  its refusals a reason of its own, which says what was found, why it is refused and
  what to write instead. Refused:
  - a decorator that holds a second wrapper of the function (in its closure, in a module
    global it names, or on the decorator object) and calls it, where the held wrapper has
    a parameter of its own, takes the tool's parameters in other places, takes the object
    of a method under another name than the function it wraps has for that place, or
    reaches the function through a single-dispatch function, a weak proxy or a cache
    named again;
  - a `functools.lru_cache` named again for another function, whose function cannot be
    told from what the cache refers to;
  - a `functools.singledispatch` function or `singledispatchmethod` on the way, with an
    implementation registered, or with nothing registered but its base (one can be
    registered between the check and the call);
  - a `functools.partialmethod` over a callable object or a class-based decorator;
  - a wrapper handed a bound argument (the object of a method, a positional argument of
    a `functools.partial`) that takes it under another name than the function it wraps
    has for that place: its signature does not show whether it hands the argument on;
  - a declared signature, also where it matches the real parameters: a `__signature__`,
    a `__text_signature__` that is not the interpreter's own, or a callable object that
    shows a `__code__` and names nothing as `__wrapped__`;
  - a `weakref.proxy` anywhere on the way;
  - a callable that answers for `__wrapped__` without holding one (a class-based
    decorator that hands every attribute on with `__getattr__`), or that shows another
    class than its own and has a `__call__` of its own that takes a parameter by name;
  - a class-based decorator that is also a descriptor (its class defines `__get__`);
  - more wrappers than the walk reads;
  - a `functools.partial` as the tool, and a tool whose annotations
    `typing.get_type_hints` cannot resolve;
  - by a rule of this gate's own since 0.2.2, the one `recusal-pydantic-ai` has: a method
    whose decorator's wrapper takes the object in the place of the method's own and names
    the method's other parameters itself, where the values it names could move up a
    place and leave a parameter with a default to fill (`def wrapper(self, table,
    limit=10)` over `def purge(self, table: str, limit: int = 10)`). The kernel's walk
    reads it by design, and the ADK calls it by keyword, so its named parameters take the
    judged values: with `return fn(table, limit)` in its body, 0.2.2 as first prepared
    gated it, judged `{table: "t", limit: 5}`, and ran `self="t"`, `table=5`,
    `limit=10`. Refused also under `functools.wraps(fn)` written above a
    `functools.lru_cache` of that wrapper. Every name the wrapper takes after the object
    counts, a keyword-only one too (`def wrapper(self, *, account, amount=7, memo="m0")`
    over `def transfer(self, account: str, amount: int = 7, memo: str = "m0")`, whose body
    `return f(account, amount, memo)` ran `self="ACCT"`, `account=55`, `amount="MEMO"`
    as the review of 0029945 found), under an ordinary decorator, a cache, a
    `functools.partial` helper of the bound method or a free facade over it as well.
    Where that parameter has no default, the stack is read: no value can move into a
    place that would run at a default, and a wrapper that kept the object and handed
    every value on fails the call with a `TypeError`, so nothing runs (one whose body
    leaves a keyword out is under Open, below). Write the wrapper with `*args` and
    `**kwargs` after the object and hand them on with it (`def wrapper(self, *args,
    **kwargs): return fn(self, *args, **kwargs)`), which is read.
  - by the same rule, a method decorator that holds a second wrapper of the method and
    calls it with the object, where the held wrapper takes the object under the method's
    own name (`def inner(self, account, amount=7, memo="m0")`), whether the decorator's
    own wrapper is `outer(self, *args, **kwargs)` or a plain `outer(*args, **kwargs)`:
    the gate looks at what the callables on the way hold (their closures, the globals
    they name, a decorator object's attributes), and what each held `functools.wraps`
    wrapper holds and names in turn, and refuses a held `functools.wraps` wrapper that
    takes the object under the method's own name and names parameters after it, whatever
    it wraps. Not counted as held: what the walk itself stands on or steps through, such
    as the function a wrapper decorates, which the walk reads as its next level (a
    decorator stacked above a wrapper that restates the method's parameters is read, as
    that wrapper is alone); the
    walk of the method's function with the object unbound also refuses one under
    `outer(self, *args, **kwargs)` that takes only `*args` and `**kwargs` after it. Give
    the held wrapper `*args` and `**kwargs` alone, the object taken in `*args` with the
    rest (`def inner(*args, **kwargs)`), which is read.
  - by the rule `recusal-pydantic-ai` has for it: a wrapper that takes a parameter of the
    function under another kind than the function's (`def w(self, account, amount,
    memo="m0")` over `def transfer(self, account: str, amount: int, *, memo: str =
    "m0")`, where the count above leaves nothing empty: with `return f(account, amount,
    memo)` it ran `self="ACCT"`, `account=55`, `amount="MEMO"` as the confirmation review
    of b0384a1 found). Give the wrapper the function's parameters with the function's own
    kinds, or only `*args` and `**kwargs`.

  Read to the end, so that a wrapper with a parameter of its own is refused, naming the
  parameter, and one that only passes its arguments on is accepted: `functools.wraps`
  wrappers and `functools.lru_cache` applied directly, a decorator written as
  `functools.wraps(f)(functools.partial(helper, f))`, `@functools.wraps(f)` written above
  `@functools.lru_cache`, and a class-based decorator built with
  `functools.update_wrapper` (on a method, a class-based decorator with no `__get__` and
  a `functools.partial` do not bind the object, and its `self` is refused as not
  annotated). No reason advises calling the refused function from a plain
  function and registering that one: the gate reads a plain function's parameters and
  never its body, so the cause would run inside it as before.
- **How the ADK calls a tool, and what that means for a shifted call.** The ADK passes
  every argument by keyword: `FunctionTool.run_async` hands the prepared arguments to
  `_invoke_callable` (`google/adk/utils/_sync_runner.py` in `google-adk` 2.14.0), which
  calls `target(**kwargs)`. Where the kernel refuses a wrapper that may keep a bound
  argument because a call by keyword would then fail and a call by position would run
  each judged value one place off, a call the ADK makes would fail with a `TypeError`,
  and nothing would run: under the ADK such a tool, refused, either runs correctly or
  fails. Two reasons pass on the kernel's text for a bound argument, which can end with
  the advice to take the argument under the name the function has for it and hand it on
  by position. Where another wrapper on the way keeps the object (a method decorator that
  does not pass `self` on), the tool written that way is gated and does not run as
  judged: called by keyword, as the ADK calls it, it raises a `TypeError`, and called by
  position it runs every judged value one place off. Each reason says so before the
  kernel's text, and the gate's own advice comes first.
- **Agent tools:** a call to a plain `AgentTool` is judged as the sub-agent receives it
  (the `request` text, or the arguments as JSON), and only when the sub-agent's own tool
  calls are judged too: it is gated (`gated_agent` gates it), or it inherits
  `RecusalPlugin` (`include_plugins=True`, the default, with the plugin on the app).
  Otherwise the call is refused. An `AgentTool` whose agent declares an `input_schema`, an
  `AgentTool` subclass, and the tools ADK makes for sub-agents in `single_turn` or `task`
  mode are refused.
- **Not judged: an agent's answer.** The gate judges tool calls, not what an agent says.
  A structured answer (`output_schema`) is the agent's output either way it arrives: the
  `set_model_response` call the ADK adds when the agent has tools, which runs nothing and
  passes without the policy, or the final text, which no callback sees. Judge whatever
  acts on the answer (the next agent's tool calls are judged by their own gate).
- **Not judged:** the parameters the ADK fills itself, `tool_context` and `input_stream`.
  A call that sets either is refused; outside a live run an `input_stream` parameter takes
  its own default, which is the tool's code.
- **Not on the audit log:** a call another before-tool callback answered before the gate
  ran (the tool did not run either), and a `set_model_response` call, which is the agent's
  answer and passes without the policy.
- **Provider options on the model:** a model object that passes its provider an option
  turning on the provider's own tool, `LiteLlm(..., web_search_options=...)`, also when
  nested (`extra_body`), or an OpenRouter web plugin in its options, is refused, in a
  `FallbackModel` too. Other provider options and model names are configuration the gate
  does not read, and a model that searches on its own is the model's choice.

**Refused although it runs correctly.** The kernel's walk reads parameters and not
bodies, so it refuses some signatures a correct tool can have. Each of these runs
correctly under the ADK, which calls it by keyword; 0.2.1 beside `recusal` 0.15.1 gated
each, and beside `recusal` 0.17.1 each is refused, before the policy is asked and
before anything runs. Each was run through this gate, and so was each remedy below.

- New with `recusal` 0.16.0:
  - A `__text_signature__` that matches the parameters. Delete it.
  - A decorator written as `functools.wraps(g)(functools.partial(helper, g))` over
    `g = Binding(f)`, where `Binding` is a class-based decorator whose class defines
    `__get__`: the walk follows the `__wrapped__` the partial carries and refuses the
    descriptor. Give `Binding` no `__get__`
    and call `functools.update_wrapper(self, fn)` in its `__init__`.
  - A class-based decorator that keeps the function in an attribute and answers every
    other attribute from it with `__getattr__`, over a plain function, which then shows
    its `__code__`. Call `functools.update_wrapper(self, fn)` in its `__init__`.
  - A facade method that passes a value of its own in the place of the first parameter
    of the function it wraps (`return search("acme", *args, **kwargs)` over
    `def search(tenant: str = "main", sql: str = "", limit: int = 10)`), where that
    parameter has a default. Give the agent the function itself, or write the method out,
    its parameters passed on to the function by keyword.
  - A class method whose function is a cache named again for a cache of it
    (`functools.update_wrapper(functools.lru_cache(...)(lambda *a, **k: cached(*a,
    **k)), cached)`), under a decorator written as
    `functools.wraps(f)(functools.partial(helper, f))`: the walk reports `cls` as a
    parameter the tool does not declare, as it does for the same class method without the
    partial, which 0.2.1 refused too. Cache the function once, without the cache that is
    named again.
- New with `recusal` 0.17.0:
  - A `weakref.proxy` of a plain function under a decorator that hands its arguments on.
    Put the function in the proxy's place.
  - A single-dispatch method that nothing is ever registered on (the object goes in by
    position, so the call dispatches; a bare single-dispatch function called by keyword,
    as the ADK calls a tool, fails). Make the method the base function itself.
  - A class-based decorator that answers every other attribute with `__getattr__`, over
    a function that names a `__wrapped__` (any `functools.wraps` decorator, any
    `functools.lru_cache`). Call `functools.update_wrapper(self, fn)` in its `__init__`.
  - A decorator that holds a `weakref.proxy` of a helper. Hold the helper itself.
  - A decorator that holds a wrapper which takes the tool's parameters in another order
    and hands them on by keyword: the ADK's call by keyword reaches each by name. Give the
    held wrapper the tool's parameters in the tool's order, or as keyword-only ones.
- New with `recusal` 0.17.1:
  - A method decorator that takes the object under another name than the method has for
    it and hands it on (`def wrapper(this, *args, **kwargs): return m(this, *args,
    **kwargs)` over `def run_sql(self, ...)`). Take the object under the name the method
    has for it (`self`, or `cls` for a class method) and hand it on by position.
  - A held `functools.wraps` wrapper that does the same (`def forward(receiver, *args,
    **kwargs): return run(receiver, *args, **kwargs)` over `def run(self, ...)`, called
    by a pass-through). Take the object in `*args` with the rest.
  - A held helper whose chain of `__wrapped__` comes back on itself
    (`helper.__wrapped__ = helper`). Name the function it wraps, once.
  - The same facade as under 0.16.0 where that parameter has no default
    (`def search(tenant: str, limit: int = 10)`). Give the agent the function itself, or
    write the method out.

  Refused too, and changing nothing that runs, since the ADK's call fails there either
  way: such a wrapper that drops the object where the place it leaves has no default
  (`def method(self, *args, **kwargs): return execute(*args, **kwargs)` over
  `def execute(database: str, ...)`, and a held `def forward(receiver, *args, **kwargs):
  return run(*args, **kwargs)`). 0.2.1 beside `recusal` 0.17.0 gated both, and the call
  raised `TypeError`. The kernel's entries for 0.16.0, 0.17.0 and 0.17.1 in the
  changelog have the whole lists for its walk.
- New in 0.2.2, by a rule of this gate's own (above):
  - A method decorator whose wrapper takes the object as `self` and names the method's
    parameters itself, and hands the object on (`def wrapper(self, table, limit=10):
    return fn(self, table, limit)`), over a method with a positional parameter that has a
    default. Write the wrapper with `*args` and `**kwargs` after the object and hand them
    on with it.
  - The same wrapper with the method's parameters as keyword-only ones (`def
    wrapper(self, *, account, amount=7, memo="m0"): return f(self, account, amount,
    memo)`): its signature is that of the one that drops the object. The same remedy.
  - A method decorator that holds a second wrapper of the method and calls it with the
    object, where the held wrapper takes the object as `self` and hands it on: one that
    names the method's parameters, under `outer(self, *args, **kwargs)` or a plain
    `outer(*args, **kwargs)`, and one that takes only `*args` and `**kwargs` after it,
    under `outer(self, *args, **kwargs)`. Give the held wrapper `*args` and `**kwargs`
    alone (`def inner(*args, **kwargs): return fn(*args, **kwargs)`).
  - A wrapper that takes a parameter of the function under another kind than the
    function's and hands it on correctly (`def w(sql="", *, limit=10): return fetch(sql,
    limit)` over `def fetch(sql: str = "", limit: int = 10)`). Give it the function's own
    kinds.
  - A method decorator whose body merely names a module-level `functools.wraps` function
    that takes the object's name and a parameter (`if False: audit_note(self, "x")` in
    `def logged(self, *args, **kwargs)`, where `audit_note = functools.wraps(note)(...)`
    takes `(self, note)`), though it never calls it: the look at what a wrapper holds
    counts every held `functools.wraps` wrapper that takes the object's name, whatever it
    wraps. Name the helper's first parameter otherwise (`def audit_note(obj, note)`), or
    keep it out of the decorator's body.
  - A method decorator that holds, or whose code names, more than 512 callables: the
    look at what it holds stops there, and a tool it could not read to the end is
    refused, whatever it holds. Keep the decorator's own code to the wrappers it calls.

**Open**, stated so you can judge them. A test named `test_open_` holds each.

- **A method decorator that forgets to pass the object on.**
  `@functools.wraps(m) def method(self, *args, **kwargs): return m(*args, **kwargs)` over
  `def run_sql(self, sql: str, force: bool = False)`, and the same where the decorator
  takes the object in `*args` (`return m(*args[1:], **kwargs)`) or over a class method's
  `cls`. It is gated, and the policy judges the call; the ADK calls it by keyword, so the
  method is missing its object, the call raises a `TypeError`, and none of it runs.
  Called by position, as other frameworks call a tool, it would run every judged value
  one place off. From the signature nothing tells it from the ordinary decorated method,
  which the kernel's entry for 0.17.1 states under "Still read, by design". Pass `self` on
  in the decorator.
- **The same, where the place the object leaves has a default.** A facade that drops its
  object in `*args` over `def execute(database: str = "main", sql: str = "SELECT 1",
  note: str = "")` is gated, and called by keyword `database` runs at its default, which
  no policy judged; the judged values run in their places. Hand the object on, or give
  the agent the function itself.
- **A method wrapper that names the method's parameters with the method's own kinds and
  drops the object, where no value can move into a place with a default**: every name is
  keyword-only (`def w(self, *, account, amount=7)` over `def transfer(self, *, account:
  str, amount: int = 7)`), or the last positional place the values could leave has no
  default. Read. A body that hands every value on fails the ADK's call with a
  `TypeError`, and nothing runs. A body that leaves a keyword out runs the function's
  default for it, which no policy judged: over `def transfer(self, account: str, *,
  amount: int = 7, memo: str = "m0")`, `def w(self, account, *, amount=7, memo="m0"):
  return f(account, amount)` was gated, judged `{account: "ACCT", amount: 55, memo:
  "MEMO"}`, and ran `self="ACCT"`, `account=55`, `amount=7`, `memo="m0"`. That is the
  decorator's own code, as below.
- **A held wrapper without `functools.wraps` that takes the object under another name and
  drops it** (`def forward(receiver, *args, **kwargs): return run(*args, **kwargs)`,
  called by a `functools.wraps` pass-through): the kernel reads it by design, since every
  correct held wrapper written without `functools.wraps` has the same shape. It is gated,
  and the ADK's call raises a `TypeError`. The same with `functools.wraps` is refused.
- **A wrapper whose body hands the values on in other places than its signature names
  them.** Over a plain function, `@functools.wraps(fn) def wrapper(database, sql="SELECT
  1"): return fn(sql)` names the function's parameters and is read; the ADK's call by
  keyword gives each judged value to the wrapper by name, and its body runs
  `fn(database="Q")` for judged `{database: "D", sql: "Q"}`. This is the decorator's own
  code, which no gate reads, as `kwargs.setdefault(...)` is (above); on a method, where
  the place moved out of is the object's, the rule above refuses it.
- **A held wrapper the kernel's walk does not find.** One that names nothing as
  `__wrapped__`, and one a `functools.partial` binds as an argument under a
  `functools.wraps` of the function (`functools.wraps(f)(functools.partial(helper,
  wrapper))`), each with a parameter of its own, run that parameter at its default, which
  no policy judged. The kernel's entry for 0.17.0 lists the other held wrappers its walk
  does not find (one built on first use, one in a slot, a container, a settings object or
  a function's own attribute, one behind a `weakref.ref`).

**Beyond the gate.** This gate judges the tool calls the framework routes through it;
the paths around it inside the framework are listed above. Like every Recusal gate, it
does not stop an agent that can reach a resource another way: a credential with wider
rights, a shell or network path outside the agent, or a file it can write that
configures the gate. Use it as one layer of several: least-privilege credentials for the
agent, a sandbox or container, limits on its network egress, and an audit anchor the
writer cannot reach ([the limits in
full](https://github.com/philpaz/recusal/blob/main/SECURITY.md#things-worth-knowing)).

## Status

**In-depth review complete.** Its fixes are released in 0.2.2. Recusal is a Beta (`0.x`) open-source project in active
development: it is not a finished or certified security product, and it is provided under
Apache-2.0 without warranty.
[What the reviews are, and where every adapter stands](https://github.com/philpaz/recusal#project-status).

**What 0.2.2 changes.** It requires `recusal` 0.17.1 (0.2.1 allowed 0.15.0), and adds rules
of the gate's own, for a method decorator that names the method's parameters and may drop
the object, held or not, and for a wrapper that takes a parameter under another kind than
the function's (above). Beside `recusal` 0.15.1, 0.2.1 gated decorated tools that then
ran a value no policy judged: a decorator that holds a second wrapper with a parameter of
its own, and a wrapper with a parameter of its own under a
`functools.wraps(f)(functools.partial(helper, f))` decorator or under a
`functools.lru_cache` named again for the function, among others; the walks of
0.16.0 to 0.17.1 refuse each, and the list above says what they refuse that runs
correctly. Every refusal of that walk has a reason of its own, which says what was found,
why it is refused and what to write instead, where 0.2.1 passed on the kernel's text, or
"its signature cannot be inspected". No reason advises calling the refused function from
a plain function, which the gate reads by its parameters alone.

**Help make it better.** Read the code, test this adapter against your own stack and tell
us what you find. Reviews, bug reports and pull requests are all welcome:
[how to contribute](https://github.com/philpaz/recusal/blob/main/CONTRIBUTING.md), [open issues](https://github.com/philpaz/recusal/issues).
Please report a security gap [privately](https://github.com/philpaz/recusal/security/advisories/new), not in a public
issue.

## Compatibility

This package is outside the kernel's frozen perimeter (`STABILITY.md`, Integrations). Its
public names are the ones in `recusal_google_adk.__all__`. When an ADK release changes
what the callback is handed, this package gets a release and the kernel does not.

A runnable offline demonstration, with a scripted model and no API key, is
[`examples/google_adk_gate.py`](https://github.com/philpaz/recusal/blob/main/examples/google_adk_gate.py)
and
[`examples/google_adk_audit.py`](https://github.com/philpaz/recusal/blob/main/examples/google_adk_audit.py).

## More

<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/philpaz/recusal/main/assets/adapter-map.svg">
    <img alt="One kernel, eight adapters. Each adapter package depends on recusal: recusal-crewai, recusal-google-adk, recusal-langchain, recusal-langgraph, recusal-openai, recusal-openai-agents, recusal-openai-agents-mcp and recusal-pydantic-ai. recusal-langchain also depends on recusal-langgraph, and recusal-openai-agents-mcp on recusal-openai-agents. The kernel depends on nothing." src="https://raw.githubusercontent.com/philpaz/recusal/main/assets/adapter-map-light.svg" width="880">
  </picture>
</p>

An arrow means "depends on". No arrow leaves the kernel, so a framework's breaking
change is answered by a release of that framework's adapter, not by a release of the
kernel.

- [Framework notes for Google ADK](https://github.com/philpaz/recusal/blob/main/docs/FRAMEWORKS.md#google-adk):
  the detail behind this page.
- [All eight adapter packages](https://github.com/philpaz/recusal/tree/main/adapters) and
  [the kernel](https://github.com/philpaz/recusal), which has zero runtime dependencies.
- [Verifying a release](https://github.com/philpaz/recusal/blob/main/docs/VERIFY.md#adapter-packages):
  each release is built in CI, signed with Sigstore and published to PyPI by trusted
  publishing.
- [Changelog](https://github.com/philpaz/recusal/blob/main/CHANGELOG.md),
  [issues](https://github.com/philpaz/recusal/issues),
  [security policy](https://github.com/philpaz/recusal/blob/main/SECURITY.md) and
  [support](https://github.com/philpaz/recusal/blob/main/SUPPORT.md).

Licensed under Apache-2.0.
