Contracts¶
Value objects that cross a boundary: they hold only HarnessWeaver types (RULES R7), and each has a JSON Schema in contracts/schemas/ (Contracts).
Messages¶
Message ¶
Bases: _Contract
One message in a model conversation.
Role ¶
Bases: StrEnum
Who wrote a message.
ModelRequest ¶
Bases: _Contract
A request to a model, by alias or concrete model name.
ModelResponse ¶
Bases: _Contract
A model's answer.
ToolCall ¶
Bases: _Contract
A tool call proposed by a model.
ToolSpec ¶
Bases: _Contract
A tool as offered to a model.
StreamChunk ¶
Bases: _Contract
One piece of a streamed model response.
Usage ¶
Bases: _Contract
Token usage of one or more model calls.
The envelope¶
Envelope ¶
Bases: BaseModel
The immutable context every hook event carries.
new
classmethod
¶
new(
*,
tenant: str,
principal: Principal | str,
task: str | None = None,
task_version: str | None = None,
budget: Budget | None = None,
clock: Clock | None = None,
run_id: str | None = None,
parent_run_id: str | None = None,
idempotency_key: str | None = None,
trace_id: str | None = None,
attributes: dict[str, str] | None = None,
) -> Self
Build the envelope for a new run. The deadline comes from budget.deadline.
with_labels ¶
with_labels(labels: Labels) -> Self
Return a copy with new labels (the clock is kept).
remaining ¶
Time left before the deadline (never negative), or None without a deadline.
Principal ¶
Bases: BaseModel
Who a run acts for.
Labels ¶
Bases: BaseModel
What kind of data a run has touched. Drives the lethal-trifecta check (RULES S3).
Budget ¶
Clock ¶
FakeClock ¶
Bases: Clock
A clock that only moves when told to. For tests (RULES T8).
It starts on Monday 2026-01-05 09:00 UTC unless given a start time.
RunContext ¶
RunContext(
*,
envelope: Envelope,
bus: HookBus,
trace: RunTrace,
meter: BudgetMeter,
models: ModelAccess | None = None,
tools: ToolBackend | None = None,
task: TaskInfo | None = None,
prompts: PromptSource | None = None,
grants: Iterable[Grant] = (),
on_chunk: Callable[[StreamChunk], None] | None = None,
harness: object = None,
can_suspend: bool = True,
telemetry: Telemetry | None = None,
governor: ToolGovernor | None = None,
policy: PolicyEngine | None = None,
context: ContextGovernor | None = None,
memory: Memory | None = None,
memory_ttl: timedelta | None = None,
context_ids: Iterable[str] = (),
recorder: Callable[[RecordedCall], Awaitable[None]]
| None = None,
recorded: int = 0,
replaying: bool = False,
grant_scope: Literal["call", "run"] = "call",
)
Bases: StepChecks, ModelCalls, ToolCalls
The state of one run and its governed operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
envelope
|
Envelope
|
The run's envelope; its clock is the run's clock. |
required |
bus
|
HookBus
|
The harness's hook bus. |
required |
trace
|
RunTrace
|
Where every outcome is recorded (R13). |
required |
meter
|
BudgetMeter
|
The run's budget meter. |
required |
models
|
ModelAccess | None
|
Model access. |
None
|
tools
|
ToolBackend | None
|
Tool backend. |
None
|
task
|
TaskInfo | None
|
The task being run, if any. |
None
|
prompts
|
PromptSource | None
|
Where prompts come from. |
None
|
grants
|
Iterable[Grant]
|
Approvals already given (when resuming). |
()
|
on_chunk
|
Callable[[StreamChunk], None] | None
|
Called with each streamed chunk after |
None
|
harness
|
object
|
The owning harness, for runners that build sessions. |
None
|
telemetry
|
Telemetry | None
|
Where spans and metrics go; |
None
|
can_suspend
|
bool
|
Whether |
True
|
activate ¶
activate() -> Generator[RunContext]
Make this the current run for the enclosed code (see current_run).
current_run ¶
current_run() -> RunContext | None
The run active in this task, for adapters and built-in middleware.
Decisions and guards¶
Decision ¶
Bases: BaseModel
A router's answer, with the stage and reason that produced it (R13).
DecisionKind ¶
Bases: StrEnum
How a decision was reached.
DecisionRequest ¶
Bases: BaseModel
A question for a router: pick one of options for text and state.
GuardResult ¶
Bases: BaseModel
A guardrail's verdict on one piece of content.
GuardAction ¶
Bases: StrEnum
What a guardrail wants done with the content it checked.
The guardrails module maps actions onto hook outcomes (DESIGNS No. 9).
Finding ¶
Bases: BaseModel
Something a guardrail found. Never holds the raw matched text (R9).
Policy¶
PolicyEffect ¶
Bases: StrEnum
The outcome of a policy check, from most to least permissive.
PolicyRequest ¶
Bases: BaseModel
The question a PolicyEngine answers: may this run, or this call, go ahead?
PolicyDecision ¶
Bases: BaseModel
A PolicyEngine's answer, with the rule that decided it.
tighten ¶
tighten(
current: PolicyEffect, proposed: PolicyEffect
) -> PolicyEffect
Combine a policy effect with a check that may only make it stricter (R3).
A judge or classifier can turn allow into require_approval or
deny, but never the other way round.
Tools¶
ToolInfo ¶
Bases: BaseModel
The parts of a tool manifest that policies and middleware decide on.
ToolResult ¶
Bases: BaseModel
What a tool returned. Output is untrusted unless the manifest says otherwise (S3).
ToolVerdict ¶
Bases: BaseModel
What the governor decided about one call, and at which of its steps (DESIGNS No. 17).
ToolManifest ¶
definition_digest ¶
The digest that pins what a model is told about a tool (S2, rug-pull defense).
Risk ¶
Bases: StrEnum
How much harm a misused call could do.
SideEffect ¶
Bases: StrEnum
What a tool changes when it runs.
Context¶
ContextItem ¶
Bases: BaseModel
One retrieved document or memory entry.
Acl ¶
Bases: BaseModel
Who may see a retrieved item. An empty list means "no restriction" for that part.
Approvals¶
ApprovalRequest ¶
Bases: BaseModel
A suspended step waiting for a human.
ApprovalDecision ¶
Bases: BaseModel
A human's answer to an ApprovalRequest.