Skip to main content

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

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.4.tar.gz (7.5 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.4-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: agentfences-0.1.4.tar.gz
  • Upload date:
  • Size: 7.5 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.4.tar.gz
Algorithm Hash digest
SHA256 d155dcb69fd7b5195fde58c34194753a989ccef3964df6084a16e11491fb5e8b
MD5 a166403f24f1d51d38cf44f67b455420
BLAKE2b-256 a88b267514a69078242acc5055f9ed18e6c715919f89d87b0b6a7cf60906ec62

See more details on using hashes here.

File details

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

File metadata

  • Download URL: agentfences-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 7.5 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 049775389c5dce12d5b1ebd68ac0321b96bc9b1e57e9ec129f94cadd95d5ba4a
MD5 f3ce2453006e3345803e9e394829e571
BLAKE2b-256 fd4a5f23b8edd5b591ea64b02eca087c23fca7e645cf10ba592e149f3432c08c

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