Expand description
causa-kernel — ContextBlock conversation kernel. No dependency on a host application, a UI shell, or another agent framework.
The kernel holds ordered material and atomic identity-preserving edits, plus
third-party model, preparation, tool and cancellation contracts. It performs
no I/O, execution policy or conversation management. Reference execution
lives in causa-runtime; concrete transports live in edge crates.
GenerationOptions describes requested generation settings; hosts own
model capability selection and persisted definitions.
§Stable serialized forms
A host stores context, so the serialized form of Context and of every
type it contains is the stable set: ContextBlock, BlockId,
BlockMeta, WireMeta, BlockContent, Role, ContentPart,
TextPayload, MediaRef, SealedPart, ToolCallPayload,
ToolResultPayload, ToolResultStatus, ToolOutput,
ToolOutputMeta, Truncation, ArtifactRef, ArtifactKind,
ToolChange and ToolDefinition.
From 0.1.0 a breaking change to one of these forms needs a minor
version. Adding an optional field is not a break: a reader ignores a field
it does not know, and a field missing from an older record reads as unset.
Every other serializable type (model output, request options, identifiers, error kinds) can be written to logs but carries no such promise. A host that stores one owns its migration.
Structs§
- Artifact
Hint - Provenance a caller attaches to bytes handed to
ArtifactStore::persist, so the store can label what it receives. - Artifact
Ref - Pointer to a tool output persisted out-of-band (e.g. a spilled oversized observation), kept on the result instead of the full content.
- BlockId
- UUID identity of one fact block, independent of its current position.
- Block
Meta - Envelope provenance. Fields are serde-additive so older records without them still deserialize.
- Call
Attachments - Non-persisted, call-scoped typed attachments handed from before-processors to tool execution.
- Call
Control - Cooperative control for a logical model invocation, preparation or tool work.
- Cancellation
Token - The cancellation primitive behind the control planes, re-exported so the port is self-contained for external drivers. A token which can be used to signal a cancellation request to one or more tasks.
- Context
- Ordered material with atomic, identity-preserving edits.
- Context
Block - A typed fact. Three axes: identity, content, envelope provenance.
- Context
Edit - An exclusive, uncommitted edit builder for a context.
- Context
Frame - The ordered material selected for one model request.
- Edit
Failure - An edit failure together with every submitted block of edit material.
- Generation
Options - Generation knobs a caller may pin for the invocation.
Noneleaves the provider default in force. Protocol adapters reject options they cannot faithfully render. Hosts own model-specific capability validation, defaults, and aggregate budgets;reasoning_effortandextra_bodyare sent as given for that reason. - Invocation
Id - Identity of one model invocation: which turn, and which round inside it.
- Media
Ref - A media fact: a cheap, durable reference. Bytes never enter facts — they appear only in resolved render payloads (provider side).
- Model
Invoke Error - A model-invocation failure: a
ModelInvokeErrorKindplus human-readable detail (provider text included where available). - Model
Item - One item the model produced: its content plus the wire fields that content does not hold.
- Model
Output - The gateway result envelope. Pure response conversion consumes neither this value nor its usage and reasoning; execution consumers retain them.
- Model
Ref - Opaque model identifier handed to the gateway. The kernel never parses it; resolution is the gateway’s job.
- Model
Request - Everything one logical invocation needs. All fields stay unchanged across internal retries; the gateway owns any attempt numbering and retry policy.
- Model
Response - The model door’s fact shape: what the model produced, as an ordered list of items. One item becomes one block on commit, in item order. Named for the participant, not for any wire role.
- Model
Usage - Provider-reported token accounting for one model response.
- Prepare
Error - Failure to prepare a request’s material.
- Processor
Context - Context made available to tool batch processors.
- Processor
Data - Host data for one run, handed to every tool processor through
ProcessorContext::data. - Reasoning
Payload - Structured reasoning content: the model’s readable thinking text. Recorded as-is by callers; the kernel does not interpret or persist it.
- Rejected
Tool Result - A result
ToolBatch::resolve_atrefused, returned with the reason. - Replacement
- One replacement expressed in coordinates of the original block sequence.
- RoundId
- Ordinal of a model round within a turn (0-based).
- Round
Info - Configuration visible while preparing this invocation’s material.
- Sealed
Part - A model-issued wire item carried as content the kernel cannot read.
- Text
Payload - A single string of text. Serializes transparently as the inner string.
- Tool
Batch - One tool batch with a completed prefix and pending suffix.
- Tool
Call Context - Identity of one tool dispatch, handed to
Tool::execute. - Tool
Call Draft - A tool call as the model proposed it, before the caller assigns its declaration
BlockId. Exactly what the gateway parsed off the wire. - Tool
Call Entry - A declaration plus its optional completed result.
- Tool
Call Id - Borrowed content key for comparing tool calls within a caller-selected
scope. Instance pairing always uses the declaration’s
BlockId. - Tool
Call Payload - A model-issued tool call. Its containing block ID is the declaration identity; provider-issued identifiers ride on BlockMeta::provider_call_id.
- Tool
Change - A change to the tools offered to the model, effective from the position of its block onward.
- Tool
Definition - The model-facing description of one callable tool; renderers map it onto the protocol’s tool entries (name, description, parameter schema).
- Tool
Description - One tool as its catalog describes it: the model-facing definition and
non-persisted
ToolMetadata. - Tool
Metadata - Non-persisted, bind-time typed metadata carried beside
ToolDefinition. - Tool
Output - What a tool returned, as recorded by the tool door.
- Tool
Output Meta - Optional observability sidecar on a tool output; never part of pairing.
- Tool
Result Payload - The result fact for one tool call: its declaration identity, terminal status, output, media, and ordered notes. Pairing is kernel-enforced.
- Tool
Surface - The tool definitions bound for one invocation: what the executor can
dispatch this round. A driver records a difference from the context’s
tool state as a
crate::ToolChangeblock, and renderers read the tools from the frame, never from this value. - TurnId
- Identity of an execution, independent of its context material.
- Wire
Meta - Wire-level residue of one provider item: every field the translator did not turn into block content, kept uninterpreted so a renderer of the same format can send the item back as returned.
Enums§
- Artifact
Kind - What an artifact holds. A label for the host; nothing in the library decides by it, so further kinds may be added.
- Batch
Error - Invalid batch construction, completion, or partition state.
- Block
Content - The content shape of a block. Four shapes: one message’s ordered parts (any role), a tool call, a tool result, a change to the offered tools.
- Cache
Directive - Prompt-cache instruction carried on a
ModelRequest. Adapters map this directive to protocol-specific cache mechanisms or treat it as a no-op where caching is automatic or unsupported. - Content
Part - One content atom inside a
BlockContent::Messageblock: ordered, identity-free, sharing the block’s envelope. The axis for media modalities isMediaRef::media_type, decided by the host’s resolver and each protocol’s rendering capabilities; newContentPartvariants are only for content that is not a run of bytes. Media bytes stay out of facts forever. - Control
Error - Why a control check failed.
- Edit
Error - Why an atomic context edit could not be committed.
- Model
Block Error - Why a model response cannot be converted into blocks.
- Model
Invoke Error Kind - Classification of a logical model invocation failure.
- Model
Item Content - The content of a
ModelItem. - Model
Stop Reason - Why the model stopped producing output for this round, as reported by the gateway. The kernel validates only the EndTurn/ToolUse structural pairing; interpreting terminal reasons is driver policy.
- Processor
Error - Failure to finish a processing phase. Per-call rejection is a result,
and should be recorded on the batch while returning
Ok(()). - Role
- The speaker of a conversation message.
- Source
Error - Listing failure — the catalog as a whole is unusable right now.
- Store
Error - Error surface of the
ArtifactStoreport. - Stream
Delta - One incremental observation from a streaming provider.
- Tool
Execution Error - Single-call failure inside a source. The executor’s tool adapter
(
ToolBridgeincausa_runtime) turns every variant into a structured tool result the model reads; the status mapping lives there, not here. - Tool
Result Error - Why tool results cannot be appended to the supplied material scope.
- Tool
Result Status - Terminal status of one tool invocation, recorded verbatim as a fact; mapping from execution errors is the driver’s job, not the kernel’s.
- Truncation
- Whether tool output content was shortened to fit the token limit.
Traits§
- Artifact
Store - Persistence port for tool artifacts — where oversized tool outputs are
spilled and read back. Callers persist raw bytes plus an
ArtifactHintand receive anArtifactRefto embed in the result; concrete stores are host concerns. - Context
Preparer - Prepares an independent request frame with exclusive access to context.
- Dynamic
Tool Source - One external tool catalog. Implementors own their connection, their
naming (see the
mcp_{server_id}_{tool}namespace convention incausa-extension), and their change notifications. - Model
Gateway - The model-invocation port: concrete gateways (provider adapters) live
outside the kernel and translate
ModelRequests onto their transport, honoring the invocation’s control plane. - Tool
- The tool port: one callable tool the model can invoke. Implementations live outside the kernel; the driver’s executor dispatches them. A tool returns only its recorded result. Handling unknown outcomes and retaining output belong to the execution consumer, not tool declarations.
- Tool
Batch Processor - A pre- or post-processing phase over one exclusively borrowed tool batch.
Functions§
- completed_
model_ stream - Wrap an already-complete output as a single-
Donestream — the degenerate form the defaultstreamimplementation and tests use. - current_
tools - The tools offered after every
ToolChangeinblocks, in the order they were first added. - validate_
tool_ result_ append - Validates this result append without mutating or consuming its inputs.
Type Aliases§
- Model
Stream - Bounded stream of provider deltas. Cancellation is observable through
the same
CallControltheinvokepath uses — drivers racenext()against the cancellation token, never poll.