Wesichain

Migration Guide

This guide maps common Python LangChain/LangGraph concepts to Wesichain’s modular Rust crates.

Concept Mapping

Python ecosystemWesichain equivalent
Runnable compositionRunnable<I, O> + .then()
@toolimpl Tool for MyTool
StateGraphGraphBuilder / ReActGraphBuilder
Checkpointer pluginswesichain-checkpoint-* crates
LangSmith tracingwesichain-langsmith
[dependencies]
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
wesichain-core = "0.3.0"
wesichain-llm = "0.3.0"
wesichain-graph = "0.3.0"

# Optional, based on use case:
# wesichain-rag = "0.3.0"
# wesichain-checkpoint-sqlite = "0.3.0"
# wesichain-checkpoint-postgres = "0.3.0"
# wesichain-compat = "0.3.0"

ReAct Migration Pattern

  • Legacy style: monolithic agent executors.
  • Current Wesichain recommendation: build a graph with ReActGraphBuilder and explicit state traits (StateSchema, ScratchpadState, HasUserInput, HasFinalOutput).
use std::sync::Arc;

use wesichain_core::{Tool, ToolCallingLlm};
use wesichain_graph::ReActGraphBuilder;

let llm: Arc<dyn ToolCallingLlm> = Arc::new(my_llm);
let tools: Vec<Arc<dyn Tool>> = vec![Arc::new(SearchTool), Arc::new(CalculatorTool)];

let graph = ReActGraphBuilder::new()
    .llm(llm)
    .tools(tools)
    .build::<AppState>()?;

Graph State Migration Pattern

Use StateSchema::apply (not merge) with an explicit Update type:

use serde::{Deserialize, Serialize};
use wesichain_graph::StateSchema;

#[derive(Clone, Default, Debug, Serialize, Deserialize)]
struct AppState {
    input: String,
    answer: Option<String>,
}

impl StateSchema for AppState {
    type Update = AppState;

    fn apply(current: &Self, update: Self::Update) -> Self {
        Self {
            input: if update.input.is_empty() {
                current.input.clone()
            } else {
                update.input
            },
            answer: update.answer.or_else(|| current.answer.clone()),
        }
    }
}

Practical Advice

  • Start by running existing examples before building custom abstractions.
  • Keep your initial migration modular: core + llm + graph, then add retrieval/checkpoint crates.
  • Use wesichain-compat for incremental migration-oriented workflows.
  • Treat wesichain-agent as the evolving v0.3 runtime track, not the default starting point for stable graph-based projects.

Next Steps

Updated Edit on GitHub