Expand description
yoagent — the agent runtime for Rust.
A simple, effective agent loop with tool execution and event streaming:
Prompt → LLM stream → tool execution → loop. The loop is the product;
everything else is optional layers on top of it.
§Quick start
use yoagent::{Agent, provider::ModelConfig, tools};
// Provider is selected from the config's protocol; the API key is read
// from ANTHROPIC_API_KEY. Call `.with_api_key(...)` to override.
let mut agent = Agent::from_config(ModelConfig::claude_sonnet_5())
.with_system_prompt("You are a helpful coding assistant.")
.with_tools(tools::default_tools());
let mut events = agent.prompt("List the files in the current directory").await;
while let Some(event) = events.recv().await {
// stream text deltas, tool calls, usage — render however you like
}
agent.finish().await;§What’s in the box
- The loop (
agent_loop()) — a stateless free function;Agentis an optional stateful wrapper (history, tool registry, steering queues). - 7 provider protocols, 20+ providers (
provider) — Anthropic, OpenAI (Completions + Responses), Azure, Gemini, Vertex, Bedrock, plus OpenAI-compatible gateways (Groq, DeepSeek, xAI, OpenCode, Ollama, …) with per-provider quirk flags. - Tools (
tools) — bash, read/write/edit file, search; add your own via theAgentTooltrait. MCP servers and OpenAPI specs (featureopenapi) become tools transparently. AToolSourcesupplies tools resolved at the start of every run, for tool sets that change while the agent lives (plugins, reconnecting servers). - Steering — inject guidance into a running agent (
Agent::steer); picked up between tool executions (per batch under the default parallel strategy). Queue follow-ups, inspect/edit the queues. - Structured outputs (
Agent::prompt_structured) — typed, schema-validated replies, enforced natively where supported (forced tool call /json_schema/responseSchema). - Permissions (
ToolMiddleware) — async approve/deny/modify hooks gating every tool call; the mechanism behind approval prompts and policy engines (yoagent ships no policy — you install it). - Input filtering (
InputFilter,AsyncInputFilter) — rewrite or reject user input before it reaches the model (PII redaction, prompt-injection guards). - Turn hooks (
TurnHook) — an async hook before every LLM request that may add one transient note to the request’s latest user turn. - Decision models (feature
decision) — typed questions (yes/no, choice, score) answered with calibrated probabilities, e.g. TypeSafe’s Jev, or any OpenAI-compatible LLM that returns logprobs; fallbacks and calibration; advisory skill/tool hints, and an opt-in, fail-closed tool gate and input guard. Off by default; nothing is sent until you pick a model. - Sub-agents (
SubAgentTool) — delegation with per-sub-agent models andSharedStatefor passing artifacts by reference. - GASP (feature
gasp) — record runs into a GASP agent repo: append-only semantic event log, restore = clone + replay, conformance-checked in CI. - Session trees (
Session) — branching conversation history with fork, checkpoints, and JSONL persistence; edit an earlier turn and re-run without losing the original branch. - Context management (
context) — token tracking and tiered compaction so long sessions keep running. - Skills (
skills) — loadSKILL.mdfiles per the AgentSkills standard. - Telemetry —
tracingspans per loop/LLM-stream/tool with token and cost fields; bridge to OpenTelemetry app-side, negligible cost otherwise. - Testing (
provider::mock::MockProvider) — script a whole multi-turn tool-calling conversation with no network. It honours the cancellation token, so abort and steering paths are testable too.
The book covers concepts and provider-specific guides.
Re-exports§
pub use agent::Agent;pub use agent::AgentBuildError;pub use agent::StructuredPromptError;pub use agent_loop::agent_loop;pub use agent_loop::agent_loop_continue;pub use context::CompactionStrategy;pub use context::DefaultCompaction;pub use extension::Extension;pub use extension::ExtensionMode;pub use extension::RunHooks;pub use llm_compaction::LlmCompaction;pub use retry::RetryConfig;pub use session::Session;pub use session::SessionEntry;pub use session::SessionError;pub use skills::SkillSet;pub use sub_agent::SubAgentTool;pub use tool_source::ToolSource;pub use types::*;
Modules§
- agent
- Stateful Agent struct — wraps the agent loop with state management, steering/follow-up queues, and abort support.
- agent_
loop - The core agent loop: prompt → LLM stream → tool execution → repeat.
- context
- Context window management — smart truncation and token counting.
- decision
decision - Decision models: typed questions in, calibrated probabilities out.
- extension
- Extensions: one plug-in contract for the agent lifecycle (#241).
- gasp
gasp - GASP bridge — record agent runs into a GASP
agent repo (feature
gasp). - llm_
compaction - LLM-based background compaction — a
CompactionStrategythat summarizes old history with a standalone LLM request instead of discarding it. - mcp
- MCP (Model Context Protocol) client support.
- openapi
openapi - OpenAPI tool adapter — auto-generate
AgentToolimplementations from OpenAPI specs. - provider
- retry
- Retry with exponential backoff and jitter for provider calls.
- rt
- Task and timer facilities that work on every target yoagent builds for.
- session
- Conversation session trees — branching history with checkpoints.
- shared_
state - Shared key-value state for sub-agent communication.
- skills
- Skills — load AgentSkills-compatible skill directories and inject into system prompts.
- sub_
agent - Sub-agent tool — delegates tasks to a child agent loop.
- tool_
source - Tools resolved per run.
- tools
- Built-in tools. The filesystem and shell tools need a native host (the
nativefeature);SharedStateToolworks everywhere. - types