Skip to main content

enact_runner/
lib.rs

1//! enact-runner — The Robust Agent Loop for Enact
2//!
3//! This crate fills the gap between `enact-core`'s deterministic kernel and the
4//! applications (CLI, API) that assume the Rust layer handles retries, context
5//! compaction, and multi-format tool call parsing.
6//!
7//! ## Architecture
8//!
9//! ```text
10//! ┌─────────────────────────────────────────────────────┐
11//! │  CLI / API / Web (thin clients)                     │
12//! └──────────────────────┬──────────────────────────────┘
13//!                        │ Execution Intent
14//!                        ▼
15//! ┌─────────────────────────────────────────────────────┐
16//! │  enact-runner (THIS CRATE)                          │
17//! │  ┌─────────────────────────────────────────────┐    │
18//! │  │  AgentRunner::run()                         │    │
19//! │  │  • Multi-iteration tool call loop           │    │
20//! │  │  • Retry with exponential backoff           │    │
21//! │  │  • Auto context compaction                  │    │
22//! │  │  • Multi-format parsing (JSON/XML/MD)       │    │
23//! │  │  • Checkpoint at intervals                  │    │
24//! │  │  • Stream event emission                    │    │
25//! │  └─────────────────────────────────────────────┘    │
26//! └──────────────────────┬──────────────────────────────┘
27//!                        │ Callable::run()
28//!                        ▼
29//! ┌─────────────────────────────────────────────────────┐
30//! │  enact-core kernel (deterministic DAG engine)       │
31//! └─────────────────────────────────────────────────────┘
32//! ```
33//!
34//! ## Quick Start
35//!
36//! ```rust,no_run
37//! use enact_runner::{AgentRunner, RunnerConfig, DefaultAgentRunner};
38//!
39//! # async fn example() -> anyhow::Result<()> {
40//! // Create runner with default config
41//! let mut runner = DefaultAgentRunner::default_new();
42//!
43//! // Or configure for long-running tasks
44//! let mut runner = DefaultAgentRunner::with_config(RunnerConfig::long_running());
45//!
46//! // Run an agent through the robust loop
47//! // let outcome = runner.run(&my_callable, "user input").await?;
48//! # Ok(())
49//! # }
50//! ```
51
52pub mod approval;
53pub mod commands;
54pub mod compaction;
55pub mod config;
56pub mod hooks;
57pub mod loop_driver;
58pub mod parser;
59pub mod registry;
60pub mod retry;
61pub mod session;
62
63// Re-exports for convenient access
64pub use approval::{
65    checker_from_approval_config, checker_from_config, AlwaysApprove, AlwaysDeny, ApprovalChecker,
66    ApprovalPrompter, AskApprovalChecker, AskOnceApprovalChecker, CliPrompter,
67    PatternApprovalChecker, PolicyWithOverrides,
68};
69pub use commands::{
70    dispatch as dispatch_command, load_commands, load_commands_for_run, CommandDef,
71};
72pub use compaction::HistoryMessage;
73pub use config::{ObservabilityConfig, RetryConfig, RunnerConfig};
74pub use hooks::{load_global_hooks, HookRegistry};
75pub use loop_driver::{AgentRunner, DefaultAgentRunner, LoopOutcome};
76pub use parser::{ParseResult, ParsedToolCall, ToolCallFormat};
77pub use registry::{LiveSessionInfo, LiveSessionRegistry};
78pub use retry::{classify_error, ErrorKind, RetryHandler};
79pub use session::{
80    SessionDetails, SessionEvent, SessionQuery, SessionReader, SessionRecorder, SessionStatus,
81    SessionSummary, SortOrder,
82};