Expand description
Core traits and types for the rune-chain LLM orchestration framework.
rune-chain-core is the foundation layer of the rune-chain-* crate family —
a modern, async-first Rust port of the LangChain concept. It defines the shared
vocabulary (types, traits, error variants) that every other rune-chain-* crate
depends on, without pulling in any LLM provider SDK itself.
§Features
Chain— the central trait; implement it to create any unit of LLM workLlm— provider-agnostic interface supporting text generation, streaming, and native function/tool callingTool— async, fallible tool implementations for agent function callingMemory— pluggable conversation history (in-process, DB, vector store, …)Message/Role— typed conversation turns (System, Human, Ai, Tool)MessageContent/ContentPart— multi-modal content (text + images)GenerateResult/TokenUsage— structured output with token accountingToolCall/FunctionDefinition— native function-calling protocolStreamData— incremental token chunks for streaming responsesPromptArgs+prompt_args!— ergonomic key-value input for templatesChainError/LlmError/ToolError— structured error types
§Quick Start
use rune_chain_core::{Chain, ChainError, GenerateResult, PromptArgs, prompt_args};
use async_trait::async_trait;
struct EchoChain;
#[async_trait]
impl Chain for EchoChain {
async fn call(&self, input: PromptArgs) -> Result<GenerateResult, ChainError> {
let text = input
.get("input")
.and_then(|v| v.as_str())
.unwrap_or("")
.to_string();
Ok(GenerateResult::from_text(text))
}
}
let chain = EchoChain;
let result = chain.invoke(prompt_args! { "input" => "hello" }).await.unwrap();
assert_eq!(result, "hello");Macros§
- prompt_
args - Build a
PromptArgsmap from key-value pairs.
Structs§
- Function
Definition - JSON-Schema-based description of a tool the LLM may call.
- Generate
Result - The result of a single LLM generation call.
- Message
- A single turn in a conversation, carrying a
Role, richMessageContent, and optional tool-call metadata for function-calling workflows. - Stream
Data - A single chunk delivered by a streaming LLM response.
- Token
Usage - Token consumption reported by a single LLM generation call.
- Tool
Call - A single tool/function call requested by the model in a generation response.
Enums§
- Chain
Error - Errors produced by a
Chainduring execution. - Content
Part - A single part within a multi-part message content.
- Image
Data - Raw image payload that can be embedded in a message.
- LlmError
- Errors produced by an
Llmduring generation. - Message
Content - The body of a
Message: either plain text or a list of rich content parts. - Role
- The originator of a
Messagein a conversation turn. - Tool
Choice - How the model should choose whether to call a tool.
- Tool
Error - Errors produced by a
Toolduring execution.
Traits§
- Chain
- A composable unit of LLM work that maps
PromptArgsto aGenerateResult. - Llm
- An async interface to a large language model.
- Memory
- Persistent conversation history attached to a
Chain. - Tool
- An LLM-callable tool that an agent can invoke during its reasoning loop.
Type Aliases§
- Prompt
Args - Key-value map of variables substituted into prompt templates.