Skip to main content

Crate pipecrab_lm

Crate pipecrab_lm 

Source
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 of Messages, oldest first. The system prompt, if any, is the first message.
GenParams
Knobs for one generate call. All optional; an engine applies its own default for any left None.
Generate
Run a generation over the current conversation: LmStage’s Processor::Effect. A unit — the conversation to generate from is read from the stage’s own state in perform, not carried in the effect.
LmStage
Adapts any LanguageModel into a pipeline Stage: it accumulates the running Conversation and, when a turn triggers generation, converts the model’s ModelDelta stream into native frames — visible text as agent Transcripts (partials as the deltas arrive, then a final), tool calls as ModelFrame::ToolCall, each generation bracketed by GenerationStarted / GenerationFinished.
ToolCall
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 an id where the provider has none, and owns all JSON validation — core does none.
ToolDefinition
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§

LmConfigError
Why configuring an LmStage or a ToolDefinition failed — a static, provider-neutral error surfaced at construction, not per generation.
LmError
Why a LanguageModel call 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.
ModelDelta
One item of the streaming protocol between a LanguageModel and LmStage: a text delta to append, or one complete tool call.

Traits§

LanguageModel
The swappable language-model capability: a chat context in, structured generation out incrementally.

Type Aliases§

ModelStream
The output of a LanguageModel::generate call: a boxed stream of ModelDelta results, delivered delta by delta.