Runtime
The coordinator for capabilities and policies. Create one per agent process.
Definition
A Runtime owns the capability registry, the policy engine, and the interception machinery. You create one per agent process, configure it with capabilities and policies, and let it govern all capability calls.
Constructor
from brane import Runtime
runtime = Runtime(
agent_id="support-agent",
environment="prod",
tenant_id="tenant_acme",
principal_id="user_sarah",
)All constructor arguments are optional:
| Argument | Type | Description |
|---|---|---|
| agent_id | str | None | Identity of this agent. Used in every AgentAction record. |
| environment | str | None | Runtime environment: dev, staging, prod. Used in ctx.is_prod and action records. |
| tenant_id | str | None | Default tenant for all actions. Can be overridden per-action. |
| principal_id | str | None | Default principal (user or service) for all actions. |
| capabilities | list[Capability] | Pre-register capabilities at construction. |
| policies | list[Policy] | Pre-register policies at construction. |
Owned Components
| Attribute | Type | Purpose |
|---|---|---|
| capabilities | CapabilityRegistry | Stores and retrieves registered capabilities. |
| policy | PolicyRegistry | Stores registered policy functions. |
| policies | PolicyEngine | Evaluates actions against registered policies. |
| interceptor | CapabilityInterceptor | Core intercept-evaluate-execute loop. |
| callables | CallableCapabilityInterceptor | Wraps Python callables with interception and argument binding. |
Methods
runtime.register_capability(capability: Capability)Register a capability in the capability registry.
runtime.capability(name, type, risk, **kwargs) → decoratorDecorator that registers the function as a governed capability and wraps it with policy enforcement.
runtime.wrap_capability(fn, name, type, risk, **kwargs) → callableWrap an existing function as a governed capability without using the decorator syntax.
runtime.before_capability(target, name?, version?) → decoratorRegister a policy that runs before the capability executes. Target is a capability name or wildcard.
runtime.after_capability(target, name?, version?) → decoratorRegister a policy that runs after the capability executes with the output available on ctx.output.
runtime.create_action(capability_name, input, action_type?) → AgentActionCreate an AgentAction manually without calling through the callable interceptor.
runtime.evaluate_action(action: AgentAction) → DecisionEvaluate a manually created action against before_capability policies.
runtime.evaluate(capability_name, input) → DecisionConvenience method: create_action + evaluate_action in one call.
Common Setups
Minimal — local dev:
runtime = Runtime(agent_id="my-agent")Full production context:
runtime = Runtime(
agent_id="support-agent",
environment="prod",
tenant_id=request.tenant_id,
principal_id=request.user_id,
)Pre-registering capabilities and policies:
from brane import Capability, Policy, Decision, Runtime
cap = Capability(name="send_email", type="tool", risk="medium")
def block_external_domains(ctx):
to = ctx.arg("to", "")
if not to.endswith("@acme.com"):
return Decision(type="deny", reason="External email addresses are blocked")
return Decision(type="allow")
policy = Policy(
target="send_email",
stage="before_capability",
function=block_external_domains,
name="block_external_email",
)
runtime = Runtime(
agent_id="comms-agent",
capabilities=[cap],
policies=[policy],
)Per-request runtime (for multi-tenant systems):
def handle_request(request):
# Create a runtime with the request's tenant and principal
runtime = Runtime(
agent_id="support-agent",
environment="prod",
tenant_id=request.tenant_id,
principal_id=request.user_id,
)
# Attach the same shared capabilities and policies
runtime.register_capability(SHARED_REFUND_CAP)
runtime.before_capability("refund_customer")(refund_policy)
# Now all actions in this request have the right identity
...create_action call.Future Constructor Arguments
Planned additions to the Runtime constructor:
audit— AuditSink for recording action eventsapprovals— ApprovalProvider for handling approval_required decisionscloud— CloudClient for remote policy evaluationgrants— GrantRegistry for agent capability grantsfail_mode— fail_open or fail_closed on policy engine errors