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::anthropic("claude-sonnet-5", "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. - 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). - 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.
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 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 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.
- mcp
- MCP (Model Context Protocol) client support.
- provider
- retry
- Retry with exponential backoff and jitter for provider calls.
- 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.
- tools
- types