Skip to main content

Python SDK for AgentBouncr — Governance for AI Agents

Project description

agentbouncr

PyPI version Python versions License: MIT

Governance for autonomous AI agents. Every tool call is checked against your policies before execution.

Native adapters for LangChain / LangGraph (drop-in callback) and CrewAI (tool wrapper). Any other framework works via the plain HTTP evaluate() client.

Installation

pip install agentbouncr

For LangChain integration:

pip install "agentbouncr[langchain]"

For CrewAI integration:

pip install "agentbouncr[crewai]"

30-Second Quickstart

from agentbouncr import AgentBouncr

client = AgentBouncr(api_key="sk_live_your_key_here")

result = client.evaluate(
    agent_id="my-research-agent",
    tool="send_email",
    params={"to": "user@example.com"},
)

if result.allowed:
    send_email(to="user@example.com")
else:
    print(f"Blocked by policy: {result.reason}")

LangChain in 3 Lines

from agentbouncr import AgentBouncr
from agentbouncr.langchain import AgentBouncrCallbackHandler

client = AgentBouncr(api_key="sk_live_your_key_here")
handler = AgentBouncrCallbackHandler(client, agent_id="my-research-agent")

executor = AgentExecutor(agent=agent, tools=tools)
executor.invoke({"input": "Find the latest AI news"}, config={"callbacks": [handler]})

Every tool call now passes through AgentBouncr first. Denied calls raise GovernanceDeniedError.

Important — pass callbacks at invoke time, not in the constructor. In LangChain 0.3.x, passing callbacks=[handler] to AgentExecutor(...) attaches the handler to the executor but does not reliably propagate it to the inner tool runs. The on_tool_start hook then never fires and governance is silently bypassed. Always pass callbacks via the per-call config={"callbacks": [handler]} argument to .invoke() / .stream() / .ainvoke() — this is the supported path and the one we test against.

LangGraph works the same way:

app = create_react_agent(llm, tools)
app.invoke({"messages": [...]}, config={"callbacks": [handler]})

Coverage

The handler intercepts standard LangChain/LangGraph tool runs via on_tool_start. That covers the patterns used by create_react_agent, AgentExecutor with Tool / StructuredTool / BaseTool subclasses, and native function-calling tool wrappers.

It does not intercept code paths that bypass the tool abstraction — for example a raw Runnable chain that calls an external API directly, or a custom node in a LangGraph that invokes an HTTP client without wrapping it as a tool. For those, call client.evaluate(...) yourself before the side effect.

CrewAI in 3 Lines

from agentbouncr import AgentBouncr
from agentbouncr.crewai import govern_tools

client = AgentBouncr(api_key="sk_live_your_key_here")

# Observe-first (default): every tool call is evaluated + logged, execution always proceeds.
agent = Agent(role="researcher", tools=govern_tools(tools, client, "my-research-agent"))

For the fail-closed path, wrap a tool with enforce=True — a denied call then raises GovernanceDeniedError and the wrapped tool never runs:

from agentbouncr.crewai import govern_tool

enforced = govern_tool(my_tool, client, agent_id="my-research-agent", enforce=True)

CrewAI defaults to observe-first / fail-open — the deliberate inverse of the LangChain handler's fail-closed default. Denials are advisory (logged, never blocking) and an unreachable API does not block the tool until you opt into enforce=True.

Authentication

Get an API key from your AgentBouncr Dashboard under Settings → API Keys.

client = AgentBouncr(api_key="sk_live_...")

For multi-workspace setups:

client = AgentBouncr(
    api_key="sk_live_...",
    tenant_id="your-workspace-id",
)

Configuration

client = AgentBouncr(
    api_key="sk_live_...",
    base_url="https://agentbouncr.com",  # default
    timeout=5.0,                              # request timeout in seconds
    max_retries=3,                            # exponential backoff for 5xx/429
    tenant_id=None,                           # optional X-Tenant-Id header
)

Error Handling

from agentbouncr import (
    AgentBouncrError,        # base class
    AuthenticationError,     # 401
    ValidationError,         # 400
    RateLimitError,          # 429 after retries exhausted
    ServerError,             # 5xx after retries exhausted
    TimeoutError,            # request exceeded timeout
    GovernanceDeniedError,   # raised by LangChain handler when policy denies
)

Links

License

MIT — see LICENSE.

The AgentBouncr backend is commercial software. The SDK is open source so you can audit, patch, and integrate freely.

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

agentbouncr-0.1.3.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

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

agentbouncr-0.1.3-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: agentbouncr-0.1.3.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for agentbouncr-0.1.3.tar.gz
Algorithm Hash digest
SHA256 03c3b718b8c6410f6dd9fd63d5092a2fdff13bf97a148844ebd1f391435463ca
MD5 368d74bb71c1de6d767f7e2fde2f9a48
BLAKE2b-256 250933022bdd26ce5ab7ca483cf7e3b7b77f55943c4c928b22cf9c2089455473

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentbouncr-0.1.3.tar.gz:

Publisher: publish-python.yml on agentbouncr/enterprise

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: agentbouncr-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for agentbouncr-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9f50b3e79dd9bb43fae2455c81ff9b1fdabfbae978616b2cf2958514eac8bfc6
MD5 9ce930caccb8033d97a290a69e12167a
BLAKE2b-256 18c0281e7279f7b00b453c858cd67b9db531e88bc2ee74d95909997ffc50fd8c

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentbouncr-0.1.3-py3-none-any.whl:

Publisher: publish-python.yml on agentbouncr/enterprise

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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