Catalog PyPI
PACKAGE EXPLORERView in registry

agentpolicy

PyPI

Runtime policy enforcement for AI agent sessions

agentsaiguardrailspolicyruntimesecurity
Versions collected1
Direct dependencies3From release 0.1.1
Last observed20 Oct, 22:55 UTC

README

Version 0.1.1 documentation

AgentPolicy

Runtime policy enforcement for AI agent sessions.

AgentPolicy is an open-source Python SDK that puts explicit runtime rules around what an agent is allowed to do. It enforces budgets, tool access, network access, and approval gates in real time, with a structured audit trail for every decision.

One policy layer for agent behavior. Zero infrastructure to manage.


What is AgentPolicy?

Agents fail in non-deterministic ways:

  • they call the wrong tool
  • they hit the wrong domain
  • they exceed budget
  • they take an action that should require human review

AgentPolicy makes those decisions explicit and enforceable.

Each runtime action is evaluated as one of:

  • allow
  • deny
  • require_approval

Every decision is recorded with the action, the reason, and the matched policy rule.

Budget is treated as a first-class policy. AgentPolicy uses agentbudget under the hood for spend accounting and hard budget enforcement instead of rebuilding that layer.


Quickstart

Define policy once. Enforce it at runtime.

budget:
  max_spend: 5.00

tools:
  allow:
    - search_docs
    - read_file
    - send_email
  block:
    - delete_prod_db

network:
  allow:
    - docs.python.org
  block:
    - twitter.com

approval:
  require_for:
    - tool: send_email
    - cost_gt: 1.00
from agentpolicy import AgentPolicy, ApprovalRequired

policy = AgentPolicy.from_yaml("policy.yaml")

with policy.session() as session:
    session.check_tool("search_docs", cost=0.02)
    session.check_http("https://docs.python.org/3/", cost=0.01)

    try:
        session.check_tool("send_email")
    except ApprovalRequired:
        session.check_tool("send_email", approved=True)

print(session.report())

Python API

For full control, define policy directly in code.

from agentpolicy import AgentPolicy

policy = AgentPolicy(
    budget="$5.00",
    allowed_tools=["search_docs", "read_file"],
    blocked_domains=["twitter.com"],
    approval_rules=[
        {"tool": "send_email"},
        {"cost_gt": 1.00},
    ],
)

with policy.session() as session:
    session.check_tool("search_docs", cost=0.02)
    session.check_http("https://docs.python.org/3/", cost=0.01)

Install

pip install agentpolicy

Python 3.9+. Installs agentbudget as a dependency.

For local development:

python3 -m pip install -e .[dev]
bash scripts/run_tests.sh

Core API

ObjectDescription
AgentPolicy(...)Define the runtime policy envelope for an agent.
AgentPolicy.from_yaml(path)Load a declarative policy file.
AgentPolicy.from_dict(data)Build policy from a Python mapping.
policy.session()Create a new PolicySession.
session.check_tool(name, cost=...)Evaluate a tool execution.
session.check_http(url, cost=...)Evaluate an outbound HTTP request.
session.check_cost(cost, source=...)Evaluate a metered cost event such as an LLM call.
session.guard_tool(...)Decorate a tool with policy enforcement.
session.evaluate(action)Return a decision without enforcing it.
session.enforce(action)Record and enforce a decision.
session.report()Return the full structured audit report.

Policy Types

Budget Policy

policy = AgentPolicy(budget="$3.00")

Denies any action that would push the session over budget.

Tool Policy

policy = AgentPolicy(
    allowed_tools=["search_docs", "read_file"],
    blocked_tools=["delete_prod_db"],
)

Supports allowlists and explicit blocks.

Network Policy

policy = AgentPolicy(
    allowed_domains=["docs.python.org", "api.openai.com"],
    blocked_domains=["twitter.com", "facebook.com"],
)

Controls outbound HTTP access at the domain layer.

Approval Policy

policy = AgentPolicy(
    approval_rules=[
        {"tool": "send_email"},
        {"domain": "api.stripe.com"},
        {"cost_gt": 1.00},
    ]
)

Escalates sensitive actions to ApprovalRequired.


CLI

agentpolicy validate policy.yaml
agentpolicy explain policy.yaml
agentpolicy demo policy.yaml

The CLI is intentionally small:

  • validate checks that a policy file is structurally valid
  • explain prints a simple machine-readable summary
  • demo runs a sample session and prints the resulting report

Auditability

AgentPolicy is designed to be legible under pressure.

Each decision includes:

  • the action
  • the decision type
  • the exact reason
  • the matched approval rule when escalation happens

Reports also summarize:

  • decisions by type
  • decisions by action category
  • cost by action category
  • denied tools
  • denied domains
  • approval-required actions

Example Report

{
    "session_id": "pol_a1b2c3d4e5f6",
    "budget": 5.0,
    "spent": 0.03,
    "remaining": 4.97,
    "decision_summary": {
        "allow": 2,
        "deny": 1,
        "require_approval": 1,
        "by_action_type": {"tool": 2, "http": 2},
    },
    "cost_summary": {
        "by_action_type": {"tool": 0.02, "http": 0.01},
    },
    "policy_hits": {
        "denied_tools": [],
        "denied_domains": ["twitter.com"],
        "approval_required": ["send_email"],
    },
    "duration_seconds": 0.14,
    "decisions": [...],
}

Relationship to AgentBudget

agentbudget answers:

  • how much has this agent spent?
  • when should execution stop on cost?

agentpolicy answers:

  • what can this agent do?
  • what can it access?
  • what requires approval?

In practice, budget is one policy dimension inside a broader runtime control layer.

The stack is:

  • agentbudget for cost accounting and hard budget enforcement
  • agentpolicy for the broader runtime decision layer

Why it exists

Most agent tooling focuses on orchestration. AgentPolicy focuses on control.

It is a good fit for:

  • internal copilots
  • research agents
  • workflow automation
  • production agent backends

Philosophy

AgentPolicy is deliberately small.

It is not a dashboard. It is not a hosted compliance product. It is not an orchestration framework.

It is a runtime primitive for making agent behavior explicit and enforceable.


Status

Early, but real.

The first version covers the four policy types that matter most in practice:

  • spend
  • tools
  • network
  • approval

That is enough to protect a surprising amount of real agent behavior without adding operational complexity.

Downloads & popularity

2downloads
1-day window · source-reported counts20 Oct 2026
840
2026-07-23: 2 · observed 2026-10-21T11:33:38.8716839Z · period 2026-07-23–2026-07-232026-07-25: 2 · observed 2026-10-21T11:33:38.8716839Z · period 2026-07-25–2026-07-252026-07-27: 3 · observed 2026-10-21T11:33:38.8716839Z · period 2026-07-27–2026-07-272026-07-31: 2 · observed 2026-10-21T11:33:38.8716839Z · period 2026-07-31–2026-07-312026-08-02: 2 · observed 2026-10-21T11:33:38.8716839Z · period 2026-08-02–2026-08-022026-08-04: 3 · observed 2026-10-21T11:33:38.8716839Z · period 2026-08-04–2026-08-042026-08-08: 2 · observed 2026-10-21T11:33:38.8716839Z · period 2026-08-08–2026-08-082026-08-09: 2 · observed 2026-10-21T11:33:38.8716839Z · period 2026-08-09–2026-08-092026-08-11: 1 · observed 2026-10-21T11:33:38.8716839Z · period 2026-08-11–2026-08-112026-08-14: 2 · observed 2026-10-21T11:33:38.8716839Z · period 2026-08-14–2026-08-142026-08-15: 2 · observed 2026-10-21T11:33:38.8716839Z · period 2026-08-15–2026-08-152026-08-17: 2 · observed 2026-10-21T11:33:38.8716839Z · period 2026-08-17–2026-08-172026-08-18: 1 · observed 2026-10-21T11:33:38.8716839Z · period 2026-08-18–2026-08-182026-08-21: 1 · observed 2026-10-21T11:33:38.8716839Z · period 2026-08-21–2026-08-212026-08-23: 3 · observed 2026-10-21T11:33:38.8716839Z · period 2026-08-23–2026-08-232026-08-24: 5 · observed 2026-10-21T11:33:38.8716839Z · period 2026-08-24–2026-08-242026-08-25: 1 · observed 2026-10-21T11:33:38.8716839Z · period 2026-08-25–2026-08-252026-08-28: 1 · observed 2026-10-21T11:33:38.8716839Z · period 2026-08-28–2026-08-282026-08-31: 1 · observed 2026-10-21T11:33:38.8716839Z · period 2026-08-31–2026-08-312026-09-01: 1 · observed 2026-10-21T11:33:38.8716839Z · period 2026-09-01–2026-09-012026-09-07: 1 · observed 2026-10-21T11:33:38.8716839Z · period 2026-09-07–2026-09-072026-09-10: 1 · observed 2026-10-21T11:33:38.8716839Z · period 2026-09-10–2026-09-102026-09-14: 4 · observed 2026-10-21T11:33:38.8716839Z · period 2026-09-14–2026-09-142026-09-16: 1 · observed 2026-10-21T11:33:38.8716839Z · period 2026-09-16–2026-09-162026-09-17: 1 · observed 2026-10-21T11:33:38.8716839Z · period 2026-09-17–2026-09-172026-09-19: 2 · observed 2026-10-21T11:33:38.8716839Z · period 2026-09-19–2026-09-192026-09-20: 5 · observed 2026-10-21T11:33:38.8716839Z · period 2026-09-20–2026-09-202026-09-21: 1 · observed 2026-10-21T11:33:38.8716839Z · period 2026-09-21–2026-09-212026-09-22: 1 · observed 2026-10-21T11:33:38.8716839Z · period 2026-09-22–2026-09-222026-09-23: 1 · observed 2026-10-21T11:33:38.8716839Z · period 2026-09-23–2026-09-232026-09-26: 1 · observed 2026-10-21T11:33:38.8716839Z · period 2026-09-26–2026-09-262026-09-27: 2 · observed 2026-10-21T11:33:38.8716839Z · period 2026-09-27–2026-09-272026-09-29: 2 · observed 2026-10-21T11:33:38.8716839Z · period 2026-09-29–2026-09-292026-09-30: 5 · observed 2026-10-21T11:33:38.8716839Z · period 2026-09-30–2026-09-302026-10-02: 1 · observed 2026-10-21T11:33:38.8716839Z · period 2026-10-02–2026-10-022026-10-06: 3 · observed 2026-10-21T11:33:38.8716839Z · period 2026-10-06–2026-10-062026-10-08: 1 · observed 2026-10-21T11:33:38.8716839Z · period 2026-10-08–2026-10-082026-10-09: 2 · observed 2026-10-21T11:33:38.8716839Z · period 2026-10-09–2026-10-092026-10-10: 2 · observed 2026-10-21T11:33:38.8716839Z · period 2026-10-10–2026-10-102026-10-12: 1 · observed 2026-10-21T11:33:38.8716839Z · period 2026-10-12–2026-10-122026-10-13: 1 · observed 2026-10-21T11:33:38.8716839Z · period 2026-10-13–2026-10-132026-10-14: 1 · observed 2026-10-21T11:33:38.8716839Z · period 2026-10-14–2026-10-142026-10-15: 5 · observed 2026-10-21T11:33:38.8716839Z · period 2026-10-15–2026-10-152026-10-16: 1 · observed 2026-10-21T11:33:38.8716839Z · period 2026-10-16–2026-10-162026-10-17: 8 · observed 2026-10-21T11:33:38.8716839Z · period 2026-10-17–2026-10-172026-10-18: 3 · observed 2026-10-21T11:33:38.8716839Z · period 2026-10-18–2026-10-182026-10-20: 2 · observed 2026-10-21T11:33:38.8716839Z · period 2026-10-20–2026-10-20
23 Jul20 Oct

pypistats · 47 observations shown. Missing days are unknown. Source category: overall: without mirrors.

View observed values
Date / source periodValueObserved at
2026-10-20 – 2026-10-2022026-10-21T11:33:38.8716839Z
2026-10-18 – 2026-10-1832026-10-21T11:33:38.8716839Z
2026-10-17 – 2026-10-1782026-10-21T11:33:38.8716839Z
2026-10-16 – 2026-10-1612026-10-21T11:33:38.8716839Z
2026-10-15 – 2026-10-1552026-10-21T11:33:38.8716839Z
2026-10-14 – 2026-10-1412026-10-21T11:33:38.8716839Z
2026-10-13 – 2026-10-1312026-10-21T11:33:38.8716839Z
2026-10-12 – 2026-10-1212026-10-21T11:33:38.8716839Z
2026-10-10 – 2026-10-1022026-10-21T11:33:38.8716839Z
2026-10-09 – 2026-10-0922026-10-21T11:33:38.8716839Z
2026-10-08 – 2026-10-0812026-10-21T11:33:38.8716839Z
2026-10-06 – 2026-10-0632026-10-21T11:33:38.8716839Z
2026-10-02 – 2026-10-0212026-10-21T11:33:38.8716839Z
2026-09-30 – 2026-09-3052026-10-21T11:33:38.8716839Z
2026-09-29 – 2026-09-2922026-10-21T11:33:38.8716839Z
2026-09-27 – 2026-09-2722026-10-21T11:33:38.8716839Z
2026-09-26 – 2026-09-2612026-10-21T11:33:38.8716839Z
2026-09-23 – 2026-09-2312026-10-21T11:33:38.8716839Z
2026-09-22 – 2026-09-2212026-10-21T11:33:38.8716839Z
2026-09-21 – 2026-09-2112026-10-21T11:33:38.8716839Z
2026-09-20 – 2026-09-2052026-10-21T11:33:38.8716839Z
2026-09-19 – 2026-09-1922026-10-21T11:33:38.8716839Z
2026-09-17 – 2026-09-1712026-10-21T11:33:38.8716839Z
2026-09-16 – 2026-09-1612026-10-21T11:33:38.8716839Z
2026-09-14 – 2026-09-1442026-10-21T11:33:38.8716839Z
2026-09-10 – 2026-09-1012026-10-21T11:33:38.8716839Z
2026-09-07 – 2026-09-0712026-10-21T11:33:38.8716839Z
2026-09-01 – 2026-09-0112026-10-21T11:33:38.8716839Z
2026-08-31 – 2026-08-3112026-10-21T11:33:38.8716839Z
2026-08-28 – 2026-08-2812026-10-21T11:33:38.8716839Z
2026-08-25 – 2026-08-2512026-10-21T11:33:38.8716839Z
2026-08-24 – 2026-08-2452026-10-21T11:33:38.8716839Z
2026-08-23 – 2026-08-2332026-10-21T11:33:38.8716839Z
2026-08-21 – 2026-08-2112026-10-21T11:33:38.8716839Z
2026-08-18 – 2026-08-1812026-10-21T11:33:38.8716839Z
2026-08-17 – 2026-08-1722026-10-21T11:33:38.8716839Z
2026-08-15 – 2026-08-1522026-10-21T11:33:38.8716839Z
2026-08-14 – 2026-08-1422026-10-21T11:33:38.8716839Z
2026-08-11 – 2026-08-1112026-10-21T11:33:38.8716839Z
2026-08-09 – 2026-08-0922026-10-21T11:33:38.8716839Z
2026-08-08 – 2026-08-0822026-10-21T11:33:38.8716839Z
2026-08-04 – 2026-08-0432026-10-21T11:33:38.8716839Z
2026-08-02 – 2026-08-0222026-10-21T11:33:38.8716839Z
2026-07-31 – 2026-07-3122026-10-21T11:33:38.8716839Z
2026-07-27 – 2026-07-2732026-10-21T11:33:38.8716839Z
2026-07-25 – 2026-07-2522026-10-21T11:33:38.8716839Z
2026-07-23 – 2026-07-2322026-10-21T11:33:38.8716839Z

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
0.1.125 Mar 20263

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 22:55 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:28df7508db196ba1a3809da7c329e76f8e6435c29bf9a6ab269b8f0adb098b07