everruns_runtime/lib.rs
1//! Public in-process runtime for embedding Everruns.
2//!
3//! The runtime crate exposes an in-memory execution surface that runs the same
4//! core atoms (`input`, `reason`, `act`) used elsewhere in the system, but
5//! without the durable engine, gRPC worker boundary, or control-plane server.
6//!
7//! This is the intended public entrypoint for embedders who want to:
8//!
9//! - run sessions in their own process
10//! - provide their own platform definition (capabilities, drivers, harnesses)
11//! - seed harnesses, agents, sessions, and workspace files directly in code
12//! - replace the default in-memory stores with custom runtime backends
13//! - inspect the assembled turn context before or after executing a turn
14//! - reuse runtime-owned host phase execution from durable or server-backed hosts
15//! - map `plan_next_host_turn(...)` onto their own queue, retry, or in-memory host
16//!
17//! For a runnable example, see:
18//!
19//! ```text
20//! cargo run -p everruns-runtime --example in_process_runtime
21//! cargo run -p everruns-runtime --example inspect_context
22//! ```
23//!
24//! # Example
25//!
26//! ```ignore
27//! use everruns_core::{
28//! CapabilityRegistry, DriverRegistry, InputMessage, LlmProviderType, ModelWithProvider,
29//! PlatformDefinition,
30//! };
31//! use everruns_core::capabilities::TestMathCapability;
32//! use everruns_runtime::InProcessRuntimeBuilder;
33//!
34//! let mut capabilities = CapabilityRegistry::new();
35//! capabilities.register(TestMathCapability);
36//!
37//! let platform = PlatformDefinition::new(capabilities, DriverRegistry::new());
38//!
39//! let runtime = InProcessRuntimeBuilder::new()
40//! .platform_definition(platform)
41//! .single_session(|s| {
42//! s.harness("math", "You are a calculator.")
43//! .harness_display_name("Math")
44//! .with_capability("test_math")
45//! .agent("math-agent", "Use tools when needed.")
46//! .agent_display_name("Math Agent")
47//! .agent_max_iterations(8)
48//! .session_title("Math Session")
49//! })
50//! .llm_sim(everruns_core::llmsim_driver::LlmSimConfig::fixed("4"))
51//! .default_model(ModelWithProvider {
52//! model: "llmsim-model".into(),
53//! provider_type: LlmProviderType::LlmSim,
54//! api_key: Some("fake-key".into()),
55//! base_url: None,
56//! })
57//! .build()
58//! .await?;
59//!
60//! let session_id = runtime.default_session_id().expect("single_session id");
61//! let result = runtime
62//! .run_turn(
63//! session_id,
64//! InputMessage::user("What is 2 + 2?"),
65//! )
66//! .await?;
67//! assert!(result.success);
68//! # Ok::<(), everruns_core::AgentLoopError>(())
69//! ```
70//!
71//! # Real-disk workspace
72//!
73//! Embedders who want built-in capabilities (`file_system`,
74//! `agent_instructions`, `skills`, ...) to read and write a real directory
75//! on disk can configure [`RealDiskSessionFileSystemFactory`] on their
76//! [`PlatformDefinition`]. Every capability that goes through
77//! `ToolContext.file_store` or `SystemPromptContext.file_store` picks it up
78//! automatically.
79//!
80//! See the runnable examples for the full wiring:
81//!
82//! ```text
83//! cargo run -p everruns-runtime --example real_disk_agent_instructions
84//! cargo run -p everruns-runtime --example real_disk_file_system_tools
85//! ```
86//!
87//! And `specs/file-store.md` for the trait contract.
88
89mod backends;
90mod builders;
91mod file_store_decorators;
92mod host;
93mod in_memory;
94mod real_disk;
95mod runtime;
96mod turn_strategy;
97
98pub use backends::{
99 EventBus, RuntimeAgentStore, RuntimeBackends, RuntimeHarnessStore, RuntimeMessageStore,
100 RuntimeProviderStore, RuntimeSessionStore,
101};
102pub use builders::{AgentBuilder, HarnessBuilder, SessionBuilder, SingleSessionBuilder};
103pub use everruns_core::AssembledTurnContext;
104pub use file_store_decorators::{
105 ApprovalGatingFileStore, DEFAULT_WRITE_BLOCKLIST, FileApprovalGate, WriteBlocklistFileStore,
106};
107pub use host::{
108 RuntimeHostAdapter, RuntimeHostTurnContext, RuntimeSessionLifecycle, detect_dependency_blocker,
109 execute_act_activity, execute_input_activity, execute_reason_activity,
110};
111pub use in_memory::{
112 InMemorySessionFileStore, InMemorySessionFileSystemFactory, InMemorySessionStorageStore,
113 InMemorySessionStore,
114};
115pub use real_disk::{RealDiskFileStore, RealDiskSessionFileSystemFactory};
116pub use runtime::{InProcessRuntime, InProcessRuntimeBuilder, TurnResult};
117pub use turn_strategy::{RuntimeActPlan, RuntimeTurnPlan, RuntimeTurnState, plan_next_host_turn};