发现 AI 代理的未来

Swiftide

收录于 2026年5月4日
智能体与应用工具
开源
工作流自动化RustRAGAI代理智能体框架SDK智能体与应用工具模型与推理框架开发者工具/代码自动化/工作流/RPA知识管理/检索/RAG

基于 Rust 的流式 LLM 应用开发库,统一数据索引、RAG 查询、智能体与任务图编排。

Swiftide 是由 bosun.ai 组织开发的 Rust LLM 应用开发库,采用管道化范式构建,以 async/parallel 为基础实现高性能流式处理。项目当前处于活跃但快速迭代阶段(v0.32.1),索引管道为核心成熟模块,查询管道与 Agent 框架标记为实验性。

索引管道支持从文件系统、网页、Fluvio、Parquet、Kafka 等数据源加载,经 Markdown/文本/代码切分(Tree-sitter)、LLM 元数据增强(问答对、摘要、标题、代码定义引用)、嵌入后写入 Qdrant、Redis、LanceDB、Postgres 或 DuckDB。管道通过 Loader → Transformer → Storage 的链式 API 组装,支持闭包作为 Transformer、管道拆分合并及缓存过滤。

查询管道采用强类型泛型状态机(Pending → Retrieved → Answered),支持子问题生成、混合检索与上下文组装。Agent 框架通过 #[swiftide::tool] 过程宏声明工具,支持自主循环调用 LLM 与工具、Agent 间协作及命令执行。任务图(Tasks)以图状工作流编排多步骤 LLM 任务。

集成层面采用 feature-gated 设计,所有第三方依赖按需启用。支持 OpenAI、Anthropic、Gemini、Bedrock、Groq、Ollama 等 LLM 提供商;内置 Langfuse 与 OpenTelemetry tracing;支持 Ragas 评估。整体架构通过多 crate workspace 分离核心抽象、索引、查询、Agent、集成与宏,核心 trait 最小化,降低扩展门槛。

安装与上手:

cargo new my-swiftide-app && cd my-swiftide-app
cargo add swiftide
# 在 Cargo.toml 中按需启用 feature flags,如:
# swiftide = { version = "0.32", features = ["openai", "qdrant"] }

索引管道示例:

indexing::Pipeline::from_loader(FileLoader::new(".").with_extensions(&["md"]))
    .with_default_llm_client(openai_client)
    .then_chunk(ChunkMarkdown::from_chunk_range(10..512))
    .then(MetadataQAText::default())
    .then_in_batch(Embed::new(FastEmbed::default()))
    .then_store_with(
        Qdrant::builder()
            .batch_size(50)
            .vector_size(384)
            .collection_name("swiftide-examples")
            .build()?,
    )
    .run().await?;

查询管道示例:

query::Pipeline::default()
    .then_transform_query(GenerateSubquestions::from_client(openai_client.clone()))
    .then_transform_query(Embed::from_client(openai_client.clone()))
    .then_retrieve(qdrant.clone())
    .then_answer(Simple::from_client(openai_client.clone()))
    .query("How can I use the query pipeline in Swiftide?")
    .await?;

Agent 示例:

#[swiftide::tool(
    description = "Searches code",
    param(name = "code_query", description = "The code query")
)]
async fn search_code(
    context: &dyn AgentContext,
    code_query: &str,
) -> Result<ToolOutput, ToolError> {
    let command_output = context
        .executor()
        .exec_cmd(&Command::shell(format!("rg '{code_query}'")))
        .await?;
    Ok(command_output.into())
}

agents::Agent::builder()
    .llm(&openai)
    .tools(vec![search_code()])
    .build()?.query("Find an example of a swiftide agent").await?;

风险提示: 项目标注为"under heavy development",存在 breaking changes 风险;查询管道与 Agent 框架均标注为 Experimental,缺乏版本稳定性承诺或成熟度路线图;未发现官方性能基准测试数据或公开的生产环境使用案例。

保持更新

获取最新的 AI 工具和趋势,直接发送到您的收件箱。没有垃圾邮件,只有智能。