Skip to main content

tinyagents/graph/
mod.rs

1//! TinyAgents graph runtime.
2//!
3//! The graph module is TinyAgents' durable workflow runtime (LangGraph-style)
4//! and one of the load-bearing surfaces of the crate's recursive language-model
5//! (RLM) architecture: because a node can embed another compiled graph
6//! ([`subgraph`]) or invoke a sub-agent, **graphs run graphs** and orchestration
7//! recurses while every step stays typed, checkpointed, and observable. A
8//! workflow authored from a `.rag` blueprint or driven from the `.ragsh` REPL
9//! lowers into exactly these same types, so a model can describe, compile, and
10//! re-enter the very runtime it is executing inside.
11//!
12//! The pieces: partial updates and reducers ([`reducer`]), commands and
13//! interrupts ([`command`]), a builder/compile contract ([`builder`]), a
14//! superstep executor ([`compiled`]), checkpointing ([`checkpoint`]),
15//! streaming/events ([`stream`]), run-status snapshots ([`status`]), graph
16//! export/visualization ([`export`]), subgraph embedding ([`subgraph`]), and
17//! per-thread productivity primitives — a durable goal ([`goals`]) and a kanban
18//! task board ([`todos`]) — exposed as harness tools.
19//!
20//! Each concern lives in its own submodule with `types.rs` (definitions),
21//! `mod.rs` (implementations), and `test.rs` (unit tests).
22
23pub mod builder;
24pub mod channel;
25pub mod checkpoint;
26pub mod command;
27pub mod compiled;
28pub mod export;
29pub mod goals;
30pub mod observability;
31pub mod orchestration;
32pub mod parallel;
33pub mod recursion;
34pub mod reducer;
35pub mod status;
36pub mod stream;
37pub mod subagent_node;
38pub mod subgraph;
39pub mod testkit;
40pub(crate) mod thread_locks;
41pub mod todos;
42
43// --- Durable execution model ---
44pub use builder::{
45    END, ForkId, GraphBuilder, GraphDefaults, NodeContext, NodeFuture, NodeHandler, Route,
46    RouterFn, START,
47};
48pub use channel::{
49    Barrier, BinaryAggregate, Channel, ChannelSet, ChannelState, ChannelUpdate, Delta, Ephemeral,
50    LastValue, Messages, NamedBarrier, Topic, Untracked,
51};
52#[cfg(feature = "sqlite")]
53pub use checkpoint::SqliteCheckpointer;
54pub use checkpoint::{
55    BarrierArrivals, Checkpoint, CheckpointConfig, CheckpointMetadata, CheckpointSource,
56    CheckpointTuple, Checkpointer, DurabilityMode, FileCheckpointer, InMemoryCheckpointer,
57    PendingActivation, PendingWrite,
58};
59pub use command::{Command, Interrupt, NodeResult, RouteTarget, Send};
60pub use compiled::{CompiledGraph, GraphExecution, GraphInput, ResumeTarget, StateSnapshot};
61pub use export::{
62    ChannelInfo, ConditionalEdgeInfo, EdgeInfo, GraphPolicySummary, GraphTopology, NodeInfo,
63    NodePolicySummary, RouteInfo, ValidationReport, WaitingEdgeInfo, blueprint_to_json,
64    blueprint_to_mermaid, blueprint_to_topology, from_json, to_json, to_mermaid,
65};
66pub use goals::{
67    GoalProgress, GoalTool, GoalToolKind, ThreadGoal, ThreadGoalStatus, TurnOutcome,
68    active_goal_context_block, goal_gate_node, goal_tools, note_user_turn, register_goal_tools,
69    run_continuation_tick,
70};
71pub use observability::{
72    GraphEventJournal, GraphHealthSummary, GraphLangfuseExporter, GraphLatencyMetrics,
73    GraphNodeHealth, GraphNodeLatency, GraphObservation, GraphStatusStore, GraphStepLatency,
74    InMemoryGraphEventJournal, InMemoryGraphStatusStore, JournalGraphSink, SpanMetadataFn,
75    StoreGraphEventJournal,
76};
77pub use orchestration::{
78    InMemoryTaskStore, JsonlTaskStore, OrchestrationControlOutcome, OrchestrationTaskFilter,
79    OrchestrationTaskKind, OrchestrationTaskRecord, OrchestrationTaskResult, OrchestrationTaskSpec,
80    OrchestrationTaskStatus, OrchestrationTool, OrchestrationToolKind, SteeringRegistry, TaskStore,
81    orchestration_tool_schema, orchestration_tool_schemas, orchestration_tools,
82    orchestration_tools_with_steering, register_orchestration_tools,
83};
84pub use recursion::{
85    ChildRun, ChildRunSink, RecursionFrame, RecursionPolicy, RecursionStack, RunTree,
86};
87pub use reducer::{
88    AppendReducer, ClosureReducer, ClosureStateReducer, MaxReducer, MinReducer, OverwriteReducer,
89    OverwriteStateReducer, Reducer, SetUnionReducer, StateReducer,
90};
91pub use status::GraphRunStatus;
92pub use stream::{CollectingSink, GraphEvent, GraphEventSink, NoopSink, StreamMode};
93pub use subagent_node::{
94    HarnessAgent, HarnessSubAgent, InputMapper, OutputMapper, SubAgentBudget, SubAgentInput,
95    SubAgentNode, SubAgentOutput, SubAgentPolicy, subagent_node,
96};
97pub use subgraph::{adapter_subgraph_node, shared_subgraph_node};
98pub use testkit::{
99    GraphAssertions, GraphEventRecorder, GraphRun, RetryCountingNode, StreamCollector,
100    assert_graph, failing_node, fanout_node, interrupting_node, noop_node, run_recorded,
101    scripted_route_node, scripted_update_node, subagent_fake_node, subgraph_test_node,
102};
103pub use todos::{
104    CardPatch, TaskApprovalMode, TaskBoard, TaskBoardCard, TaskCardStatus, TodoTool, TodosSnapshot,
105    normalise_board, parse_status, register_todo_tools, render_markdown, todo_tools,
106};