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:modelconstruction. - 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
- Agent
Builder - Allow
All - Budget
- Hard limits enforced by the runtime before every model call.
- Effect
Policy - 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.
- Fallback
Model - Tries each model in order. Moves on when a request fails with a retryable error or when the answer is unusable:
- InMemory
Journal - Jsonl
Journal - One JSON-lines file per run, fsynced on every append.
- Lease
Holder - Who currently holds a run’s lease.
- Message
- Model
Request - Model
Response - Pending
Call - 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:modelspec. - 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). - Rejected
Attempt - 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.
- Tool
Error - Tool
Spec - Usage
Enums§
- Agent
Error - Content
- Provider-neutral content block.
- Decision
- Effect
- What a tool does to the world. Policies and retry semantics key off this.
- Event
Kind - Journal
Error - Model
Error - Role
- Status
- Stop
Reason - Stream
Event - 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.