yoagent

The agent loop for Rust. Stream from any of 7 LLM protocols, run tools, loop until done.

yoagent is a library for building LLM-powered agents that use tools. It provides the core loop — prompt the model, execute tool calls, feed results back — and gets out of your way.

The yoagent loop

Philosophy

The loop is the product. An agent is just a loop: send messages to an LLM, get back text and tool calls, execute the tools, repeat until the model stops. yoagent implements that loop with streaming, cancellation, context management, and multi-provider support — and stops there.

agent_loop() is a stateless free function that takes everything it needs as arguments. Agent is an optional wrapper that adds message history, a tool registry, and steering queues. You can drive the loop yourself without adopting our state model.

Try it without an API key

git clone https://github.com/yologdev/yoagent && cd yoagent
ollama serve &
cargo run --example cli -- --provider ollama

A working coding agent in your terminal — file read/write/edit, shell, ripgrep search, streaming output, and skills.

What's here

The loop and its control surfaces

  • The agent loop — how a turn runs, and how steering and follow-ups interrupt it
  • Messages and events — the full AgentEvent stream for text deltas, thinking, and tool execution
  • Tool middleware — async allow / modify / deny hooks gating every tool call
  • Lifecycle callbacks plus execution limits (max turns, tokens, wall-clock) and CancellationToken abort
  • Retry with exponential backoff and jitter, for rate-limit and network errors only

Models and tools

  • 7 API protocols, 20+ providers — Anthropic, OpenAI Completions and Responses, Azure, Gemini, Vertex, Bedrock, plus OpenAI-compatible gateways, each with a real implementation rather than a shared shim
  • Built-in tools — bash, file read/write/edit, list, ripgrep search; add your own via the AgentTool trait
  • MCP servers and OpenAPI specs become tools transparently
  • Structured outputs — typed, schema-validated replies enforced natively where the provider supports it
  • Prompt caching

Scaling a session

  • Sub-agents and shared state — delegate to child loops with their own model, tools, and limits; sub-agents read large artifacts by key instead of re-pasting them into every context window
  • Context management — token tracking and tiered compaction (truncate tool outputs → summarise old turns → drop middle)
  • State persistence — save and restore a run
  • Session trees — branching history with fork, checkpoints, and JSONL persistence
  • Skills — load AgentSkills-standard SKILL.md directories

Running it in production

  • Telemetrytracing spans per loop, LLM stream, and tool, with token and cost fields
  • Cost tracking with separate cache-read and cache-write rates
  • GASP — record runs as an append-only semantic event log; restore is clone + replay

Ecosystem

yoagent is part of the Yolog ecosystem. It powers the agent backend for Yolog applications.