pub struct Runtime {
pub state: Arc<StateStore>,
pub tools: Arc<RwLock<HashMap<String, ToolSchema>>>,
pub policies: Arc<RwLock<PolicyEngine>>,
pub log: Arc<Mutex<EventLog>>,
pub rate_limiter: Arc<RateLimiter>,
pub result_cache: Arc<ResultCache>,
/* private fields */
}Expand description
Common Agent Runtime — deterministic execution layer.
Lock ordering discipline (never hold multiple simultaneously, never hold sync locks across .await):
- capabilities (RwLock, read-only during execution)
- tools (RwLock, read-only during execution)
- policies (RwLock, read-only during execution)
- cost_budget (RwLock, read-only during execution)
- log (TokioMutex, acquired/released per event)
- tool_executor (TokioMutex, clone Arc and drop before await)
- idempotency_cache (TokioMutex, acquired/released per check)
StateStore uses parking_lot::Mutex (sync) — NEVER hold across .await points.
Fields§
§state: Arc<StateStore>§tools: Arc<RwLock<HashMap<String, ToolSchema>>>§policies: Arc<RwLock<PolicyEngine>>§log: Arc<Mutex<EventLog>>§rate_limiter: Arc<RateLimiter>§result_cache: Arc<ResultCache>Implementations§
Source§impl Runtime
impl Runtime
pub fn new() -> Self
Create a runtime with shared state, event log, and policies. Each runtime gets its own tool set, executor, and idempotency cache.
Sourcepub fn with_inference(self, engine: Arc<InferenceEngine>) -> Self
pub fn with_inference(self, engine: Arc<InferenceEngine>) -> Self
Attach a local inference engine. Registers infer, embed, classify
as built-in tools with real implementations.
Sourcepub fn with_learning(
self,
memgine: Arc<TokioMutex<MemgineEngine>>,
auto_distill: bool,
) -> Self
pub fn with_learning( self, memgine: Arc<TokioMutex<MemgineEngine>>, auto_distill: bool, ) -> Self
Attach a memgine for automatic skill learning after execution. Enables auto-distillation of execution traces into skills.
pub fn with_executor(self, executor: Arc<dyn ToolExecutor>) -> Self
Sourcepub async fn set_executor(&self, executor: Arc<dyn ToolExecutor>)
pub async fn set_executor(&self, executor: Arc<dyn ToolExecutor>)
Set a tool executor for the next execute() call. Used by NAPI bindings where executor varies per call.
pub fn with_event_log(self, log: EventLog) -> Self
Sourcepub async fn register_tool(&self, name: &str)
pub async fn register_tool(&self, name: &str)
Register a tool with just a name (backward compatible).
Sourcepub async fn register_tool_schema(&self, schema: ToolSchema)
pub async fn register_tool_schema(&self, schema: ToolSchema)
Register a tool with full schema.
Sourcepub async fn tool_schemas(&self) -> Vec<ToolSchema>
pub async fn tool_schemas(&self) -> Vec<ToolSchema>
Get all registered tool schemas (for model prompt generation).
Sourcepub async fn set_cost_budget(&self, budget: CostBudget)
pub async fn set_cost_budget(&self, budget: CostBudget)
Set a cost budget that limits proposal execution.
Sourcepub async fn set_capabilities(&self, caps: CapabilitySet)
pub async fn set_capabilities(&self, caps: CapabilitySet)
Set per-agent capability permissions that restrict tools, state keys, and action count.
Sourcepub async fn set_rate_limit(
&self,
tool: &str,
max_calls: u32,
interval_secs: f64,
)
pub async fn set_rate_limit( &self, tool: &str, max_calls: u32, interval_secs: f64, )
Set a per-tool rate limit (token bucket).
max_calls tokens are available per interval_secs window.
When the bucket is empty, dispatch() applies backpressure by
waiting until a token refills.
Sourcepub async fn enable_tool_cache(&self, tool: &str, ttl_secs: u64)
pub async fn enable_tool_cache(&self, tool: &str, ttl_secs: u64)
Enable cross-proposal result caching for a tool with a TTL in seconds.
Sourcepub async fn execute(&self, proposal: &ActionProposal) -> ProposalResult
pub async fn execute(&self, proposal: &ActionProposal) -> ProposalResult
Execute a full proposal through the runtime loop.
Sourcepub async fn save_checkpoint(&self) -> Checkpoint
pub async fn save_checkpoint(&self) -> Checkpoint
Save a checkpoint of the current runtime state.
Sourcepub async fn save_checkpoint_to_file(&self, path: &str) -> Result<(), String>
pub async fn save_checkpoint_to_file(&self, path: &str) -> Result<(), String>
Save checkpoint to a JSON file.
Sourcepub async fn load_checkpoint_from_file(
&self,
path: &str,
) -> Result<Checkpoint, String>
pub async fn load_checkpoint_from_file( &self, path: &str, ) -> Result<Checkpoint, String>
Load a checkpoint from a JSON file and restore state.
Sourcepub async fn restore_checkpoint(&self, checkpoint: &Checkpoint)
pub async fn restore_checkpoint(&self, checkpoint: &Checkpoint)
Restore runtime state from a checkpoint.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Runtime
impl !RefUnwindSafe for Runtime
impl Send for Runtime
impl Sync for Runtime
impl Unpin for Runtime
impl UnsafeUnpin for Runtime
impl !UnwindSafe for Runtime
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more