yoagent/lib.rs
1// Enables the `doc_cfg` feature badges on docs.rs only; a no-op on stable.
2#![cfg_attr(docsrs, feature(doc_cfg))]
3
4//! **yoagent** — the agent runtime for Rust.
5//!
6//! A simple, effective agent loop with tool execution and event streaming:
7//! `Prompt → LLM stream → tool execution → loop`. The loop is the product;
8//! everything else is optional layers on top of it.
9//!
10//! # Quick start
11//!
12//! ```no_run
13//! use yoagent::{Agent, provider::ModelConfig, tools};
14//!
15//! # #[tokio::main]
16//! # async fn main() {
17//! // Provider is selected from the config's protocol; the API key is read
18//! // from ANTHROPIC_API_KEY. Call `.with_api_key(...)` to override.
19//! let mut agent = Agent::from_config(ModelConfig::anthropic("claude-sonnet-5", "Sonnet 5"))
20//! .with_system_prompt("You are a helpful coding assistant.")
21//! .with_tools(tools::default_tools());
22//!
23//! let mut events = agent.prompt("List the files in the current directory").await;
24//! while let Some(event) = events.recv().await {
25//! // stream text deltas, tool calls, usage — render however you like
26//! }
27//! agent.finish().await;
28//! # }
29//! ```
30//!
31//! # What's in the box
32//!
33//! - **The loop** ([`agent_loop()`](agent_loop())) — a stateless free function; [`Agent`] is an
34//! optional stateful wrapper (history, tool registry, steering queues).
35//! - **7 provider protocols, 20+ providers** ([`provider`]) — Anthropic,
36//! OpenAI (Completions + Responses), Azure, Gemini, Vertex, Bedrock, plus
37//! OpenAI-compatible gateways (Groq, DeepSeek, xAI, OpenCode, Ollama, ...)
38//! with per-provider quirk flags.
39//! - **Tools** ([`tools`]) — bash, read/write/edit file, search; add your own
40//! via the [`AgentTool`] trait. [MCP](mcp) servers and
41//! [OpenAPI specs](https://docs.rs/yoagent/latest/yoagent/openapi/index.html)
42//! (feature `openapi`) become tools transparently.
43//! - **Steering** — inject guidance into a running agent ([`Agent::steer`]);
44//! picked up between tool executions (per batch under the default parallel
45//! strategy). Queue follow-ups, inspect/edit the queues.
46//! - **Structured outputs** ([`Agent::prompt_structured`]) — typed,
47//! schema-validated replies, enforced natively where supported (forced
48//! tool call / `json_schema` / `responseSchema`).
49//! - **Permissions** ([`ToolMiddleware`]) — async approve/deny/modify hooks
50//! gating every tool call; the mechanism behind approval prompts and
51//! policy engines (yoagent ships no policy — you install it).
52//! - **Input filtering** ([`InputFilter`]) — rewrite or reject user input
53//! before it reaches the model (PII redaction, prompt-injection guards).
54//! - **Sub-agents** ([`SubAgentTool`]) — delegation with per-sub-agent models
55//! and [`SharedState`] for passing artifacts by reference.
56//! - **GASP** (feature `gasp`) — record runs into a
57//! [GASP](https://github.com/yologdev/gasp) agent repo: append-only
58//! semantic event log, restore = clone + replay, conformance-checked in CI.
59//! - **Session trees** ([`Session`]) — branching conversation history with
60//! fork, checkpoints, and JSONL persistence; edit an earlier turn and
61//! re-run without losing the original branch.
62//! - **Context management** ([`context`]) — token tracking and tiered
63//! compaction so long sessions keep running.
64//! - **Skills** ([`skills`]) — load `SKILL.md` files per the
65//! [AgentSkills](https://agentskills.io) standard.
66//! - **Telemetry** — `tracing` spans per loop/LLM-stream/tool with token and
67//! cost fields; bridge to OpenTelemetry app-side, negligible cost otherwise.
68//! - **Testing** ([`provider::mock::MockProvider`]) — script a whole multi-turn
69//! tool-calling conversation with no network. It honours the cancellation
70//! token, so abort and steering paths are testable too.
71//!
72//! The [book](https://yologdev.github.io/yoagent/) covers concepts and
73//! provider-specific guides.
74
75pub mod agent;
76pub mod agent_loop;
77pub mod context;
78pub mod mcp;
79pub mod provider;
80pub mod retry;
81pub mod session;
82pub mod shared_state;
83pub mod skills;
84pub mod sub_agent;
85pub mod tools;
86pub mod types;
87
88#[cfg(feature = "openapi")]
89#[cfg_attr(docsrs, doc(cfg(feature = "openapi")))]
90pub mod openapi;
91
92#[cfg(feature = "gasp")]
93#[cfg_attr(docsrs, doc(cfg(feature = "gasp")))]
94pub mod gasp;
95
96pub use agent::{Agent, AgentBuildError, StructuredPromptError};
97pub use agent_loop::{agent_loop, agent_loop_continue};
98pub use context::{CompactionStrategy, DefaultCompaction};
99pub use retry::RetryConfig;
100pub use session::{Session, SessionEntry, SessionError};
101pub use shared_state::SharedState;
102pub use skills::SkillSet;
103pub use sub_agent::SubAgentTool;
104pub use types::*;