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.

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
Sampling knobs a caller may pin for the invocation. None means “unspecified”: renderers omit the knob and the provider default applies.
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).
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, rendered verbatim into the provider request’s model field. 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 said (text) and asked (tool calls). 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 thinking text plus the optional provider signature some APIs attach so it can be replayed on later turns. Recorded as-is by callers; the kernel does not interpret or persist it.
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.
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.
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 offered to the model for one invocation; renderers turn this into the protocol’s tools array.
TurnId
Identity of an execution, independent of its context material.

Enums§

ArtifactKind
What an artifact holds.
BatchError
Invalid batch construction, completion, or partition state.
BlockContent
The content shape of a block. Three shapes: one message’s ordered parts (any role), a tool call, a tool result.
CacheDirective
Prompt-cache instruction carried on a ModelRequest. The Anthropic translation face renders explicit cache_control breakpoints at the stable-prefix anchors; OpenAI-family providers cache server-side and accept the directive as a documented no-op.
ContentPart
One content atom inside a BlockContent::Parts 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.
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(()).
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.
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.