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