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.
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 owns | This 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 model | The model loop that calls tools (agent loop) |
| Approval of one exact action, and durable human decision records | Where run state is stored (harness state) |
| Per-call receipts and ledgers | Content screening of inputs and outputs (guardrails) |
| Governed effect backends: MCP, a send broker, a governed browser, sandboxed code | Identity 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 path | Tier | What it is for |
|---|---|---|
recohut_kit.harness.contracts.ToolPolicy | core | Declares one tool's authority. An effect tool must supply authorize. Approval implies effect. |
recohut_kit_pydantic_ai.harness.pydantic_ai.Harness | core | Enforces the policies in the native loop: closed allowlist, action ledger, approval round trip. |
recohut_kit.human (contracts, preview, checkpoints, action_request, cases) | core | Exact-action review previews, HumanRequest records, decision rules, a case lifecycle. No SDK, credentials or persistence. |
recohut_kit_pydantic_ai.human.pydantic_ai.continuation_results | core | Maps persisted human decisions to the exact native tool call ids, with rechecks. |
recohut_kit.harness.tool_access.ReviewedTools | catalog | A kit-owned executor for non-native loops: resolve, validate, authorize, approve, claim, invoke, verify. |
recohut_kit.agents_tools | catalog | ToolSpec (schema, effect, policy, limits), ToolLedger, a safe calculator, an OpenAPI operation executor, plan admission. |
recohut_kit.tools | catalog | ToolResult and ToolReceipt, adapters to LangChain, PydanticAI and Strands tools, a SQLite idempotency fence. |
recohut_kit.function_calling | catalog | Provider-neutral tool schemas, argument validation and turn records for hand-written loops. |
recohut_kit.capabilities | catalog | A host-governed catalog of capability descriptors with availability, loading and authorization states. |
recohut_kit.auth | catalog | RBAC, ReBAC and ABAC with explicit deny, OAuth and PKCE contracts, token admission. Feeds ToolPolicy.authorize. |
recohut_kit.mcp | supported | Official-SDK MCP server registration and scoped client sessions, with policy checks for sampling, roots and elicitation. |
recohut_kit.broker | supported | A credential-owning send broker. It checks an independent approval and reserves one durable grant before a provider sends. |
recohut_kit.browser | supported | Opt-in governed browser dispatch with public-URL admission and single-use action-bound grants. |
recohut_kit.execution | catalog | Isolated Python in a pinned Docker container with CPU, memory, time and output limits. |
recohut_kit.ticketing, recohut_kit.aws_tools | catalog | Jira and Linear adapters behind one backend protocol, and governed S3, Lambda, DynamoDB and CloudWatch tools. |
recohut_kit.harnesses | deprecated shim | Old 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.
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=TrueThe 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.
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.
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 aliceA 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.
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 need | Use |
|---|---|
| Tools for a new PydanticAI agent | Plain functions, one ToolPolicy each, passed to Harness |
| Approval inside the same process | Harness.approve |
| Approval by another team, queue or channel that outlives the process | recohut_kit.human plus continuation_results |
| Tools for a loop that is not PydanticAI | ReviewedTools (needs an approval authority, action lifecycle and credential injector) |
| One schema rendered for OpenAI, MCP or LangChain | agents_tools.ToolSpec or function_calling |
| Expose your tools to other clients, or use another server's tools | recohut_kit.mcp |
| Send a message with credentials the agent must never hold | recohut_kit.broker |
| Drive a web page under policy | recohut_kit.browser |
| Run model-written code | recohut_kit.execution with its limits recorded |
| Decide who is allowed, by role or relation | recohut_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. Passstrict_tools=Trueto make the Harness raise aValueErrorthat 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 aReconciliationwithfoundand non-empty readback evidence. Without it the run stops. - Use the action id as the downstream idempotency key.
current_action().idis 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_atand is bound to one run. approveneeds host-verified identity. A signature alone is not enough. Without a principal, an access policy and a confirmation, it raisesPermissionError.- Add
DeferredToolRequeststo the agent'soutput_typewhen any tool hasapproval=True. A call with no matching policy raisesHarnessErrorrather 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.
ToolSpecannotations grant nothing. An MCPreadOnlyHintis protocol metadata. Execution is still decided by the policy.harnessesis a deprecated shim. Import fromrecohut_kit.harness.boundaryandrecohut_kit.harness.plans.- Sandboxed execution is only as strong as Docker. The
executionowner 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