Expand description
Agent Chain Core - A Rust implementation of LangChain core library.
This crate provides:
- Message types for LLM conversations (human, AI, system, tool)
- Tool trait and
#[tool]macro for function calling - Chat model abstractions and provider integrations
- Support for multiple providers (Anthropic, OpenAI, etc.)
§Architecture
The architecture follows LangChain’s pattern:
- Core layer ([
chat_model]): BaseChatModeltrait that all providers implement - Message layer (
messages): Message types for conversations - Tools layer (
tools): Tool definitions and the#[tool]macro
§Quick Start
ⓘ
use agent_chain_core::{init_chat_model, HumanMessage};
// Initialize a model - provider is inferred from name
let model = init_chat_model("claude-sonnet-4-5-20250929", None)?;
// Or specify explicitly
let model = init_chat_model("my-custom-model", Some("openai"))?;
// Use the model
let messages = vec![HumanMessage::new("Hello!").into()];
let response = model.generate(messages, None).await?;§Feature Flags
default: Includes all providersspecta: Specta derive support
Re-exports§
pub use error::Error;pub use error::Result;pub use chat_models::BoundChatModel;pub use chat_models::ChatChunk;pub use chat_models::ChatModel;pub use chat_models::ChatModelExt;pub use chat_models::ChatResult;pub use chat_models::ChatResultMetadata;pub use chat_models::ChatStream;pub use chat_models::DynBoundChatModel;pub use chat_models::DynChatModelExt;pub use chat_models::LangSmithParams;pub use chat_models::ToolChoice;pub use chat_models::UsageMetadata;pub use messages::AIMessage;pub use messages::AnyMessage;pub use messages::BaseMessage;pub use messages::ContentPart;pub use messages::HasId;pub use messages::HumanMessage;pub use messages::ImageDetail;pub use messages::ImageSource;pub use messages::MessageContent;pub use messages::SystemMessage;pub use messages::ToolCall;pub use messages::ToolMessage;pub use tools::Tool;pub use tools::ToolDefinition;
Modules§
- chat_
models - Core ChatModel trait and related types.
- error
- Error types for agent-chain.
- messages
- Message types for LLM interactions.
- tools
- Tools module for LLM function calling.
Attribute Macros§
- async_
trait - tool
- Marks a function as a tool that can be used by an LLM.