langchain-rust

Library Listed

LangChain for Rust, the easiest way to write LLM-based programs in Rust

Checked · Sources

Downloads
4,306
Dependents
4
Stars
1,362
Forks
179
Contributors
39
Commits
603
Latest release
8.0.0 ·

About

From the project README ·

⚡ Building applications with LLMs through composability, with Rust! ⚡

🤔 What is this?

This is the Rust language implementation of LangChain.

Read the full README

Current Features

Installation

This library heavily relies on serde_json for its operation.

Step 1: Add serde_json

First, ensure serde_json is added to your Rust project.

cargo add serde_json
Step 2: Add langchain-rust

Then, you can add langchain-rust to your Rust project.

Simple install
cargo add langchain-rust
With Sqlite
sqlite-vss

Download additional sqlite_vss libraries from https://github.com/asg017/sqlite-vss

cargo add langchain-rust --features sqlite-vss
sqlite-vec

Download additional sqlite_vec libraries from https://github.com/asg017/sqlite-vec

cargo add langchain-rust --features sqlite-vec
With Postgres
cargo add langchain-rust --features postgres
With SurrialDB
cargo add langchain-rust --features surrealdb
With Weaviate
cargo add langchain-rust --features weaviate
With Milvus
cargo add langchain-rust --features milvus
With Pinecone
cargo add langchain-rust --features pinecone
With Qdrant
cargo add langchain-rust --features qdrant
With Chroma
cargo add langchain-rust --features chroma
With MongoDB (Atlas vector store, chat history on any MongoDB)
cargo add langchain-rust --features mongodb
With Redis (chat history and vector store)
cargo add langchain-rust --features redis

Please remember to replace the feature flags sqlite, postgres or surrealdb based on your specific use case.

This will add both serde_json and langchain-rust as dependencies in your Cargo.toml file. Now, when you build your project, both dependencies will be fetched and compiled, and will be available for use in your project.

Remember, serde_json is a necessary dependencies, and sqlite, postgres and surrealdb are optional features that may be added according to project needs.

Quick Start Conversational Chain
use langchain_rust::{
    chain::{Chain, LLMChainBuilder},
    fmt_message, fmt_placeholder, fmt_template,
    language_models::llm::LLM,
    llm::openai::{OpenAI, OpenAIModel},
    message_formatter,
    prompt::HumanMessagePromptTemplate,
    prompt_args,
    schemas::messages::Message,
    template_fstring,
};

#[tokio::main]
async fn main() {
    //We can then initialize the model:
    // If you'd prefer not to set an environment variable you can pass the key in directly via the `openai_api_key` named parameter when initiating the OpenAI LLM class:
    // let open_ai = OpenAI::default()
    //     .with_config(
    //         OpenAIConfig::default()
    //             .with_api_key("<your_key>"),
    //     ).with_model(OpenAIModel::Gpt4oMini.to_string());
    let open_ai = OpenAI::default().with_model(OpenAIModel::Gpt4oMini.to_string());


    //Once you've installed and initialized the LLM of your choice, we can try using it! Let's ask it what LangSmith is - this is something that wasn't present in the training data so it shouldn't have a very good response.
    let resp = open_ai.invoke("What is rust").await.unwrap();
    println!("{}", resp);

    // We can also guide it's response with a prompt template. Prompt templates are used to convert raw user input to a better input to the LLM.
    let prompt = message_formatter![
        fmt_message!(Message::new_system_message(
            "You are world class technical documentation writer."
        )),
        fmt_template!(HumanMessagePromptTemplate::new(template_fstring!(
            "{input}", "input"
        )))
    ];

    //We can now combine these into a simple LLM chain:

    let chain = LLMChainBuilder::new()
        .prompt(prompt)
        .llm(open_ai.clone())
        .build()
        .unwrap();

    //We can now invoke it and ask the same question. It still won't know the answer, but it should respond in a more proper tone for a technical writer!

    match chain
        .invoke(prompt_args! {
        "input" => "Quien es el escritor de 20000 millas de viaje submarino",
           })
        .await
    {
        Ok(result) => {
            println!("Result: {:?}", result);
        }
        Err(e) => panic!("Error invoking LLMChain: {:?}", e),
    }

    //If you want to prompt to have a list of messages you could use the `fmt_placeholder` macro

    let prompt = message_formatter![
        fmt_message!(Message::new_system_message(
            "You are world class technical documentation writer."
        )),
        fmt_placeholder!("history"),
        fmt_template!(HumanMessagePromptTemplate::new(template_fstring!(
            "{input}", "input"
        ))),
    ];

    let chain = LLMChainBuilder::new()
        .prompt(prompt)
        .llm(open_ai)
        .build()
        .unwrap();
    match chain
        .invoke(prompt_args! {
        "input" => "Who is the writer of 20,000 Leagues Under the Sea, and what is my name?",
        "history" => vec![
                Message::new_human_message("My name is: luis"),
                Message::new_ai_message("Hi luis"),
                ],

        })
        .await
    {
        Ok(result) => {
            println!("Result: {:?}", result);
        }
        Err(e) => panic!("Error invoking LLMChain: {:?}", e),
    }
}
Runs on
GPU support unknown
What shows it
  • no dependency or feature matches a backend row
Native code
Optional
  • Binds native code: tree-sitter (feature tree-sitter), ort-sys (feature fastembed), ring (feature surrealdb), tree-sitter-language (feature tree-sitter)
  • Build uses a native toolchain: cc (feature tree-sitter)
Python bindings
No Python binding crate found
License
MIT

Compare with similar projects

Order: strongest tier first, then most downloads, then name, with unmeasured values last. A library counts downloads over 30 days. An app counts binary downloads per release. An app with none counts its crate downloads over 30 days. ML Rust runs this catalogue, so its closest project always gets a row.

langchain-rust beside the projects that share a topic with it
ProjectDownloadsDependentsStarsLatest releaseRuns on (GPU)Native codeLicense
langchain-rust This page Listed

LangChain for Rust, the easiest way to write LLM-based programs in Rust

4,306 downloads over 30 days 4 1,362 8.0.0 GPU support unknown Binds native code: tree-sitter (feature tree-sitter), ort-sys (feature fastembed), ring (feature surrealdb), tree-sitter-language (feature tree-sitter). Build uses a native toolchain: cc (feature tree-sitter) MIT
rust-mcp-sdk Featured

An asynchronous SDK and framework for building MCP-Servers and MCP-Clients, leveraging the rust-mcp-schema for type safe MCP Schema Objects.

29,764 downloads over 30 days 51 199 2.0.0 GPU support unknown No native code found MIT
yoagent Listed

The agent loop for Rust: stream from 7 LLM protocols, run tools, loop until done. Native or wasm32 (Cloudflare Workers).

2,027 downloads over 30 days 5 369 0.27.4 GPU support unknown No native code found MIT
opencrabs App Listed

The autonomous, self-improving AI agent. Single Rust binary. Every channel. Recommended: the 40MB prebuilt binary for macOS, Linux and Windows: https://github.com/opencrabs/opencrabs/releases

125 binary downloads per release Not applicable 1,027 0.5.15 GPU support unknown Binds native code: libsqlite3-sys, llama-cpp-sys-2, opusic-sys (feature local-tts), tree-sitter (feature code-graph), alsa-sys (feature local-stt) and 1 more MIT
yomo Listed

A QUIC-based runtime for AI-LLM tool routing and serverless execution

26 downloads over 30 days 0 1,930 2.1.6 GPU support unknown No native code found Apache-2.0
edgequake Listed

Rust SDK for the EdgeQuake RAG platform

11 downloads over 30 days 0 2,297 0.4.1 GPU support unknown No native code found Apache-2.0
axp App Listed

An open protocol that gives AI agents a secure, sandboxed place to run code and use tools — with lean context usage. AXP works alongside MCP

Not measured Not applicable 3 Not measured Not measured Not measured Apache-2.0
Why ListedNo archive, New or Featured rule places it, so it is Listed.

What it lacks for Featured

  • It has 0 active dependents and 0 new dependents in 365 days. Featured needs 11 active dependents or 9 new dependents in 365 days. The repository route reads 1,362 stars, 179 forks and 39 contributors. It needs 4,539 stars, 434 forks and 79 contributors together.

What else the check found

  • The last activity is on 3 Nov 2026, 6 days ago. The rules expect an update within 365 days. Dormancy rule

Exact rules: Listed, Featured library. The check on applied thresholds version 9.

Every rule outcome, as the check records it
  • expected-interval: version 8.0.0 base 200, raised to the 365-day floor: E = 365 days
  • dormancy: last activity 2026-11-03, 6 days ago, E = 365: active
  • featured: not featured: active_users 0 < 11 and new_adopters 0 < 9 and repository route stars 1362 (needs 4539), forks 179 (needs 434), contributors 39 (needs 79)
  • listed: listed: no archive, new or featured rule applies

Measurements and sources

Each signal row shows the raw value, its source and the fetch date. The Sources list gathers every distinct source on this page. Movement needs more history.

Sources6 sources
Adoption0 active dependents, 0 new dependents in 365 days1 not measured
Adoption measurements
SignalValueSourceFetchedCounts
Active dependents0crates.io database dumpYes
New dependents (365 days)0crates.io database dumpYes
Peak active dependents4crates.io database dumpYes
Active dependents as a share of the peak0.925crates.io database dumpYes
Binary downloads per releaseNot measuredYes
MaintenanceLatest human commit: 6 days ago3 not measured
Maintenance measurements
SignalValueSourceFetchedCounts
Latest human commit2026-11-03GitHub repositoryYes
Latest release2026-11-03crates.io database dumpYes
First release2024-04-16crates.io database dumpYes
Latest version8.0.0crates.io database dumpYes
Days the oldest outside issue waits for a reply0GitHub repositoryYes
Maintainer replies over 365 days52GitHub repositoryYes
Repository archivedfalseGitHub repositoryYes
Repository gonefalseGitHub repositoryYes
Release commit or manifest in the repotruecrates.io packageYes
Published docstruecrates.io database dumpYes
Latest release fails cargo checkNot measuredYes
Build check dateNot measuredYes
Build check toolchainNot measuredYes
SecurityUnpatched vulnerabilities: none
Security measurements
SignalValueSourceFetchedCounts
Unpatched vulnerabilities past the grace windownoneRustSec advisory databaseYes
RustSec unmaintained advisorynoneRustSec advisory databaseYes
Deprecation noticenonecrates.io database dumpYes
Deprecated requirementnonecrates.io database dumpYes
Distribution23 releases, 4,306 downloads over 30 days5 not measured
Distribution measurements
SignalValueSourceFetchedCounts
Releases23crates.io database dumpYes
Downloads over 30 days4306crates.io database dumpYes
Binary downloads over the last 3 releasesNot measuredYes
Homebrew installs on request over 365 daysNot measuredYes
Repology repository familiesNot measuredYes
Docker pull growth over 90 daysNot measuredYes
Docker pulls at the growth baselineNot measuredYes
Every version a prereleasefalsecrates.io database dumpYes
Every version 0.0.xfalsecrates.io database dumpYes
Every version yankedfalsecrates.io database dumpYes
Crate deleted from crates.iofalsecrates.io database dumpYes
Repository1,362 stars, 179 forks, 39 contributors, 603 commits. Stars alone never qualify a project.
Repository measurements
SignalValueSourceFetchedCounts
GitHub stars1362GitHub repositoryYes — one part of the repository route
GitHub forks179GitHub repositoryYes — one part of the repository route
Contributors with a GitHub account39GitHub contributorsYes — one part of the repository route
Commits on the default branch603GitHub repositoryNo
Repository's main crate left out of the entrynonecrates.io database dumpYes
Facts that never count
Facts that never count measurements
SignalValueSourceFetchedCounts
LicenseMITcrates.io database dumpNo
Runs on, from listed crates and their direct dependenciesGPU support unknowncrates.io database dumpNo
What shows each backendno dependency or feature matches a backend rowcrates.io database dumpNo
Native code, from listed crates and their dependenciesBinds native code: tree-sitter (feature tree-sitter), ort-sys (feature fastembed), ring (feature surrealdb), tree-sitter-language (feature tree-sitter). Build uses a native toolchain: cc (feature tree-sitter)crates.io database dumpNo
Python bindings, from direct dependencies of listed cratesNo Python binding crate foundcrates.io database dumpNo
Crates that depend on a listed crate directly4crates.io database dumpNo

Corrections and review history

Report a correction

No correction applies to this entry.

Judgments

A judgment enters only through an approved issue and a merged pull request.

No judgment applies to this entry.