Fast, streaming indexing, query, and agentic LLM applications in Rust
翻译准备中
取自仓库 README
正在加载完整 README。
查看完整 README ↗Swiftide is an opinionated framework for building LLM applications. It gives you an agent harness, typed task graphs for orchestration, and streaming, composable indexing/query pipelines for RAG.
Tool implementations, or MCP servers.tracing, metrics, and Langfuse support.The core primitives provide the shared interaction model. Around them, use pipelines for data flows, agents for tool loops, and tasks for graphs of typed hand-offs.
Swiftide keeps default dependencies light. Start with the agent harness and add the integrations your application needs.
cargo add swiftide --features swiftide-agents,openai
cargo add anyhow
cargo add tokio --features macros,rt-multi-thread
If using OpenAI, set the API key expected by the OpenAI-compatible integration:
export OPENAI_API_KEY=...
Swiftide provides a harnass for building (semi) autonomous agents. The harnass owns message history, call an LLM, invoke tools, run hooks, and stopping. Tools are pure functions and easy to add. The AgentContext abstracts over message history (in memory by default) and provides tools access to the outside world via a ToolExecutor (local by default, see also the docker executor).
use anyhow::Result;
use swiftide::{
agents,
chat_completion::{ToolOutput, errors::ToolError},
traits::AgentContext,
};
#[swiftide::tool(
description = "Looks up a Swiftide concept",
param(name = "concept", description = "Concept to explain")
)]
async fn explain_concept(
_context: &dyn AgentContext,
concept: &str,
) -> Result<ToolOutput, ToolError> {
let explanation = match concept {
"tasks" => "Tasks compose typed nodes into explicit workflows.",
"agents" => "Agents run LLM completions, tools, hooks, and stop conditions.",
"pipelines" => "Pipelines stream data through indexing and retrieval steps.",
_ => "Swiftide composes agents, task graphs, tools, and RAG pipelines.",
};
Ok(explanation.into())
}
#[tokio::main]
async fn main() -> Result<()> {
let openai = swiftide::integrations::openai::OpenAI::builder()
.default_prompt_model("gpt-4o-mini")
.build()?;
agents::Agent::builder()
.llm(&openai)
.tools([explain_concept()])
.on_new_message(|_, message| {
println!("{message}");
Box::pin(async { Ok(()) })
})
.limit(8)
.build()?
.query("Explain Swiftide tasks and agents in one paragraph.")
.await?;
Ok(())
}
The agent calls the model, exposes explain_concept as a tool, prints new messages, and stops
within the configured turn limit. By default all agents have a tool to stop the loop. This can be customized.
Agent capabilities include:
#[swiftide::tool], derived tools, or manual Tool implementationsToolExecutor implementations for command/file accessApprovalRequired and feedback-aware contextsStart with examples/hello_agents.rs,
then look at the human approval, MCP, streaming, resume, and structured-output examples.
Tasks are Swiftide's orchestration layer. A task is a typed graph of TaskNode steps. Each node has
an input type, output type, and error type; transitions decide where the output goes next.
Tasks are strongly typed at build time. It allows you to compose agents, other swiftide components, and functions to create complex automations.
From examples/tasks.rs.
use swiftide::{
prompt::Prompt,
tasks::{Task, TaskRunOutcome, Transition},
traits::SimplePrompt,
};
use std::sync::Arc;
let prompt_model: Arc<dyn SimplePrompt> = Arc::new(openai.clone());
let briefing_agent = BriefingAgent::new(agent);
let mut task: Task<Prompt, String> = Task::new();
let brief = task.register_node(prompt_model.clone());
let decide = task.register_node(briefing_agent);
let render = task.register_node(prompt_model);
task.starts_with(brief);
task.register_transition(brief, move |short_brief| {
decide.transitions_with(short_brief)
})?;
task.register_transition(decide, move |decision: BriefingDecision| {
Transition::next(
&render,
Prompt::from("Write a hand-off note for {{audience}}: {{summary}}")
.with_context_value("audience", decision.audience)
.with_context_value("summary", decision.summary),
)
})?;
task.register_transition(render, task.transitions_to_finish())?;
match task.run(Prompt::from("Summarize the rollout plan")).await? {
TaskRunOutcome::Completed(note) => println!("{note}"),
TaskRunOutcome::Paused => println!("Task paused"),
}
Task capabilities include:
TaskNode implementations for domain logicNodeId handles, transitions, and join payloadsTaskAgent for the simple case where an agent should run as a task nodeSee examples/tasks.rs for a
prompt plus custom agent workflow, and
examples/tasks_fanout.rs
for fan-out and join.
Swiftide includes first-class indexing and querying pipelines for retrieval-augmented generation. Pipelines are streaming and composable: load data, transform it, embed it, cache it, store it, then retrieve and answer with a typed query flow.
use swiftide::{
indexing::{self, loaders::FileLoader, transformers::{ChunkCode, Embed, MetadataQACode}},
integrations::qdrant::Qdrant,
};
async fn index(openai: swiftide::integrations::openai::OpenAI) -> anyhow::Result<()> {
let qdrant = Qdrant::builder()
.collection_name("swiftide-code")
.vector_size(1536)
.batch_size(50)
.build()?;
indexing::Pipeline::from_loader(FileLoader::new(".").with_extensions(&["rs"]))
.with_default_llm_client(openai.clone())
.then_chunk(ChunkCode::try_for_language_and_chunk_size("rust", 10..2048)?)
.then(MetadataQACode::default())
.then_in_batch(Embed::new(openai))
.then_store_with(qdrant)
.run()
.await?;
Ok(())
}
Indexing supports loaders, caches, chunkers, transformers, batch transformers, embedders, and storage backends. Query pipelines support query transformation, retrieval, response transformation, answer generation, hybrid search, reranking patterns, and evaluation.
Swiftide integrations are feature-gated so application builds stay intentional.
| Area | Supported integrations |
|---|---|
| LLM providers | OpenAI and Azure OpenAI, Anthropic, Gemini, OpenRouter, AWS Bedrock Converse API, Groq, Ollama, Dashscope |
| Tooling | MCP toolboxes, local command execution, custom tool executors |
| Storage and retrieval | Qdrant, Redis, LanceDB, PgVector, DuckDB, Redb |
| Loading data | Files, scraping, Fluvio, Kafka, Parquet, executor-backed file streams |
| Code and text processing | Markdown, text splitting, tree-sitter code chunking and metadata |
| Observability | tracing, metrics, Langfuse |
The examples has a variety of examples.
hello_agents.rs,
streaming_agents.rs,
agents_with_human_in_the_loop.rs,
agents_mcp_tools.rsstop_with_args_custom_schema.rs,
agent_can_fail_custom_schema.rstasks.rs,
tasks_fanout.rsindex_codebase.rs,
query_pipeline.rs,
hybrid_search.rsresponses_api.rs,
responses_api_reasoning.rs,
,
More background is available on the Bosun blog, including posts about tasks, streaming agents, human-in-the-loop flows, and Rust performance for AI tools.
Swiftide is pre-1.0. APIs can change while the agent harness and task graph APIs settle around production use. The current API docs and examples are the most reliable source of exact signatures.
Swiftide is part of the bosun.ai project.
Contributions are welcome. Read CONTRIBUTING.md, open an issue for design discussion, file a bug report, or propose a feature. Join the Discord for a faster feedback loop.
Before opening a pull request:
cargo +nightly fmt --all -- --check.cargo clippy --workspace --all-targets --all-features -- -D warnings when touching shared behavior.AI-generated code is welcome and should be reviewed like any other code. Keep abstractions small, keep domain logic separate from plumbing, and pay attention to allocations in indexing, querying, and task execution paths.
AI agents can refer to AGENTS.md for workspace layout, commands, and expectations.
Distributed under the MIT License. See LICENSE for more information.