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.2.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.2-py3-none-any.whl (2.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: agentfences-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 e19b6b503ca4e6c9f1b5a51cb1e1d32a0bbe00b3ac9b656192206424c44de4e1
MD5 65d79d24019dd9fa36c394f83fe1e7e5
BLAKE2b-256 3c462ce1aba4396eb2057ecadf9b96ccc8b44a3346a30ca9a0b1f39b80611940

See more details on using hashes here.

File details

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

File metadata

  • Download URL: agentfences-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5d0ba743bb5b1f294a394545f64dd41d4c6dad810cfd692b5d45350977b06ad9
MD5 3f487d1a994fdb1f7c52203c0b9b6d15
BLAKE2b-256 88b242f38e28360686bfb431fcb27b009c126d59054d8e08e234ab400295c6d3

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