1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//! # 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
//!
//! 1. **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.
//! 2. **Graph runtime** ([`graph`]) — LangGraph-style durable typed state
//! graphs: [`START`]/[`END`], nodes, conditional routing, [`Command`]s,
//! fan-out, reducers/channels, [`Checkpoint`]s, [`Interrupt`]s, subgraphs,
//! streaming, and topology export.
//! 3. **Registry** ([`registry`]) — a named capability catalog (models, tools,
//! agents, graphs, stores, middleware, policy) that `.rag`/`.ragsh` bind by
//! name.
//! 4. **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.
//! 5. **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`]).
// --- Error: the crate-wide error type and `Result` alias ---
pub use ;
// --- Registry: named capability catalog (.rag/.ragsh binding by name) ---
pub use ;
// --- Language: registry → blueprint binding façade ---
// The strict, registry-backed entry points the REPL and orchestrators use to
// turn `.rag`/`.ragsh` source into validated blueprints. `compile_source` runs
// parse -> compile -> registry-bind in one call.
pub use ;
pub use Blueprint;
// --- Harness: embeddings + retrieval ---
pub use ;
// --- Harness: first-class sub-agents (agent-calling-agent composition) ---
pub use ;
// --- Harness: orchestrator → sub-agent steering ---
pub use ;
// --- Cooperative run cancellation ---
pub use CancellationToken;
// --- Harness: durable observability (journals, status stores, sinks) ---
pub use ;
// --- Graph: durable execution model (LangGraph-style) ---
// Re-exported with explicit names so the durable API is discoverable at the
// crate root. The `harness::stream::StreamMode` and `graph::stream::StreamMode`
// types intentionally stay behind their module paths to avoid a name clash.
pub use SqliteCheckpointer;
pub use ;
// --- Graph: sub-agent nodes (delegate a graph step to a registered agent) ---
pub use ;
// --- Graph: channel-per-field state model (additive; see state-channels.md) ---
// An opt-in alternative to the monolithic State + StateReducer path: state is
// split into independently-merged named channels.
pub use ;
// --- Graph: durable observability (journals, status stores, journaling sink) ---
// Names are graph-prefixed so they never collide with the harness observability
// re-exports above.
pub use ;
// --- Graph: export / visualization ---
// Topology types are surfaced at the crate root; the `to_json`/`to_mermaid`
// free functions stay behind `graph::export::` to avoid generic-name clashes.
pub use ;