Matimo AGDK
Matimo Agent Governance Development Kit. Govern any agent in three lines:
from matimo_agdk import Governor
governor = Governor.from_env()
governor.start()
with governor.run("my-run"):
result = governor.guard(my_tool_fn, name="search")(query="roaiq")
Matimo AGDK is the Python SDK half of Matimo Gateway (the other half is a
zero-code LLM proxy any HTTP client can point at directly, see the
base_url-swap section below). AGDK adds three things a proxy alone
cannot: a cryptographic agent identity signed locally, mandatory execution
telemetry so an unregistered or gone-quiet agent is provably absent (not
just unobserved), and a governed tool-call check-in with human-in-the-loop
support.
Install
Published on PyPI as matimo-agdk. Python 3.13 or newer is required.
pip install matimo-agdk
Framework adapters are optional extras -- see "Framework adapters" below
for what each one actually does:
pip install matimo-agdk[langchain]
pip install matimo-agdk[google-adk]
pip install matimo-agdk[crewai]
pip install matimo-agdk[autogen]
pip install matimo-agdk[all]
The full guide, from getting an API key to operating an agent, is docs/USER-MANUAL.md.
Quickstart
-
Register the agent once (per machine, not per run) and get an org API
key from your Matimo Enterprise tenant admin:
export MATIMO_API_KEY=me-live-...
matimo-agdk register --name my-agent --framework custom
Registration asks Gateway to require a valid Matimo-Agent-Signature on
this agent's LLM calls (requireSignedRequests: true). Pass
--signed-requests optional to turn that off, or
--signed-requests tenant-default to omit the field and let the tenant
default apply. This needs a Gateway release that supports the field. No
released Gateway supports it yet: the default gets a 400 and nothing is
registered, so against a released Gateway use tenant-default.
gateway_chat_model(provider="anthropic"), the async methods of
gateway_chat_model(provider="openai"), and clients built from
*_client_kwargs() alone do not sign LLM calls, so register agents that
use them with optional.
This writes ~/.matimo/agents/my-agent.json (identity metadata) and
~/.matimo/agents/my-agent.pem (the private key, 0600 on POSIX). The
private key is returned by the server exactly once, at registration --
there is no way to retrieve it again. Losing it means registering fresh,
or rotating the key if you still hold the identity and the org API key
(matimo-agdk rotate-key --name my-agent). register refuses to run
again for a name that already has credentials (a second registration
would create a second identity and destroy the first one's key); pass
--force only when you really mean to replace them.
-
Build a Governor from the persisted credentials:
from matimo_agdk import Governor
governor = Governor.from_env(agent_name="my-agent")
governor.start() # starts the background telemetry/heartbeat exporter
-
Wrap the tools you want governed, and record LLM/tool activity inside a
run:
def search(query: str) -> str: ...
with governor.run("answer-a-question"):
result = governor.guard(search, name="search", category="web")(query="roaiq")
governor.llm_span(model="gpt-4o-mini", duration_ms=812)
-
Point your LLM client at Gateway instead of the real provider. Two
ways, depending on whether you need per-request signing:
import openai
# Quick: attaches the session token once, when the client is built. It is
# not refreshed (a session lasts one hour by default) and nothing is
# signed, so it stops working when the session expires, and it never works
# for an identity whose tenant enforces requireSignedRequests. Fine for a
# short script; not for a long-running agent.
client = openai.OpenAI(**governor.openai_client_kwargs())
# Recommended: attaches a live session token and signs every request, and
# transparently re-handshakes if the session expires mid-run. Signing costs
# nothing when the tenant does not enforce it.
client = openai.OpenAI(
base_url=governor.config.base_url,
api_key=governor.config.api_key,
http_client=governor.httpx_client(),
)
For Anthropic, use governor.anthropic_http_client() instead of
httpx_client(): anthropic 1.6 and newer are built on httpx2 and reject
an httpx.Client. The helper returns whichever client the installed
release accepts (pip install httpx2 if it is missing).
default_headers= alone cannot carry a per-request signature: the
signature covers the exact bytes of each request's own body, which is
only known once that specific request is being sent. governor.httpx_client()
solves this with a request event hook that computes and attaches a fresh
Matimo-Agent-Signature per call.
-
Async code uses the same shape with AsyncGovernor and await:
from matimo_agdk import AsyncGovernor
governor = await AsyncGovernor.from_env(agent_name="my-agent").start()
async with governor.run("answer-a-question"):
result = await governor.guard(async_search, name="search")(query="roaiq")
Framework adapters
Every adapter supports mode="observe" (telemetry only, never blocks) and
mode="govern" (default: also enforces DENY/PENDING and rapid suspend).
Each has one obvious registration point, but which piece actually
enforces a DENY differs by framework -- read each module's own docstring
before assuming attaching a callback/plugin alone is enough.
| Framework |
Register once |
LLM through Gateway |
Enforcement point |
Signing on LLM calls |
Verified against |
| LangChain |
MatimoCallbackHandler/AsyncMatimoCallbackHandler (telemetry) + govern_tools() (enforcement) |
gateway_chat_model(provider="openai"\|"anthropic") |
govern_tools()'s wrapped _run/_arun -- the callback alone can only crash the chain, not deny gracefully (see the module docstring) |
Full (openai), session-header-only (anthropic) |
langchain-core 1.6.3, langchain-openai 1.6.2, langchain-anthropic 1.7.2 |
| Google ADK |
MatimoPlugin(governor) on Runner(plugins=[...]) |
gateway_model() (real openai SDK, no litellm) |
MatimoPlugin.before_tool_callback's dict short-circuit -- ADK's own documented graceful-DENY contract |
Full: live session token, run id, and per-request JWS via governor.httpx_async_client() |
google-adk 2.9.1, openai 2.54.0 |
| CrewAI |
govern_crew(crew_or_agents, governor) |
gateway_llm() |
The wrapped func of each @tool/Tool(func=...) (covers CrewAI's native tool calling), or the wrapped _run/_arun of any other BaseTool (0.1.0 wrapped only _run/_arun, see CHANGELOG 0.1.1) |
Full: live session token, run id, and per-request JWS via CrewAI's transport interceptor (verified live with requireSignedRequests=true) |
crewai 1.15.22 |
| AutoGen |
govern_tools(tools, governor) |
gateway_model_client() |
The wrapped run() on each BaseTool |
Full |
autogen-core/-agentchat/-ext 0.7.5 (modern generation only -- see below) |
| Any other framework |
govern(callable_or_tools, governor) |
build your own client with governor.openai_client_kwargs()/httpx_client() |
governor.guard() under the hood |
Depends on your client |
No framework dependency at all |
Sync vs. async governors. gateway_chat_model() (LangChain) and
gateway_llm() (CrewAI) build their clients synchronously, so they need a
sync Governor; passing an AsyncGovernor raises a TypeError that says
so. A sync Governor still serves async framework code (blocking calls are
moved to a thread). gateway_model_client() (AutoGen) and gateway_model()
(ADK) are the reverse: both need an AsyncGovernor, because their
underlying async client needs a live per-request signing hook only
AsyncGovernor.httpx_async_client() provides. LangChain's ChatOpenAI is
wired with the live sync client only, so its async methods (ainvoke) fall
back to a session header fixed at construction and are not signed.
"Session-header-only" means: the session token is attached, but there
is no per-request Matimo-Agent-Signature (nonce + body hash) the way
LangChain's OpenAI path, AutoGen, and ADK get, because the underlying
client (ChatAnthropic, CrewAI's LLM) doesn't expose a request-hook
mechanism this SDK can use. Each gateway_*/govern_* helper's own
docstring explains exactly why, verified by reading the installed package's
source, not assumed. If your tenant might ever enable
requireSignedRequests, prefer a path marked "Full" for that traffic.
AutoGen note: pyautogen (the legacy 0.2-style ConversableAgent/
register_function package name) ships an empty __init__.py as of
its latest release on PyPI (0.10.0) -- verified directly, not assumed. This
adapter targets the actively maintained autogen_core/autogen_agentchat/
autogen_ext generation instead. If you're on the legacy API (now under
the community ag2 package), wrap your registered functions with
matimo_agdk.adapters.generic.govern() directly -- it works with any
plain callable.
Spans and runs, by design. LangChain reports one tool span per call: when a
tool is wrapped by govern_tools() the wrapper is canonical (it sees the
decision) and the callback handler skips its own span for that call; a tool that
is not wrapped still gets the handler's span. A denied call's span is tied to
LangChain's run tree (its run and span ids) only when a Matimo callback handler
is attached, since that is what tells the wrapper which run it is inside. CrewAI
and AutoGen give the SDK no per-crew or per-chat id, so they cannot group a crew
or chat into one run on their own: wrap the call in governor.run() (or
async with governor.run()), which is the grouping mechanism. LangChain LLM
spans carry gen_ai.provider.name (openai, anthropic, google) derived from
the client class; an unknown class gives no provider.
See examples/{langchain,google_adk,crewai,autogen}_agent.py for a
runnable end-to-end demo of each, and each adapter module's own docstring
for the full detail this table compresses.
What AGDK does not do
- AGDK never executes your tools.
governor.guard() checks policy and
records telemetry around your own callable; the actual tool code always
runs in your process, on your infrastructure. A DENY simply means the
wrapped call never happens.
- AGDK never sees your real LLM provider credentials. Once registered,
your agent's LLM traffic goes through Matimo Gateway using Gateway's own
session token, not your OpenAI/Anthropic key. Gateway resolves the
actual BYOK provider credentials server-side.
- AGDK is not a zero-code option. If you don't need a cryptographic
identity, telemetry, or tool governance, you can point any OpenAI/
Anthropic-compatible client directly at Gateway's
base_url with just
an API key and skip AGDK entirely -- that "base_url swap" path is real
and supported, just without the identity/telemetry/tool-check layer
this SDK adds.
Rapid suspend: what it really means
An admin can flip an identity's lifecycle_status to suspended or
revoked, or trip an org-wide emergency stop. Two different things happen
next, on two different timescales:
-
The next call Gateway itself receives (LLM proxy or tool check) is
denied immediately, server-side, regardless of AGDK. Lifecycle status
is read fresh from the database on every such call, never from a stale
cache. This is real and immediate.
-
AGDK's own governor.state/is_suspended()/raise_if_suspended()/
on_suspend(callback) are updated by two paths: polling is the
guarantee, a push channel is the fast path.
- Polling (always on). They reflect the last telemetry heartbeat
response, which can lag the true server state by up to one heartbeat
interval (sized automatically from the server's reported staleness
window, clamped to 15s-5min, or set explicitly via
heartbeat_interval).
- Push (on by default, best-effort). A background consumer keeps
GET /v1/control/stream (Server-Sent Events) open and typically applies
a suspend, revoke or emergency-stop within about a second. A pushed
event only ever tightens local state; a relaxing event triggers an
immediate poll instead of being trusted. Check
governor.control_stream_status (connecting, connected, backoff,
unsupported, disabled). Disable with
GatewayConfig(control_stream_enabled=False) or MATIMO_CONTROL_STREAM=0.
An older Gateway without the route falls back to polling automatically.
Do not rely on the push channel for a hard bound: it can be down
(backoff/unsupported/disabled), and in that case the polling
interval above is the bound. This is why the product calls this "rapid
suspend," never "instant kill": a long-running loop that never calls
Gateway and never checks governor.state could keep running locally
for up to that interval, and a compromised or patched process can ignore
either signal. See docs/SERVER-CONTRACT.md sections 7.3 and 10.
When Gateway is unreachable
A tool check needs Gateway. What a tool call does when Gateway cannot answer at
all (a connection error, a timeout, a 5xx) is your choice, per agent: