Skip to main content

Runtime governance for AI agents — budget limits, loop protection, token limits, audit trail

Project description

Fences

Runtime governance for AI agents. Give any agent budget limits, loop protection, and a decision audit trail in three lines of code.

import fences
fences.init(local_only=True)

@fences.governed(budget_usd=0.50, max_iterations=20, max_duration_ms=60_000)
async def run_agent(query: str):
    response = call_llm(query)
    fences.log_decision(reasoning="searching for sources", action="web_search")
    await fences.checkpoint(cost_delta_usd=compute_cost(response))
    return response

If the agent exceeds its budget, loops past the iteration limit, or runs too long, checkpoint() raises and execution stops immediately.

Install

pip install fences

Quickstart — no backend needed

import fences
from fences import governed, checkpoint, log_decision
from fences import BudgetExceeded, IterationLimitReached

fences.init(local_only=True)

@governed(budget_usd=0.10, max_iterations=10)
async def my_agent(query: str):
    for step in range(100):
        log_decision(reasoning=f"step {step}: searching", action="search")
        await checkpoint(cost_delta_usd=0.01)
    return "done"

What gets enforced

Limit Parameter Raises
Spend budget_usd BudgetExceeded
Iterations max_iterations IterationLimitReached
Duration max_duration_ms TimeLimitReached

Handling breaches

from fences import BudgetExceeded, IterationLimitReached, TimeLimitReached

try:
    result = await my_agent("research this topic")
except BudgetExceeded as e:
    print(f"Stopped: spent ${e.spent_usd:.4f} of ${e.budget_usd:.4f}")
except IterationLimitReached as e:
    print(f"Stopped: {e.iterations} iterations reached")
except TimeLimitReached as e:
    print(f"Stopped: ran for {e.duration_ms}ms")

Cloud mode

Connect to a Fences backend for persistent audit trails, a dashboard, and server-authoritative enforcement across distributed agents.

fences.init(api_key="fc_...", endpoint="https://your-fences-instance.com")

Everything else stays the same — same decorator, same checkpoint() calls.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agentfences-0.1.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agentfences-0.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file agentfences-0.1.0.tar.gz.

File metadata

  • Download URL: agentfences-0.1.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.3

File hashes

Hashes for agentfences-0.1.0.tar.gz
Algorithm Hash digest
SHA256 577cd19587189abf42d4efa1060a86330c2de50b1c7fb09459af5cad2d6d4243
MD5 6f24a968cce6d2690bbf123864e64590
BLAKE2b-256 f671cf4b4566c2605844189c8552f3295cb011af13b85308ac5b4020e6233b6f

See more details on using hashes here.

File details

Details for the file agentfences-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: agentfences-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.3

File hashes

Hashes for agentfences-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 96953305d03fee67793fa904dda5188c06a13a616cf333b0004c2095be81cb69
MD5 5c4bed97fbe9d6357de6ad6e2cab687c
BLAKE2b-256 d5883af2ee76527c48f2a410c5b3cd5d82aa4593ef1239ceab4e3e183ec2b223

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page