Metadata-Version: 2.5
Name: brutor-runtime-hooks
Version: 0.2.0
Summary: Agent Hooks interceptor for Brutor Agent Control: governs the tool calls, prompts and answers an agent handles in its own process
Project-URL: Documentation, https://docs.brutor.ai/runtime-hooks/
Author: Brutor AI Ltd.
License-Expression: LicenseRef-Brutor-Enterprise-SDK
License-File: LICENSE
License-File: NOTICE
Keywords: agent control specification,agent framework,agent hooks,agents,approvals,claude agent sdk,governance,langgraph,openai agents,policy
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: License :: Other/Proprietary License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Security
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: brutor-agent-auth<0.3,>=0.2
Requires-Dist: httpx<1,>=0.27
Provides-Extra: agent-framework
Requires-Dist: agent-framework-core==1.26.0; extra == 'agent-framework'
Requires-Dist: agent-hooks-sdk==0.1.0b3; extra == 'agent-framework'
Provides-Extra: bundle
Requires-Dist: agent-control-spec==0.4.0b2; extra == 'bundle'
Provides-Extra: claude-agent-sdk
Requires-Dist: claude-agent-sdk<0.3,>=0.2.185; extra == 'claude-agent-sdk'
Provides-Extra: langgraph
Requires-Dist: langgraph<1.3,>=1.2; extra == 'langgraph'
Provides-Extra: openai-agents
Requires-Dist: openai-agents<0.26,>=0.25; extra == 'openai-agents'
Description-Content-Type: text/markdown

# Brutor Agent Control — Runtime Hooks for Python (Enterprise)

Governed runtime hooks for agents that run outside the gateway.

**Edition:** Enterprise

## What it is

Runtime hooks for Brutor Agent Control. Your agent calls tools, reads prompts
and writes answers in its own process, out of the gateway's sight. With this package each of those
steps is decided by the gateway, under the same grants, argument policies, data scope, run policies,
guardrails and approvals as its own traffic. The decision travels as an
[Agent Hooks 0.1](https://github.com/responsibleai/agent-hooks) interceptor call.

The package is a client of the Enterprise Edition gateway and is licensed under the Brutor
Enterprise SDK Licence (see License below). You can install it and evaluate it against any gateway,
including an Enterprise trial. Production use needs an Enterprise licence on the gateway.

Documentation: https://docs.brutor.ai/runtime-hooks/

## Requirements

Python 3.11 or later (CI runs 3.11 to 3.15). Dependencies: `brutor-agent-auth` (>=0.2,<0.3) and `httpx`.

## Install

```bash
pip install brutor-runtime-hooks                      # the interceptor and HookSession
pip install 'brutor-runtime-hooks[agent-framework]'   # Microsoft Agent Framework
pip install 'brutor-runtime-hooks[claude-agent-sdk]'  # Claude Agent SDK (Python)
pip install 'brutor-runtime-hooks[openai-agents]'     # OpenAI Agents SDK
pip install 'brutor-runtime-hooks[langgraph]'         # LangGraph
pip install 'brutor-runtime-hooks[bundle]'            # the local bundle cache
```

The agent authenticates with `brutor-agent-auth` (a dependency): a short-lived workload token from
the platform it runs on, so no secret is stored in the agent.

## Quick start

```python
from brutor.runtime_hooks import BrutorApprovalResolver, BrutorInterceptor, HookSession

interceptor = BrutorInterceptor()  # BRUTOR_GATEWAY_URL; credential from brutor.auth.WorkloadAuth()
resolver = BrutorApprovalResolver(interceptor)

async with HookSession(
    interceptor, agent_id="loan-screening", framework="langgraph", tools=["write_file"], resolver=resolver
) as hooks:
    pre = await hooks.pre_tool_call("call_1", "write_file", {"path": "/letters/APP-1042.md"})
    if pre.proceeds:  # pre.target: the arguments as allowed, or as the gateway transformed them
        result = write_file(**pre.target)
        await hooks.post_tool_call("call_1", "write_file", pre.target, result)
```

Each step returns a `HookOutcome` (`verdict`, `proceeds`, `target`, `transformed`): act only when
`proceeds`, and always with `target`, which is the redacted or rewritten value after a `transform`.

Turn runtime hooks on for the AI System first (Admin Console, the AI System's Runtime hooks tab):
`observe` shows what `enforce` would decide and blocks nothing; `enforce` applies the decisions.

- **Microsoft Agent Framework**: `middleware=[brutor_middleware(interceptor)]` from
  `brutor.runtime_hooks.adapters.agent_framework`. The framework is the Agent Hooks host for all
  eight interception points.
- **Claude Agent SDK**: `async with BrutorClaudeSession(interceptor, options, agent_id=...) as client:`
  from `brutor.runtime_hooks.adapters.claude_agent_sdk`. It covers prompts, tool calls and answers;
  model calls are governed by pointing the SDK at the gateway.
- **OpenAI Agents SDK**: `await BrutorRunner(interceptor).run(agent, prompt)` from
  `brutor.runtime_hooks.adapters.openai_agents`, in place of `Runner.run`. Brutor's guardrails are
  added to copies of your agents; tools the SDK's guardrails cannot see (hosted tools, built-in
  execution tools, agents used as tools) are refused unless you name them in `allow_uncovered`.
- **LangGraph**: `brutor_tool_node(tools, interceptor)` in place of `ToolNode(tools)`, and
  `await governed_invoke(graph, inputs, config, interceptor, agent_id=...)` to run the graph. A hold
  interrupts the graph; resuming it re-evaluates the same decision with the approval. Add
  `BrutorState` to a checkpointed graph's state so the session survives checkpoints.

## The local bundle cache

`BrutorInterceptor(bundle=True)` evaluates Brutor's stateless tool rules in the agent's process
(the agent's export, fetched after `agent_startup`). A definite local deny is answered at once and
still recorded by the gateway; everything else, a local allow included, is decided by the gateway.
It is off by default.

## An agent reached as a delegate

An agent that another agent calls through the gateway receives the delegation in
`x-brutor-delegation-*` headers. Start its session with them, and send the run handle (never the
delegation headers) on its own gateway calls:

```python
from brutor.runtime_hooks import HookSession, delegation_from_headers

async with HookSession(
    interceptor, agent_id="fraud-screener", framework="custom", delegation=delegation_from_headers(request.headers)
) as hooks:
    headers = hooks.outbound_headers({"Content-Type": "application/json"})  # X-Brutor-Run-Id
```

The adapters take the same `delegation=` argument.

## Failing closed

When the gateway gives no usable decision (an error, a timeout, an answer that is not a valid
verdict), `BrutorInterceptor` raises `DecisionUnavailable` and the host denies the step.
`HookSession` and the adapters do this for you. The SDK never logs a credential, a run handle, an
approval token or the content of a step. Content that the gateway's checks do not read is replaced
by its hash before it is sent.

## Development

From `sdk/enterprise/python/brutor-runtime-hooks` in the Brutor Agent Control repository (tools
pinned in `requirements-dev.txt`). The `sdk-enterprise.yml` workflow runs these gates:

```bash
python -m pip install -r requirements-dev.txt -e ../../../python/brutor-agent-auth -e '.[agent-framework,claude-agent-sdk,openai-agents,langgraph,bundle]'
ruff check . && ruff format --check .
mypy --strict src
python scripts/env_registry.py --check
python -m pytest        # fails below 95% coverage
```

## Documentation

https://docs.brutor.ai/runtime-hooks/

## Security

See SECURITY.md at the repository root.

## License

Proprietary: the Brutor Enterprise SDK Licence (see `LICENSE`). It is not an open-source license.
