-
Notifications
You must be signed in to change notification settings - Fork 0
Examples
The repository keeps runnable examples under examples/. Run all commands from
the repository root.
cargo run --example basic_graphThe core shape is:
use tinyagents::graph::END;
use tinyagents::harness::message::Message;
use tinyagents::{GraphBuilder, NodeContext, NodeResult, Result};
#[derive(Clone, Debug)]
struct AgentState {
messages: Vec<Message>,
needs_tool: bool,
}
#[tokio::main]
async fn main() -> Result<()> {
let graph = GraphBuilder::<AgentState, AgentState>::overwrite()
.add_node("agent", |mut state: AgentState, _ctx: NodeContext| async move {
state.messages.push(Message::assistant("I should check the local tool."));
Ok(NodeResult::Update(state))
})
.add_node("tool", |mut state: AgentState, _ctx: NodeContext| async move {
state.messages.push(Message::tool("echo", "tool result"));
state.needs_tool = false;
Ok(NodeResult::Update(state))
})
.set_entry("agent")
.add_conditional_edges(
"agent",
|state: &AgentState| {
if state.needs_tool { "tool".to_string() } else { "done".to_string() }
},
[("tool", "tool"), ("done", END)],
)
.add_edge("tool", "agent")
.compile()?;
let run = graph
.run(AgentState {
messages: vec![Message::user("Can you use a tool?")],
needs_tool: true,
})
.await?;
println!("visited: {:?}", run.visited);
Ok(())
}Use this example when you want graph behavior without a live model provider.
export OPENAI_API_KEY=...
cargo run --features openai --example openai_chatThis registers an OpenAiModel in AgentHarness, sets it as the default model,
and sends one user message through the harness.
export OPENAI_API_KEY=...
cargo run --features openai --example openai_graph_agentThis composes the harness and graph runtime: a graph node invokes an
OpenAI-backed harness, stores the answer in graph state, and then routes to
END.
export OPENAI_API_KEY=...
cargo run --features openai --example openai_toolsThe harness exposes a local typed tool to the model. The model requests the tool, the harness executes it, and the tool result is fed back into the model loop.
export OPENAI_API_KEY=...
cargo run --features openai --example openai_structuredThis demonstrates schema-constrained model output and the harness-side structured extraction path.
export OPENAI_API_KEY=...
cargo run --features openai --example openai_self_blueprintThe model emits .rag source, TinyAgents parses and compiles it, the registry
binds referenced capabilities, and the resulting graph is executed through the
same runtime as Rust-built graphs.
Recursive language-model (RLM) harness for Rust.
Getting started
Concepts
Modules
Providers
Contributing