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

Uploaded Python 3

File details

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

File metadata

  • Download URL: agentfences-0.1.3.tar.gz
  • Upload date:
  • Size: 5.4 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.3.tar.gz
Algorithm Hash digest
SHA256 f22f78c9a3b07e800e382e7643bcc0f9c1c35d5b1750a8819bc7057d68a987b2
MD5 6969ee8c1c7f00ad75f77bc85420b565
BLAKE2b-256 cb6590fcf2efe906b75eff70893b010d097714a0356257a2db8c870d27a69d5a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: agentfences-0.1.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3d14ddcece6ae1edd4da71669456c3c4ba3058009163063ccc9ac860d2a4d582
MD5 2d46864225c4add469f011d91f29d38b
BLAKE2b-256 36f840a076eae1af44d3e470764d131e230b56b18e6e0c982c8f46d430b9a7ce

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