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

Uploaded Python 3

File details

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

File metadata

  • Download URL: agentfences-0.1.1.tar.gz
  • Upload date:
  • Size: 2.3 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.1.tar.gz
Algorithm Hash digest
SHA256 1cbe0dda940db58d49783bcf519a0a83ca15b5d38e7dea5fcc295c80496ccf7a
MD5 5213f7bc07519a5c18a00be94ebed0b2
BLAKE2b-256 0db7768b84a20851bda94cb17f4a073ad8a0652115fe4fb4ac72e625fd01da71

See more details on using hashes here.

File details

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

File metadata

  • Download URL: agentfences-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 2.2 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 43d1446df665fb4b35cea8f341cef3801c2a95bef401d89eb8927d6336c0c49d
MD5 8848688a90c98598baa6fadc1e72e66f
BLAKE2b-256 a7ec56f8792f25d3fecad153ce7beae2e25e90f06a31c2a3966e78dccd136993

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