Skip to main content

Crate causa_kernel

Crate causa_kernel 

Source
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§

ArtifactHint
Provenance a caller attaches to bytes handed to ArtifactStore::persist, so the store can label what it receives.
ArtifactRef
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.
BlockMeta
Envelope provenance. Fields are serde-additive so older records without them still deserialize.
CallControl
Cooperative control for a logical model invocation, preparation or tool work.
CancellationToken
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.
ContextBlock
A typed fact. Three axes: identity, content, envelope provenance.
ContextEdit
An exclusive, uncommitted edit builder for a context.
ContextFrame
The ordered material selected for one model request.
EditFailure
An edit failure together with every submitted block of edit material.
GenerationOptions
Generation knobs a caller may pin for the invocation. None leaves the provider default in force. Protocol adapters reject options they cannot faithfully render. Hosts own model-specific capability validation, defaults, and aggregate budgets; reasoning_effort and extra_body are sent as given for that reason.
InvocationId
Identity of one model invocation: which turn, and which round inside it.
MediaRef
A media fact: a cheap, durable reference. Bytes never enter facts — they appear only in resolved render payloads (provider side).
ModelInvokeError
A model-invocation failure: a ModelInvokeErrorKind plus human-readable detail (provider text included where available).
ModelItem
One item the model produced: its content plus the wire fields that content does not hold.
ModelOutput
The gateway result envelope. Pure response conversion consumes neither this value nor its usage and reasoning; execution consumers retain them.
ModelRef
Opaque model identifier handed to the gateway. The kernel never parses it; resolution is the gateway’s job.
ModelRequest
Everything one logical invocation needs. All fields stay unchanged across internal retries; the gateway owns any attempt numbering and retry policy.
ModelResponse
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.
ModelUsage
Provider-reported token accounting for one model response.
PrepareError
Failure to prepare a request’s material.
ProcessorContext
Context made available to tool batch processors.
ReasoningPayload
Structured reasoning content: the model’s readable thinking text. Recorded as-is by callers; the kernel does not interpret or persist it.
RejectedToolResult
A result ToolBatch::resolve_at refused, 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).
RoundInfo
Configuration visible while preparing this invocation’s material.
SealedPart
A model-issued wire item carried as content the kernel cannot read.
TextPayload
A single string of text. Serializes transparently as the inner string.
ToolBatch
One tool batch with a completed prefix and pending suffix.
ToolCallContext
Identity of one tool dispatch, handed to Tool::execute.
ToolCallDraft
A tool call as the model proposed it, before the caller assigns its declaration BlockId. Exactly what the gateway parsed off the wire.
ToolCallEntry
A declaration plus its optional completed result.
ToolCallId
Borrowed content key for comparing tool calls within a caller-selected scope. Instance pairing always uses the declaration’s BlockId.
ToolCallPayload
A model-issued tool call. Its containing block ID is the declaration identity; provider-issued identifiers ride on BlockMeta::provider_call_id.
ToolChange
A change to the tools offered to the model, effective from the position of its block onward.
ToolDefinition
The model-facing description of one callable tool; renderers map it onto the protocol’s tool entries (name, description, parameter schema).
ToolOutput
What a tool returned, as recorded by the tool door.
ToolOutputMeta
Optional observability sidecar on a tool output; never part of pairing.
ToolResultPayload
The result fact for one tool call: its declaration identity, terminal status, output, media, and ordered notes. Pairing is kernel-enforced.
ToolSurface
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::ToolChange block, and renderers read the tools from the frame, never from this value.
TurnId
Identity of an execution, independent of its context material.
WireMeta
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§

ArtifactKind
What an artifact holds. A label for the host; nothing in the library decides by it, so further kinds may be added.
BatchError
Invalid batch construction, completion, or partition state.
BlockContent
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.
CacheDirective
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.
ContentPart
One content atom inside a BlockContent::Message block: ordered, identity-free, sharing the block’s envelope. New modalities arrive as new variants (additive); media bytes stay out of facts forever.
ControlError
Why a control check failed.
EditError
Why an atomic context edit could not be committed.
ModelBlockError
Why a model response cannot be converted into blocks.
ModelInvokeErrorKind
Classification of a logical model invocation failure.
ModelItemContent
The content of a ModelItem.
ModelStopReason
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.
ProcessorError
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.
SourceError
Listing failure — the catalog as a whole is unusable right now.
StoreError
Error surface of the ArtifactStore port.
StreamDelta
One incremental observation from a streaming provider.
ToolExecutionError
Single-call failure inside a source. The executor’s tool adapter (ToolBridge in causa_runtime) turns every variant into a structured tool result the model reads; the status mapping lives there, not here.
ToolResultError
Why tool results cannot be appended to the supplied material scope.
ToolResultStatus
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§

ArtifactStore
Persistence port for tool artifacts — where oversized tool outputs are spilled and read back. Callers persist raw bytes plus an ArtifactHint and receive an ArtifactRef to embed in the result; concrete stores are host concerns.
ContextPreparer
Prepares an independent request frame with exclusive access to context.
DynamicToolSource
One external tool catalog. Implementors own their connection, their naming (see the mcp_{server_id}_{tool} namespace convention in causa-extension), and their change notifications.
ModelGateway
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.
ToolBatchProcessor
A pre- or post-processing phase over one exclusively borrowed tool batch.

Functions§

completed_model_stream
Wrap an already-complete output as a single-Done stream — the degenerate form the default stream implementation and tests use.
current_tools
The tools offered after every ToolChange in blocks, in the order they were first added.
validate_tool_result_append
Validates this result append without mutating or consuming its inputs.

Type Aliases§

ModelStream
Bounded stream of provider deltas. Cancellation is observable through the same CallControl the invoke path uses — drivers race next() against the cancellation token, never poll.