Expand description
pipecrab-lm: the provider-neutral structured-generation interface.
LanguageModel is the swappable LM capability the conversation loop drives:
a Conversation in, a ModelStream of ModelDeltas out
incrementally — text to append, or a complete ToolCall. Every item is a
preemption point, so a barge-in
Interrupt stops the reply within a
single delta. Concrete engines stay behind the trait, so the pipeline never
names one.
§ModelDelta vs ModelFrame
A ModelDelta is the internal protocol between a LanguageModel and
LmStage, not a pipeline frame. The stage translates deltas into native
frames: visible text becomes agent Transcripts
(cumulative partials, then a final) because a transcript is prose; a tool call
becomes ModelFrame::ToolCall because
it is structured protocol; the lifecycle becomes
GenerationStarted /
GenerationFinished.
Tool-call syntax, JSON, and provider metadata never enter a transcript.
§Tools
ToolDefinition::parameters is a serde_json::Value so a framework’s
schema reaches a hosted adapter without a string round trip. Core stays
JSON-free: a ToolCall carries validated arguments as JSON text, and
ModelDelta::tool_call normalizes a JSON object into it.
Provider-specific streaming, tool-call fragments, and constrained output are
parsed inside the implementation; the stage sees only complete calls.
LmStage::with_tools / add_tools configure tools on
the stage — validated (duplicate names rejected) and passed to every
generation. An adapter that wraps a higher-level agent (e.g. Rig) keeps its own
registered tools internal, so the stage neither reads nor copies them.
The chat-context types (Message, Conversation) preserve structured
assistant turns, tool calls, tool results, and external events so a hosted
adapter can reconstruct valid provider history.
Platform-neutral and wasm32-checkable: the concrete engines live elsewhere
(a native llama.cpp context, a hosted Rig agent, a browser Worker), each
behind this trait, so the interface itself carries no backend dependency and
compiles for both the host and wasm32-unknown-unknown.
Structs§
- Conversation
- The chat context handed to
LanguageModel::generate: an ordered list ofMessages, oldest first. The system prompt, if any, is the first message. - GenParams
- Knobs for one
generatecall. All optional; an engine applies its own default for any leftNone. - Generate
- Run a generation over the current conversation:
LmStage’sProcessor::Effect. A unit — the conversation to generate from is read from the stage’s own state inperform, not carried in the effect. - LmStage
- Adapts any
LanguageModelinto a pipelineStage: it accumulates the runningConversationand, when a turn triggers generation, converts the model’sModelDeltastream into native frames — visible text as agentTranscripts (partials as the deltas arrive, then a final), tool calls asModelFrame::ToolCall, each generation bracketed byGenerationStarted/GenerationFinished. - Tool
Call - A complete tool call emitted by a language model. Only complete calls enter
the pipeline: an adapter assembles provider-specific fragments into one
arguments_json, synthesizes anidwhere the provider has none, and owns all JSON validation — core does none. - Tool
Definition - A provider-neutral tool definition: name, description, and a JSON Schema for
the arguments — the shape every hosted provider expects. It carries no
execution callback; tool execution lives outside
pipecrab-lm.
Enums§
- LmConfig
Error - Why configuring an
LmStageor aToolDefinitionfailed — a static, provider-neutral error surfaced at construction, not per generation. - LmError
- Why a
LanguageModelcall failed. - Message
- One turn of conversation history, preserving the structure a hosted adapter needs to reconstruct valid provider history: visible assistant text, the assistant’s tool calls, tool-call IDs, tool results, and external events.
- Model
Delta - One item of the streaming protocol between a
LanguageModelandLmStage: a text delta to append, or one complete tool call.
Traits§
- Language
Model - The swappable language-model capability: a chat context in, structured generation out incrementally.
Type Aliases§
- Model
Stream - The output of a
LanguageModel::generatecall: a boxed stream ofModelDeltaresults, delivered delta by delta.