大家好,向大家介绍一下我最近在做的开源项目:Juncture。
Juncture 是 LangGraph 的 Rust 实现。LangGraph 是目前 Python 生态中最流行的图驱动智能体编排框架之一,Juncture 的目标是将其核心编程模型(StateGraph + Pregel 执行引擎)完整移植到 Rust,同时借助 Rust 的类型系统实现编译期安全和真正的多核并行。
核心设计
编译期类型化状态:通过 #[derive(State)] 过程宏,自动生成类型安全的 State/Update 结构体对,支持逐字段的 Reducer 语义(replace、append、ephemeral、last_write_wins、custom):
#[derive(State, Clone, Debug, Serialize, Deserialize)]
struct MyState {
#[reducer(replace)]
count: i32,
#[reducer(append)]
history: Vec<String>,
}
Pregel 执行引擎:基于 tokio::spawn + JoinSet 实现真正的并行执行,配合 CowState<S>(Arc-based 写时复制)避免昂贵的状态克隆。
功能覆盖:HITL(人机协作)、子图、Send 动态扇出、9 种流式模式、检查点持久化(Memory/SQLite/Postgres)、跨线程键值存储、LLM 集成(OpenAI/Anthropic/Ollama)、ReAct 智能体工厂等。
基准测试
空操作节点上的框架开销对比:
| 场景 | Juncture (Rust) | LangGraph (Python) | 加速比 |
|---|---|---|---|
| 顺序执行 3000 节点 | 16.9 ms | 7,652 ms | 452x |
| 流式 10000 节点 | 142.7 ms | 78,085 ms | 547x |
| 扇出 100 主题 | 1.35 ms | 566 ms | 420x |
| 宽状态 1200 迭代 | 95.4 ms | 3,593 ms | 38x |
| 条件路由 50 分支 | 0.7 ms | 3.9 ms | 5.6x |
这些反映的是框架开销,实际 LLM 调用占主导,框架差异在实践中可忽略。Rust 的价值更多在类型安全、内存效率和部署灵活性。
可观测性
内嵌了 Langfuse 兼容的可观测性引擎(juncture-telemetry),一行初始化即可启用本地 Web 仪表盘,支持 trace 树、token/cost 图表、Langfuse 云端导出和 OTLP 接入。
init()
.with_store("db")
.with_langfuse_from_env()
.with_dashboard(8123)
.install()
.await?;
WASM 支持
- 浏览器(
wasm32-unknown-unknown)通过wasm-bindgen - 边缘 CLI(
wasm32-wasip1)通过 WASI - 边缘 HTTP 服务通过 Fermyon Spin
工作空间结构
7 个 crate + benchmarks + examples(16 个渐进式示例 + 多智能体深度研究应用 + WASM 演示):
crates/juncture/ # 门面 crate -- LLM 提供商、工具、预构建智能体
crates/juncture-core/ # Channel 系统、StateGraph、Pregel 引擎
crates/juncture-derive/ # #[derive(State)] 过程宏
crates/juncture-checkpoint/ # MemorySaver、SqliteSaver、PostgresSaver
crates/juncture-tracing/ # OpenTelemetry 集成
crates/juncture-telemetry/ # Langfuse 兼容内嵌可观测性
crates/juncture-store/ # 跨线程持久化键值存储
快速体验
[dependencies]
juncture = "0.1"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
serde = { version = "1", features = ["derive"] }
use juncture::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(State, Clone, Debug, Serialize, Deserialize)]
struct MyState {
#[reducer(replace)]
count: i32,
#[reducer(append)]
history: Vec<String>,
}
async fn increment(state: &MyState) -> Result<MyState::Update> {
Ok(MyStateUpdate {
count: Some(state.count + 1),
history: Some(vec![format!("count -> {}", state.count + 1)]),
})
}
#[tokio::main]
async fn main() -> Result<()> {
let mut graph = StateGraph::<MyState>::new();
graph.add_node("increment", increment);
graph.add_edge(START, "increment");
graph.add_edge("increment", END);
let compiled = graph.compile()?;
let result = compiled
.invoke(MyState { count: 0, history: vec![] }, &RunnableConfig::default())
.await?;
println!("Result: {:?}", result);
Ok(())
}
项目状态
早期阶段。已实现 LangGraph Python 的核心功能子集,API 设计尽量贴近原版,方便熟悉 LangGraph 的开发者直接迁移。
欢迎试用和反馈:https://github.com/greatwallisme/juncture
Ext Link: https://github.com/greatwallisme/juncture
评论区
写评论还没有评论