Skip to main content

Crate rune_chain_core

Crate rune_chain_core 

Source
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 work
  • Llm — provider-agnostic interface to any large language model
  • Memory — pluggable conversation history (in-process, DB, vector store, …)
  • Message / Role — typed conversation turns (System, Human, Ai, Tool)
  • GenerateResult / TokenUsage — structured output with token accounting
  • StreamData — incremental token chunks for streaming responses
  • PromptArgs + prompt_args! — ergonomic key-value input for templates
  • ChainError / LlmError — structured error types with From wiring

§Quick Start

Implement Chain for your own type:

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 PromptArgs map from key-value pairs.

Structs§

GenerateResult
The result of a single LLM generation call.
Message
A single turn in a conversation, carrying a Role and text content.
StreamData
A single chunk delivered by a streaming LLM response.
TokenUsage
Token consumption reported by a single LLM generation call.

Enums§

ChainError
Errors produced by a Chain during execution.
LlmError
Errors produced by an Llm during generation.
Role
The originator of a Message in a conversation turn.

Traits§

Chain
A composable unit of LLM work that maps PromptArgs to a GenerateResult.
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§

PromptArgs
Key-value map of variables substituted into prompt templates.