This document covers library embedding and extension points. For build/test/release commands, use docs/developer/BUILD.md.
cargo run -- exec "your prompt here"
cargo run
cargo run -- --trace /tmp/buddy.trace.jsonl
cargo run -- -vv# Structured logs + runtime JSONL trace together
cargo run -- -vv --trace /tmp/buddy.trace.jsonl
# Target a single component with explicit filter expression
BUDDY_LOG=buddy::runtime=trace cargo run
# Use standard Rust log env var when preferred
RUST_LOG=buddy::agent=debug cargo run -- -vPrompt iteration with real models:
make prompt-eval MODEL=<profile> PROMPTS=<file>See docs/developer/prompt-evals.md for the full trace-backed workflow.
Add to your Cargo.toml:
[dependencies]
buddy = { path = "../buddy" }Then in your code:
use buddy::agent::Agent;
use buddy::config::load_config;
use buddy::tools::execution::ExecutionContext;
use buddy::tools::shell::ShellTool;
use buddy::tools::ToolRegistry;
#[tokio::main]
async fn main() {
let config = load_config(None).unwrap();
let execution = ExecutionContext::local();
let mut tools = ToolRegistry::new();
tools.register(ShellTool {
confirm: true,
denylist: vec!["rm -rf /".to_string(), "mkfs".to_string()],
color: true,
execution: execution.clone(),
approval: None,
});
let mut agent = Agent::new(config, tools);
let response = agent.send("Hello!").await.unwrap();
println!("{response}");
}use async_trait::async_trait;
use buddy::error::ToolError;
use buddy::tools::{Tool, ToolContext};
use buddy::types::{FunctionDefinition, ToolDefinition};
struct MyTool;
#[async_trait]
impl Tool for MyTool {
fn name(&self) -> &'static str {
"my_tool"
}
fn definition(&self) -> ToolDefinition {
ToolDefinition {
tool_type: "function".into(),
function: FunctionDefinition {
name: "my_tool".into(),
description: "Does something useful.".into(),
parameters: serde_json::json!({"type": "object", "properties": {}}),
},
}
}
async fn execute(
&self,
arguments: &str,
_context: &ToolContext,
) -> Result<String, ToolError> {
let _ = arguments;
Ok("result".into())
}
}An alternate frontend can be built against the runtime actor/event API:
cargo run --example alternate_frontend -- "list files"- Model transport/runtime integration:
src/api/mod.rsexposesModelClient.src/runtime/{schema,mod}.rsexposes runtime command/event channels.
- Tools:
- implement
Toolinsrc/tools/mod.rs - register tools in
src/app/entry.rs(build_tools) - shared execution backends are in
src/tools/execution/*
- implement
- Terminal/runtime rendering:
src/ui/render.rsexposesRenderSinksrc/ui/runtime/*converts runtime events to render actionssrc/repl/*contains shared REPL/runtime helper state
- Config/auth:
src/config/*handles layered config loading and profile resolutionsrc/auth/*handles provider login flows and encrypted credential storage
- High-level: docs/design/DESIGN.md
- Detailed module map: docs/design/module-map.md
- Runtime/protocol behavior: docs/design/runtime-and-protocols.md
- Tool/execution contracts: docs/design/tools-and-execution.md