adk_runtime_policy (erlang_adk v0.7.0)

View Source

Fail-closed runtime authorization and byte-budget policy.

A compiled policy is an immutable Erlang value. Agent and tool names must be explicitly allowed (or the corresponding allow selector must be all), and deny selectors always win. Content and tool arguments are measured at the runtime boundary without retaining their values.

Every check returns an immutable, JSON-safe audit decision. Decisions never contain arguments, content, credentials, exception text, pids, references, or functions. They can therefore be appended to an event/audit store by the caller without further redaction.

Summary

Functions

Authorize an agent invocation, then enforce the content budget.

Enforce the content budget for an already-authorized runtime value, such as a model response or tool result.

Authorize a resolved tool call, then enforce its canonical JSON argument budget. Runner integration must call this only after normal tool resolution, preserving dynamic toolset and plugin precedence.

Compile and strictly validate a policy.

JSON-safe policy metadata. Names are policy configuration, not runtime argument/content values.

Types

decision/0

-type decision() :: map().

outcome/0

-type outcome() :: {allow, decision()} | {deny, decision()}.

policy/0

-opaque policy()

Functions

check_agent(Policy, AgentId, Content)

-spec check_agent(policy(), binary(), term()) -> outcome().

Authorize an agent invocation, then enforce the content budget.

check_content(Policy, Subject, Content)

-spec check_content(policy(), binary(), term()) -> outcome().

Enforce the content budget for an already-authorized runtime value, such as a model response or tool result.

check_tool(Policy, ToolName, Arguments)

-spec check_tool(policy(), binary(), term()) -> outcome().

Authorize a resolved tool call, then enforce its canonical JSON argument budget. Runner integration must call this only after normal tool resolution, preserving dynamic toolset and plugin precedence.

compile(Options)

-spec compile(map()) -> {ok, policy()} | {error, term()}.

Compile and strictly validate a policy.

Supported keys are id, agents, tools, max_argument_bytes, and max_content_bytes. Agent/tool rules are maps with allow and deny selectors. A selector is all or a list of UTF-8 binary names. Omitted allow selectors are empty, which is intentionally fail-closed.

describe(Policy)

-spec describe(policy()) -> map().

JSON-safe policy metadata. Names are policy configuration, not runtime argument/content values.