Library API Overview
Recursive is both a CLI tool and a Rust library. Embed the agent loop directly in your own program when the CLI is not the right shell for your use case.
Adding the dependency
toml
[dependencies]
recursive-agent = "0.6"
tokio = { version = "1", features = ["full"] }Minimal example
rust
use std::sync::Arc;
use recursive::{
runtime::AgentRuntime,
tools::{ApplyPatch, ListDir, ReadFile, RunShell, ToolRegistry, WriteFile},
llm::OpenAiProvider,
};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let llm = Arc::new(OpenAiProvider::new(
"https://api.openai.com/v1",
std::env::var("OPENAI_API_KEY")?,
"gpt-4o-mini",
));
let tools = ToolRegistry::local()
.register(Arc::new(ReadFile::new(".")))
.register(Arc::new(WriteFile::new(".")))
.register(Arc::new(ApplyPatch::new(".")))
.register(Arc::new(ListDir::new(".")))
.register(Arc::new(RunShell::new(".")));
let mut runtime = AgentRuntime::builder()
.llm(llm)
.tools(tools)
.max_steps(20)
.build()?;
let outcome = runtime.run("list the files in src and summarise them").await?;
println!("{}", outcome.final_text.unwrap_or_default());
Ok(())
}Public API surface
The library exposes:
AgentRuntime+AgentRuntimeBuilder— the main entry pointToolRegistry— registers and dispatches toolsLlmProvidertrait — implement your own backendTooltrait — implement your own toolsAgentEvent— subscribe to the event stream via anEventSinkFinishReason— why the agent stoppedMessage,Role— transcript primitivesRuntimeOutcome— what the agent returned
See also:
- Agent Builder — builder options
- Custom Tools — implementing the
Tooltrait - Custom Providers — implementing
LlmProvider - Events & Observers — the
AgentEventstream - Multi-Agent — pools, messaging, orchestration