Expand description
§TinyAgents — a recursive language-model (RLM) harness for Rust
TinyAgents is a typed, durable runtime where language models call models, agents call agents, and graphs run graphs — and where a model can author, compile, and run the very workflow it is standing inside, all as inspectable, checkpointed, policy-checked Rust.
The “recursive” framing is the through-line of the whole crate, not a footnote. It is architected around the execution model described in “Recursive Language Models” (Alex L. Zhang, Tim Kraska, Omar Khattab, MIT CSAIL, 2025; https://arxiv.org/abs/2512.24601): rather than stuffing everything into one context window, a model treats long context as an external environment it interacts with through a REPL — examining, decomposing, and recursively calling sub-models over snippets. TinyAgents brings that idea to Rust as a production-shaped harness (sub-model / sub-agent / sub-graph calls as functions, persistent session values, depth tracking, and trajectory/event logging). It is inspired by and architected around the RLM execution model, not a reimplementation of the paper’s benchmarks.
§The five surfaces
- Harness (
harness) — provider-neutral model calls, typed tools, middleware, structured output, streaming, usage/cost, retry/limits, cache, memory/embeddings, sub-agents, steering, and a testkit. - Graph runtime (
graph) — LangGraph-style durable typed state graphs:START/END, nodes, conditional routing,Commands, fan-out, reducers/channels,Checkpoints,Interrupts, subgraphs, streaming, and topology export. - Registry (
registry) — a named capability catalog (models, tools, agents, graphs, stores, middleware, policy) that.rag/.ragshbind by name. - Expressive language
.rag(language) — a declarative, side-effect-free blueprint format that compiles (lexer → parser → compiler) into the same graph/harness runtime; the safe boundary for agent-authored plans. - REPL language
.ragsh(repl) — imperative, capability-bound interactive orchestration; the RLM/CodeAct loop surface.
§The recursion story
Both .rag and .ragsh lower into the same graph + harness types
as hand-written Rust — a language whose programs are the runtime that
interprets them. A harness agent can be exposed as a tool to another agent
(SubAgent, SubAgentTool, SubAgentSession), so orchestration is
just a model calling a model; the runtime tracks parent/child run lineage and
enforces a recursion cap (TinyAgentsError::SubAgentDepth). At the deepest
level a model can emit a .rag blueprint that compiles through the same
registry-bound path as a human-authored file and runs on the same runtime the
model is already executing in (see examples/openai_self_blueprint.rs).
§Provider features
The default build is offline and deterministic (harness::providers::MockModel).
Hosted and local providers (OpenAI plus the OpenAI-compatible endpoints for
Anthropic, Ollama, DeepSeek, Groq, xAI, OpenRouter, Together, and Mistral)
live behind the openai Cargo feature.
§Crate-root re-exports
For discoverability the most-used types from each surface are re-exported at
the crate root, grouped below by surface (error, registry,
language, harness, and graph).
Re-exports§
pub use error::Result;pub use error::TinyAgentsError;pub use registry::CapabilityRegistry;pub use registry::ComponentId;pub use registry::ComponentKind;pub use registry::ComponentMetadata;pub use language::compiler::CapabilityResolver;pub use language::compiler::bind_capabilities;pub use language::compiler::bind_capabilities_with_registry;pub use language::compiler::compile;pub use language::compiler::compile_source;pub use language::types::Blueprint;pub use harness::embeddings::EmbeddingModel;pub use harness::embeddings::InMemoryVectorStore;pub use harness::embeddings::MockEmbeddingModel;pub use harness::embeddings::Retriever;pub use harness::embeddings::ScoredDoc;pub use harness::embeddings::VectorStore;pub use harness::embeddings::cosine_similarity;pub use harness::subagent::SubAgent;pub use harness::subagent::SubAgentSession;pub use harness::subagent::SubAgentTool;pub use harness::steering::SteeringCommand;pub use harness::steering::SteeringCommandKind;pub use harness::steering::SteeringHandle;pub use harness::steering::SteeringOutcome;pub use harness::steering::SteeringPolicy;pub use harness::cancel::CancellationToken;pub use harness::observability::AgentObservation;pub use harness::observability::FanOutSink;pub use harness::observability::HarnessEventJournal;pub use harness::observability::HarnessStatusStore;pub use harness::observability::InMemoryEventJournal;pub use harness::observability::InMemoryStatusStore;pub use harness::observability::JournalSink;pub use harness::observability::JsonlSink;pub use harness::observability::RedactingSink;pub use harness::observability::StoreEventJournal;pub use graph::Checkpoint;pub use graph::CheckpointConfig;pub use graph::CheckpointMetadata;pub use graph::CheckpointSource;pub use graph::CheckpointTuple;pub use graph::Checkpointer;pub use graph::ChildRun;pub use graph::ChildRunSink;pub use graph::ClosureReducer;pub use graph::ClosureStateReducer;pub use graph::Command;pub use graph::CompiledGraph;pub use graph::DurabilityMode;pub use graph::END;pub use graph::FileCheckpointer;pub use graph::ForkId;pub use graph::GraphBuilder;pub use graph::GraphDefaults;pub use graph::GraphEvent;pub use graph::GraphExecution;pub use graph::GraphRunStatus;pub use graph::InMemoryCheckpointer;pub use graph::Interrupt;pub use graph::NodeContext;pub use graph::NodeResult;pub use graph::RecursionFrame;pub use graph::RecursionPolicy;pub use graph::RecursionStack;pub use graph::Reducer;pub use graph::ResumeTarget;pub use graph::Route;pub use graph::RouteTarget;pub use graph::RunTree;pub use graph::START;pub use graph::StateReducer;pub use graph::StateSnapshot;pub use graph::HarnessAgent;pub use graph::HarnessSubAgent;pub use graph::SubAgentBudget;pub use graph::SubAgentInput;pub use graph::SubAgentNode;pub use graph::SubAgentOutput;pub use graph::SubAgentPolicy;pub use graph::subagent_node;pub use graph::subagent_node;pub use graph::Barrier;pub use graph::BinaryAggregate;pub use graph::Channel;pub use graph::ChannelSet;pub use graph::ChannelState;pub use graph::ChannelUpdate;pub use graph::Delta;pub use graph::Ephemeral;pub use graph::LastValue;pub use graph::Messages;pub use graph::NamedBarrier;pub use graph::Topic;pub use graph::Untracked;pub use graph::GraphEventJournal;pub use graph::GraphObservation;pub use graph::GraphStatusStore;pub use graph::InMemoryGraphEventJournal;pub use graph::InMemoryGraphStatusStore;pub use graph::JournalGraphSink;pub use graph::StoreGraphEventJournal;pub use graph::ChannelInfo;pub use graph::ConditionalEdgeInfo;pub use graph::EdgeInfo;pub use graph::GraphPolicySummary;pub use graph::GraphTopology;pub use graph::NodeInfo;pub use graph::NodePolicySummary;pub use graph::RouteInfo;pub use graph::ValidationReport;pub use graph::WaitingEdgeInfo;
Modules§
- error
- Crate-wide error type and
Resultalias. - graph
- TinyAgents graph runtime.
- harness
- Harness runtime modules — the execution layer of the recursive runtime.
- language
- Expressive language (
.rag) — the declarative blueprint surface of the recursive runtime. - registry
- Registry coordination and discovery primitives — the named capability catalog that makes TinyAgents recursive.
- repl
- REPL language (
.ragsh) — capability-bound interactive orchestration; the RLM/CodeAct surface of the runtime.