Agent Action Gateway
Let AI agents change real systems safely. You control what they can do, and you can prove what they did.
1. Overview
AI agents call tools that change real systems: they delete tables, deploy code, restart services. Called directly, there is no control (a wrong or prompt-injected agent still acts) and no proof (no record of what it tried, what ran, and what was refused).
This package puts a checkpoint between the agent and those tools. The agent decides what to do. The checkpoint decides if it runs, and records it either way.
2. Key features
| Problem | What the checkpoint does | |
|---|---|---|
| Control | A risky action runs unseen | It waits until a person approves that exact action. The approval works once. |
| The agent acts in the wrong environment | A prod tool is refused from a dev or staging session. |
|
| A retry repeats the action | The same action does not run twice, even after a crash. | |
| The agent loops or runs too long | Limits on steps, time and cost stop the run. | |
| The agent holds the real API key | With the gateway, it never sees the key. | |
| Prove | No record of what happened | Every checked action is recorded, with secrets hidden. A dashboard shows it, and is where a person approves, settles held actions and accepts changed tools. |
| A reviewer approves without seeing why | Each approval carries what the agent read before asking, taken by the gateway and frozen with SHA-256, kept apart from the agent's own words. | |
| A new version may be less safe | A release gate tests it on your cases and fails if it got worse. |
Smaller features (stop and ask for a missing value, risk decided per call for
tools like execute_sql, tool pinning, the bypass scanner) are explained in the
SDK guide, the gateway guide and the
evaluation guide.
3. Technology stack
- Python 3.11+, standard library only. No required dependencies in a safety tool.
- SQLite by default, PostgreSQL optional: approvals and records survive a crash.
- MCP (stdio and Streamable HTTP) and HTTP, written without an SDK (why: section 8).
- pytest, ruff, mypy in CI on Python 3.11 to 3.13.
4. Core concepts
- Risk class:
read,writeordestructive. Anything undeclared is destructive. Everything exceptreadneeds an approval. - Exact approval: bound to the action and its arguments, used once, expires after 15 minutes.
- Waiting for approval vs held: an action waiting for approval was blocked and has not run; a person approves or denies it. A held action was approved and sent, then got no answer (a timeout), so nobody knows if it happened. It is not run again until a person checks the real system and settles it.
- Collected evidence: the read results the agent got through the checkpoint before asking are frozen onto the approval, not written by the model. It is a copy of what the tools returned, not proof that it is true (details and limits).
- Effect claim: recorded before the action runs, keyed on what the action is. A retry finds it and gets the first result instead of acting again (details).
- Pinning: the MCP proxy saves each tool's definition; a changed tool is hidden until a person accepts it.
- Virtual key: the gateway holds the real key; the agent gets a key that only works for its allowed routes.
5. Architecture
How it works, in four steps:
- The agent asks. Every tool call goes to the checkpoint (the library in Python, or the MCP proxy). The agent cannot reach your tools, the real keys or the records any other way.
- The checkpoint checks. Limits, environment, and for anything that is not a read, an approval from a person for that exact call.
- It runs once. The action is claimed before it runs, so a retry or crash never runs it twice. With the gateway, the real key is added there and the agent never sees it.
- Everything is recorded. A person sees it in the dashboard, approves calls, settles actions with no clear result, and accepts changed tools.
flowchart LR
A["1. Your agent<br/>asks to run a tool"] --> C
subgraph C["2. Checkpoint: library or MCP proxy"]
direction TB
K["Check limits<br/>and environment"] --> AP{"Not a read:<br/>approved by<br/>a person?"}
end
AP -->|no: blocked,<br/>approval requested| P
AP -->|yes| O["3. Run once<br/>(claimed first,<br/>never twice)"]
O --> T[Your tools /<br/>MCP servers]
O --> G["Gateway<br/>adds the real key"]
G --> API[Real APIs]
C --> R[("4. Records<br/>secrets hidden")]
O --> R
R --> P["Person<br/>dashboard"]
P -->|approves; agent<br/>tries again| A
Show every part and step
flowchart TD
subgraph AG["Agent side"]
A["Your agent<br/>(proposes an action)"]
end
subgraph CP["Checkpoint: the only way in"]
LIB["Library: session() / ctx.tool<br/>(Python functions)"]
PX["MCP proxy<br/>(stdio, or HTTP with a token)"]
PIN{"0. Tool definition<br/>same as pinned?"}
S1["1. Decide the risk<br/>read / write / destructive<br/>(undeclared = destructive)"]
S2{"2. Within limits?<br/>steps, time, cost, loops"}
S3{"3. Right environment?"}
S4{"4. Not a read:<br/>exact approval?<br/>(same action and arguments,<br/>unused, under 15 min)"}
S5{"5. Claim the effect:<br/>claimed before?"}
RUN["6. Run it, with the intent key"]
OUT{"Result?"}
end
subgraph TL["Your systems"]
T["Your tools / MCP servers"]
GW["Gateway<br/>virtual key in, real key out;<br/>routes, hosts, private-address check"]
API["Real APIs"]
end
subgraph ST["Records (SQLite or PostgreSQL)"]
APR[("Approvals")]
RCP[("Receipts<br/>pending / done / failed / resolved")]
TR[("Run records<br/>secrets hidden")]
PN[("Pinned tools")]
end
subgraph HU["Person"]
D["Dashboard<br/>approve or deny, settle held actions,<br/>accept changed tools, see runs<br/>(settle and accept also by CLI)"]
end
A -->|Python call| LIB
A -->|MCP call| PX
PX --> PIN
PIN -->|changed: hidden until accepted| PN
PIN -->|same| S1
LIB --> S1
S1 --> S2
S2 -->|no| BLK["Blocked, with the reason"]
S2 -->|yes| S3
S3 -->|no| BLK
S3 -->|yes| S4
S4 -->|no| REQ["Blocked: approval requested<br/>(agent gets an approval id)"]
REQ --> APR
S4 -->|yes, now used up| S5
S5 -->|done before| PREV["Return the first result<br/>(not run again)"]
S5 -->|pending: may have landed| HELD["Held: not run again"]
S5 -->|new, or failed before| RUN
RUN --> T
RUN --> GW
GW --> API
RUN --> OUT
OUT -->|ok| OK["Mark done, return the result"]
OUT -->|clear error| FAIL["Mark failed<br/>(safe to try again)"]
OUT -->|timeout or no answer| HELD
OK --> RCP
FAIL --> RCP
HELD --> RCP
BLK --> TR
REQ --> TR
OK --> TR
PREV --> TR
APR --> D
RCP --> D
TR --> D
PN --> D
D -->|approve| APR
D -->|settle: landed or not| RCP
D -->|accept| PN
REQ -.->|agent retries with the approval id| A
| Part | Use it when your agent calls | Checks | Guide |
|---|---|---|---|
Library (session()) |
Python functions | everything in section 6 | SDK guide |
MCP proxy (agent-gateway mcp-proxy) |
MCP tools, started as a command or reached by URL (--http) |
everything in section 6, plus pinning | MCP proxy |
Gateway (agent-gateway gateway) |
HTTP APIs, key kept from the agent | routes, environment, key custody, approval (off when the route file holds keys); no limits or effect claim of its own | gateway guide |
For full checks and key custody, put the gateway behind the proxy (how). Package layout: architecture.
6. Execution flow
Every call goes through enforce() in this order. Nothing reaches the tool until
all checks pass, and every outcome is recorded.
flowchart TD
I{"Required inputs given?"} -->|no| Q[Stop and ask]
I -->|yes| K["Decide the risk<br/>(undeclared = destructive)"]
K --> L{"Within limits?"}
L -->|yes| E{"Right environment?"}
E -->|yes| P{"Not a read: exact approval?"}
P -->|yes| O{"Claimed before?"}
O -->|no, or failed before| R[Run it]
O -->|done| D[Return the earlier result]
O -->|pending| H[Held until a person settles it]
R -->|timeout or no answer| H
L -->|no| B[Block, with the reason]
E -->|no| B
P -->|no| A[Block, and request an approval]
R --> REC[(Record)]
D --> REC
H --> REC
B --> REC
A --> REC
When something goes wrong:
- Unknown result: a timeout, a dropped connection, a 5xx or a crash mid-call
may have landed, so the action is held and never repeated silently; settle it
with
agent-gateway receipts. A failure that proves nothing happened (a refused connection, a 4xx) may be retried, with the same intent key (details). - Dead MCP server: restarted (at most 3 times a minute), tools re-checked against the pins. A broken config edit keeps the last good config.
The approval loop and the held path, step by step: architecture.
7. Implementation
| Feature | Main files |
|---|---|
| Check pipeline | engine/enforcement.py |
| Sessions, wrapped tools, stop-and-ask | runtime/session.py |
| Approvals, limits | policy/locks.py, policy/fuses.py |
| Effect claims | audit/receipts.py, policy/fingerprint.py |
| MCP proxy, per-call risk | integrations/mcp_proxy.py, guards/sql.py |
| Gateway, key custody | integrations/gateway.py, credential/ |
| Redaction | guards/redaction.py |
Wrap a tool and give the agent the wrapped version:
from agent_action_gateway import session
def drop_table(table: str, intent_key: str = "") -> dict:
# Your real code. Pass `intent_key` to your provider as an idempotency key.
return {"dropped": table}
with session(environment="prod") as ctx:
drop = ctx.tool(drop_table, action="db.drop_table", risk="destructive")
drop(table="users") # blocked: needs approval
approval = ctx.request_approval("db.drop_table", {"table": "users"})
ctx.approve(approval.approval_id, "on-call engineer")
drop(table="orders", approval_id=approval.approval_id) # blocked: approval was for "users"
drop(table="users", approval_id=approval.approval_id) # allowed, and only once
Your agent is any function that takes the task and the tools:
result = ctx.run(agent, task, tools={"drop_table": drop})
result["status"] # "blocked" if any action was refused
More: SDK guide.
8. Technical decisions
| Decision | Why | Trade-off |
|---|---|---|
| Unknown means destructive | a forgotten tool must not run freely | new tools need a rule or an approval |
| Approval used once, for exact arguments | it cannot be reused for another action | a retry after a failure needs a new approval |
| Claim the effect before running | the only way to catch a repeat after a crash | needs a store that survives restarts |
| A proxy instead of changing MCP servers | works with servers you do not control | calls that skip the proxy are not checked |
| Keys in a separate gateway | an agent cannot leak a key it never had | one more service to run |
| MCP written without the SDK | no dependencies, full control in a security proxy; tested against the official SDK client | we follow MCP spec changes ourselves |
| Built-in release gate, not promptfoo or DeepEval | it reads the gateway's own records: blocked, approved and repeated actions | fewer features than those tools |
9. Limits and future work
- It checks actions, not reasoning, and cannot detect a guessed value.
- Only calls through the checkpoint are checked. An agent with a terminal can go around it unless it runs with no keys and no direct route to your systems (setups).
- It judges what is in the call. It cannot see what your tool does inside (for example, a database function that deletes rows).
- "Once" needs an idempotency key or a lookup from the provider.
- Evidence on an approval is the newest 10 reads that went through, not only the ones about this action. Reads made with an agent's own tools are not seen. There is no screen recording.
- Usage (tokens, cost) shows only if the agent reports it.
- Not independently audited. (full list)
Future work:
- Verified approvers: names are typed today. Sign-in through your own identity provider would tie each approval to a real person.
- Named agents on a shared proxy: agents on one proxy share a budget, a list of reads and the approvals today. Naming each agent would separate them (until then, run one proxy per agent). An agent would still be told apart only by its token (details).
- Evidence about this action only: keep the reads since the previous approval. It narrows the list but cannot be exact, because the gateway cannot tell which read led to which action.
- More clients tested (Claude Desktop, Cursor), usage hooks for more agents, and an independent security review.
10. Testing
- About 760 automated tests, plus lint and type checks, in CI.
make proof: 1,000 crashed retries cause 1 side effect; 0 destructive actions run without a valid approval.- Run with Claude Code in the demo: the MCP proxy, a real Postgres MCP server and the gateway, on test databases. Not yet run with Claude Desktop or Cursor. PostgreSQL tests need a test database.
11. Setup
There is no hosted version. Everything runs on your machines, and nothing is sent to us.
| Part | How it runs |
|---|---|
| Library | inside your agent's Python code; no server |
| MCP proxy | started by your MCP client (stdio), or as a service you run (--http) |
| Gateway | a server you run; it holds the real keys |
| Dashboard | a local web page (127.0.0.1); to share it, put it behind your own sign-in |
pip install agent-action-gateway
Or the Docker image (amd64 and arm64): docker pull ghcr.io/greyydaze/agent-action-gateway:0.4.0.
| To | Run |
|---|---|
| check MCP tool calls | agent-gateway mcp-proxy --config servers.json |
| run the proxy as its own service | agent-gateway mcp-proxy --config servers.json --http |
| run the key-holding gateway | agent-gateway gateway --config routes.json --db gateway.db |
| approve, settle held actions, accept tools, see runs | agent-gateway dashboard |
| settle actions held with an unknown outcome | agent-gateway receipts list |
| find calls that skip the checkpoint | agent-gateway check --app your_agent.py (--format json for CI) |
| test a new agent version | agent-gateway gate check --cases your-cases.json ... (guide) |
| show Claude Code's tokens and cost | add report_usage.mjs (in the repository, not the pip package) as a Stop hook; set AGENT_GATEWAY_USAGE_URL and AGENT_GATEWAY_PROXY_TOKEN |
Secrets come from environment variables: the upstream keys named in the route
file, the master key (the variable named by master_key_env in the route file),
AGENT_GATEWAY_DASHBOARD_TOKEN,
AGENT_GATEWAY_PROXY_TOKEN (proxy over HTTP), and ${NAME}
in the proxy config. Run the gateway and the proxy where the agent cannot read
their keys, config or approvals (separate user, container or host).
deploy/ has a Compose setup for each, and agent-gateway verify-boundary checks it from the agent's side; see the
gateway guide.
Develop: pip install -e ".[dev]", then make verify and make proof.
Documentation
| Guide | Read it for |
|---|---|
| SDK guide | the library, approvals, limits, stop-and-ask, the MCP proxy (rules, per-call risk, pinning, HTTP mode) |
| Gateway guide | holding keys, deployment setups, checking your deployment, known limitations |
| Receipt guarantees | exactly what "once only" means |
| Evaluation guide | the release gate, gate online, path, wall |
| Architecture | how the package is organized |
deploy/ |
Docker Compose for the gateway and the proxy, Kubernetes and systemd examples |
License
MIT
Metadata
Release files for agent-action-gateway 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| agent_action_gateway-0.4.0.tar.gz | 299.9 kB | Without provenance | Details for agent_action_gateway-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| agent_action_gateway-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for agent_action_gateway-0.4.0-py3-none-any.whl |
Total release size: 506.8 kB
Release files / agent_action_gateway-0.4.0.tar.gz
| Download URL | agent_action_gateway-0.4.0.tar.gz |
|---|---|
| Size | 299.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b6d227aeb636e8aa09ed3e881fcb2e24c209c627e57a6f26d6af2916c019c117
|
|
BLAKE2b-256 checksum How to use checksums |
913e6114a14d1b25a6cafb07006f7ef2a2b96419994a18ece1db7f5be6a584e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|
Release files / agent_action_gateway-0.4.0-py3-none-any.whl
| Download URL | agent_action_gateway-0.4.0-py3-none-any.whl |
|---|---|
| Size | 206.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2521a11247c2030b756c18a8e9fc7acd552e06556ff74389425bc0e9fe18aa39
|
|
BLAKE2b-256 checksum How to use checksums |
7d919b00baada9e34a1f7fbe544c75eb3a039d19504b862631113e6869341f90
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|
Security for agent-action-gateway 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.