Skip to main content

sage_runtime/
lib.rs

1//! Runtime library for compiled Sage programs.
2//!
3//! This crate provides the types and functions that generated Rust code
4//! depends on. It handles:
5//!
6//! - Agent spawning and lifecycle
7//! - Message passing between agents
8//! - LLM inference calls
9//! - RFC-0011: Tool execution (Http, Fs, etc.)
10//! - RFC-0012: Mock infrastructure for testing
11//! - Tracing and observability
12//! - Error handling
13//! - v2.0: Persistence for @persistent agent beliefs
14//! - v2.0: Supervision trees for agent lifecycle management
15//! - Phase 3: Session types for protocol verification
16
17#![forbid(unsafe_code)]
18
19mod agent;
20mod error;
21mod llm;
22pub mod mock;
23pub mod persistence;
24pub mod session;
25pub mod stdlib;
26pub mod supervisor;
27pub mod tools;
28pub mod tracing;
29
30pub use agent::{spawn, spawn_with_llm_config, AgentContext, AgentHandle, Message};
31pub use error::{ErrorKind, SageError, SageResult};
32pub use llm::{LlmClient, LlmConfig};
33pub use mock::{
34    try_get_mock, with_mock_tools, MockLlmClient, MockQueue, MockResponse, MockToolRegistry,
35};
36pub use persistence::{CheckpointStore, Persisted};
37pub use session::{
38    ProtocolStateMachine, ProtocolViolation, SenderHandle, SessionId, SessionRegistry,
39    SessionState, SharedSessionRegistry,
40};
41pub use supervisor::{RestartConfig, RestartPolicy, Strategy, Supervisor};
42pub use tools::{
43    DatabaseClient, DbRow, FsClient, HttpClient, HttpResponse, ShellClient, ShellResult,
44};
45pub use tracing as trace;
46
47/// Prelude for generated code.
48pub mod prelude {
49    pub use crate::agent::{spawn, spawn_with_llm_config, AgentContext, AgentHandle, Message};
50    pub use crate::error::{ErrorKind, SageError, SageResult};
51    pub use crate::llm::{LlmClient, LlmConfig};
52    pub use crate::mock::{
53        try_get_mock, with_mock_tools, MockLlmClient, MockQueue, MockResponse, MockToolRegistry,
54    };
55    pub use crate::persistence::{CheckpointStore, Persisted};
56    pub use crate::session::{
57        ProtocolStateMachine, ProtocolViolation, SenderHandle, SessionId, SessionRegistry,
58        SessionState, SharedSessionRegistry,
59    };
60    pub use crate::supervisor::{RestartConfig, RestartPolicy, Strategy, Supervisor};
61    pub use crate::tools::{
62        DatabaseClient, DbRow, FsClient, HttpClient, HttpResponse, ShellClient, ShellResult,
63    };
64    pub use crate::tracing as trace;
65}