Skip to main content

Crate cairn

Crate cairn 

Source
Expand description

§Cairn

Durable, governed, model-agnostic agents.

ⓘ
use cairn::prelude::*;

let agent = Agent::builder("support")
    .model(cairn::models::from_spec("anthropic:claude-opus-5-5")?)
    .system("You resolve support tickets.")
    .tool(get_order)
    .tool(refund)                       // Effect::Irreversible -> needs approval
    .budget(Budget::default().max_steps(20).max_usd(1.0))
    .journal(JsonlJournal::new("runs")?)
    .build()?;

let outcome = agent.run("Refund order 1042").await?;

Modules§

agent
budget
eval
Evals by replay: re-run recorded runs on a candidate configuration (e.g. another model), score the results and compare cost.
event
journal
message
model
models
Model adapters and provider:model construction.
output
Helpers for reading structured output out of model text.
policy
prelude
pricing
state
testing
Deterministic models for tests and offline examples.
tool

Structs§

Agent
AgentBuilder
AllowAll
Budget
Hard limits enforced by the runtime before every model call.
EffectPolicy
Requires human approval for every call at or above approve_at. The default gates irreversible tools.
Event
One immutable fact in a run’s history.
FallbackModel
Tries each model in order. Moves on when a request fails with a retryable error or when the answer is unusable:
InMemoryJournal
JsonlJournal
One JSON-lines file per run, fsynced on every append.
LeaseHolder
Who currently holds a run’s lease.
Message
ModelRequest
ModelResponse
PendingCall
A tool call requested by the model that has not produced a result yet.
Priced
Attaches pricing to any model, e.g. one built from a provider:model spec.
Pricing
USD per million tokens. Prices change often, so Cairn never hardcodes them; set them from your provider’s current price sheet. A model that is genuinely free should say so explicitly with Pricing::new(0.0, 0.0).
RejectedAttempt
A model answer that was received, paid for, and discarded.
RunOutcome
Result of driving a run until it finishes or needs a human.
RunState
The full state of a run, derived purely from its events.
ToolCtx
Passed to every tool invocation.
ToolError
ToolSpec
Usage

Enums§

AgentError
Content
Provider-neutral content block.
Decision
Effect
What a tool does to the world. Policies and retry semantics key off this.
EventKind
JournalError
ModelError
Role
Status
StopReason
StreamEvent
Incremental output from a streaming model call.

Traits§

Journal
Append-only, per-run event storage.
Model
Policy
Decides, before execution, whether a tool call may run.
Tool

Functions§

synthesize_stream
Express a complete response as the deltas a streaming call would yield.
tool
Builds a typed tool from an async function. The JSON schema shown to the model is derived from I, and model input is validated against it.

Type Aliases§

ModelStream