Skip to content

Anmolnoor/agent-policy-gate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

agent-policy-gate

Small policy, review, and audit primitives for gating agent tool calls.

Four pieces:

  • PolicyGate — evaluates an action as allow, ask, or deny.
  • ReviewQueue — stores human review requests in memory or SQLite.
  • AuditLog — records append-only events in memory or JSONL.
  • @gated — wraps sync or async functions and enforces the policy before execution.

Install

pip install agent-policy-gate
# with FastAPI review router
pip install "agent-policy-gate[api]"

Quick start

from agent_policy_gate import AuditLog, PendingApproval, PolicyGate, ReviewQueue, gated

policy = PolicyGate.from_dict({
    "default": "allow",
    "actions": {
        "send_email": "ask",
        "delete_file": "deny",
    },
})
reviews = ReviewQueue("sqlite:///tmp/reviews.db")
audit = AuditLog("jsonl:///tmp/audit.jsonl")

@gated(policy=policy, reviews=reviews, audit=audit, action="send_email")
def send_email(to: str, subject: str, body: str) -> str:
    return f"sent email to {to}: {subject}"

try:
    send_email("alice@example.com", "Hi", "Hello")
except PendingApproval as exc:
    print(f"approve review {exc.review_id} first")

reviews.approve(exc.review_id, approver="operator")
send_email("alice@example.com", "Hi", "Hello", _policy_review_id=exc.review_id)

Review API

If you have FastAPI installed (pip install "agent-policy-gate[api]"):

from fastapi import FastAPI
from agent_policy_gate.api import create_review_router

app = FastAPI()
app.include_router(create_review_router(reviews))

Routes:

  • GET /reviews
  • GET /reviews/{review_id}
  • POST /reviews/{review_id}/approve
  • POST /reviews/{review_id}/deny

See docs/agent-policy-gate.md for the full reference and examples/ for runnable code.

Status

Alpha. API may change before 1.0. Carved out of Beekeeper as a standalone primitive.

License

Apache 2.0 — see LICENSE.

About

Small policy, review, and audit primitives for gating agent tool calls. Carved out of Beekeeper.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages