Skip to Content
Recodocs

Tools and permissions

The tools-and-permissions layer defines what an agent may call, who authorizes each call, which calls need a person's approval, and the ledger that records what ran.

9 min read

Reading an invoice and approving its payment are not the same action. A tool is a callable function; a tool policy controls which functions are visible, which change the outside world and which effects require a named person's approval. This layer also records and settles calls whose outcome is uncertain. Giving a model access to a tool is not the same as authorizing every possible use of it.

The kit keeps one rule through all of it: the model never grants itself authority. A tool's policy, the identity of the caller and the approval all come from application code. A model argument, a tool description or a persisted record cannot widen them.

Where the boundary is

Tool exposure answers what operations can be requested. Approval answers whether a particular effect may proceed. Those are separate questions even for a tool that is already visible.

This layer ownsThis layer does not own
ToolPolicy: one frozen policy per tool (effect, approval, authorize, reconcile, verify)The tool function's own business logic
Tool visibility: a tool without a policy is hidden from the modelThe model loop that calls tools (agent loop)
Approval of one exact action, and durable human decision recordsWhere run state is stored (harness state)
Per-call receipts and ledgersContent screening of inputs and outputs (guardrails)
Governed effect backends: MCP, a send broker, a governed browser, sandboxed codeIdentity providers and sessions. The host authenticates and hands in a Principal.

Owners and tiers

The golden-path owner is a pair that shares one contract. recohut_kit.harness.contracts.ToolPolicy declares authority and is stdlib-only. The PydanticAI Harness enforces it inside the native loop. recohut_kit.human holds approval records that outlive the process. Tools themselves are plain native functions.

Import pathTierWhat it is for
recohut_kit.harness.contracts.ToolPolicycoreDeclares one tool's authority. An effect tool must supply authorize. Approval implies effect.
recohut_kit_pydantic_ai.harness.pydantic_ai.HarnesscoreEnforces the policies in the native loop: closed allowlist, action ledger, approval round trip.
recohut_kit.human (contracts, preview, checkpoints, action_request, cases)coreExact-action review previews, HumanRequest records, decision rules, a case lifecycle. No SDK, credentials or persistence.
recohut_kit_pydantic_ai.human.pydantic_ai.continuation_resultscoreMaps persisted human decisions to the exact native tool call ids, with rechecks.
recohut_kit.harness.tool_access.ReviewedToolscatalogA kit-owned executor for non-native loops: resolve, validate, authorize, approve, claim, invoke, verify.
recohut_kit.agents_toolscatalogToolSpec (schema, effect, policy, limits), ToolLedger, a safe calculator, an OpenAPI operation executor, plan admission.
recohut_kit.toolscatalogToolResult and ToolReceipt, adapters to LangChain, PydanticAI and Strands tools, a SQLite idempotency fence.
recohut_kit.function_callingcatalogProvider-neutral tool schemas, argument validation and turn records for hand-written loops.
recohut_kit.capabilitiescatalogA host-governed catalog of capability descriptors with availability, loading and authorization states.
recohut_kit.authcatalogRBAC, ReBAC and ABAC with explicit deny, OAuth and PKCE contracts, token admission. Feeds ToolPolicy.authorize.
recohut_kit.mcpsupportedOfficial-SDK MCP server registration and scoped client sessions, with policy checks for sampling, roots and elicitation.
recohut_kit.brokersupportedA credential-owning send broker. It checks an independent approval and reserves one durable grant before a provider sends.
recohut_kit.browsersupportedOpt-in governed browser dispatch with public-URL admission and single-use action-bound grants.
recohut_kit.executioncatalogIsolated Python in a pinned Docker container with CPU, memory, time and output limits.
recohut_kit.ticketing, recohut_kit.aws_toolscatalogJira and Linear adapters behind one backend protocol, and governed S3, Lambda, DynamoDB and CloudWatch tools.
recohut_kit.harnessesdeprecated shimOld import paths that forward to recohut_kit.harness.boundary and recohut_kit.harness.plans.

How the pieces fit

Every step writes an event to the run store, so the order of action_prepared, action_approved, action_started and action_completed can be read back after the fact.

Worked examples

Declaring tools and gating one behind approval

ToolPolicy is a frozen dataclass. A read tool takes the default. An effect tool must name an authorize callback, and an approval tool must also be an effect tool. The full run, including the approval round trip, is on the agent loop page. This example shows the policy mapping and the construction rules.

tool_policies.py
from recohut_kit.harness.contracts import Scope, ToolPolicy

scope = Scope("acme", "u-1", "helpdesk")

policies = {
    # A read tool: visible to the model, no approval.
    "lookup_policy": ToolPolicy(),
    # An effect tool: authorize runs again at dispatch; approval parks the run first.
    "issue_refund": ToolPolicy(
        effect=True,
        approval=True,
        authorize=lambda s, action: s == scope and action.arguments["amount_cents"] <= 50_000,
    ),
}
# Pass as Harness(..., tools=policies). A native tool that is not a key here is hidden.

try:
    ToolPolicy(effect=True)                 # no authorize callback
except ValueError as error:
    print(error)                            # Effect tools require a trusted authorization callback

try:
    ToolPolicy(approval=True)               # approval without effect
except ValueError as error:
    print(error)                            # Approval is an effect boundary; declare effect=True

The authorize callback receives the host-owned Scope and the exact Action (id, name and arguments). It runs once when the action is prepared and again at dispatch.

Approving one exact action

Harness.approve approves a single action by id and digest. It needs a Principal that the host built after authentication, an Access policy that allows approve, and a confirmation reference that validate_confirmation can check. Approval does not run the effect and does not grant other tools.

approve_action.py
from time import time

from recohut_kit.learning.access import Access, Principal
from recohut_kit.learning.access import Scope as AccessScope

# harness, scope and first (the parked result of harness.run) come from the earlier run.
action = harness.runs.pending(scope, first.run.id)[0].action

principal = Principal("alice", scope.tenant, "sso")          # built only after the host authenticates alice
area = AccessScope(scope.tenant, scope.agent)
access = Access(
    area,
    authorize=lambda p, permission, owner: p == principal and permission == "approve" and owner == area,
)

harness.approve(
    scope, first.run.id,
    action_id=action.id, action_digest=action.digest,         # the approval is bound to these exact arguments
    reviewer="alice", expires_at=time() + 600,
    confirmation="msg-42",                                    # reference to the retained confirming message
    principal=principal, access=access,
    validate_confirmation=lambda source: source,              # host check that the message matches this run and action
)
result = await harness.resume(scope, first.run.id, deps=None)

If principal, access or confirmation is missing, approve raises PermissionError. A changed argument changes the action digest, so an approval for one call cannot be reused for another.

A durable approval request for a separate reviewer

Use recohut_kit.human when the reviewer works in another system, such as a ticket queue, and the decision must survive a restart. action_approval_request builds an immutable HumanRequest with a preview of the exact action. decide returns a new request with the decision recorded. The host persists it and does the compare-and-swap.

human_request.py
from recohut_kit.harness.contracts import Action, Binding
from recohut_kit.human.action_request import action_approval_request
from recohut_kit.human.checkpoints import decide
from recohut_kit.human.preview import ConsequenceSchema
from recohut_kit.principal import Principal

binding = Binding("cfg-1", "src-1")
action = Action("run-1:call-2", "issue_refund", {"order_id": "A-17", "amount_cents": 4200})
schema = ConsequenceSchema(
    required=("order_id", "amount_cents"),
    payload_map={"order_id": "order_id", "amount_cents": "amount_cents"},
    recipient_paths=(),
    consequences=("Money is returned to the customer.",),
    technical_allowlist=(),
)

request = action_approval_request(
    action, tenant="acme", conversation_id="conv-1", execution_id="run-1",
    requester="u-1", decision_makers=("alice",), binding=binding, source_revision="src-1",
    compatibility="refund-v1", schema=schema, summary_keys=("order_id", "amount_cents"),
    created_at=1000.0, expires_at=2000.0, reason="Refund above the auto-approve limit",
)
print(request.kind, request.state)                       # approval pending

decided = decide(
    request, Principal("alice", "acme", "sso"),
    decision_id="d-1", expected_version=request.version, kind="approve",
    content="Checked the order", now=1100.0, binding=binding, source_revision="src-1",
    action_digest=action.digest, schema=schema,
)
print(decided.state, decided.decision.actor)             # approved alice

A person outside decision_makers raises PermissionError. recohut_kit_pydantic_ai.human.pydantic_ai.continuation_results turns the stored decisions back into the native DeferredToolResults. It checks binding, source revision, expiry and current host authorization first, and it never invents an observation.

A tool definition with a schema and a ledger

The catalog agents_tools owner describes a tool once as a ToolSpec and records each call in a ToolLedger. It does not depend on any agent SDK. ToolSpec refuses a spec whose effect disagrees with its policy.

tool_spec.py
from pydantic import BaseModel

from recohut_kit.agents_tools.contracts import ToolCallReceipt, ToolLedger, ToolSpec
from recohut_kit.harness.contracts import ToolPolicy


class RefundArgs(BaseModel):
    order_id: str
    amount_cents: int


refund = ToolSpec(
    "issue_refund", "Refund an order.", RefundArgs,
    effect=True, side_effect="write",
    policy=ToolPolicy(effect=True, approval=True, authorize=lambda scope, action: True),
    idempotency_semantics="keyed by action id",
)
print(refund.to_openai_schema()["function"]["name"])     # issue_refund
print(refund.to_mcp_schema()["annotations"])             # {'readOnlyHint': False}

ledger = ToolLedger()
attempt = ledger.claim("call-1", "issue_refund")         # a second claim of call-1 raises ValueError
ledger.append(ToolCallReceipt(
    ledger.run_id, "call-1", "issue_refund", {"order_id": "A-17"}, "ok",
    duration_ms=3, result_size=31, attempt=attempt, identity_hash=refund.identity_hash,
))
print(ledger.total_calls, ledger.counts)                 # 1 {'issue_refund': 1}

Choosing between owners

You needUse
Tools for a new PydanticAI agentPlain functions, one ToolPolicy each, passed to Harness
Approval inside the same processHarness.approve
Approval by another team, queue or channel that outlives the processrecohut_kit.human plus continuation_results
Tools for a loop that is not PydanticAIReviewedTools (needs an approval authority, action lifecycle and credential injector)
One schema rendered for OpenAI, MCP or LangChainagents_tools.ToolSpec or function_calling
Expose your tools to other clients, or use another server's toolsrecohut_kit.mcp
Send a message with credentials the agent must never holdrecohut_kit.broker
Drive a web page under policyrecohut_kit.browser
Run model-written coderecohut_kit.execution with its limits recorded
Decide who is allowed, by role or relationrecohut_kit.auth, called from authorize

Failure behaviour, limits and gotchas

  • A tool with no policy is hidden, silently. Harness(tools={...}) is a closed allowlist. A missing key leaves a native tool out of the model's view with no error. Pass strict_tools=True to make the Harness raise a ValueError that names every native tool without a policy and every policy key that matches no tool.
  • Effect tools run one at a time. The Harness marks them sequential, so two effects do not interleave.
  • An uncertain effect stops. If a run is interrupted after an effect starts and the outcome is unknown, the harness will not replay it. Supply reconcile, an async callback that returns a Reconciliation with found and non-empty readback evidence. Without it the run stops.
  • Use the action id as the downstream idempotency key. current_action().id is stable for a logical call. SQLite cannot make a remote effect transactional.
  • Approval is exact. It binds the tool call's id and argument digest. It expires at expires_at and is bound to one run.
  • approve needs host-verified identity. A signature alone is not enough. Without a principal, an access policy and a confirmation, it raises PermissionError.
  • Add DeferredToolRequests to the agent's output_type when any tool has approval=True. A call with no matching policy raises HarnessError rather than being parked.
  • Tool errors reach the model in a reduced form. When a recovery policy is configured, a failing tool is turned into a retry that names only the exception type and an error code, not the message. Without one, the exception propagates.
  • ToolSpec annotations grant nothing. An MCP readOnlyHint is protocol metadata. Execution is still decided by the policy.
  • harnesses is a deprecated shim. Import from recohut_kit.harness.boundary and recohut_kit.harness.plans.
  • Sandboxed execution is only as strong as Docker. The execution owner records its limits and checks cleanup. It does not claim a stronger boundary.

The policy is the boundary

Decorating a function or writing a good description does not restrict it. Calling a decorated Python function directly bypasses every check. The boundary exists only where the Harness, ReviewedTools or another enforcing executor dispatches the call.

How is this page?

Last updated on