pub struct SharedInfra {
pub state: Arc<StateStore>,
pub log: Arc<Mutex<EventLog>>,
pub policies: Arc<RwLock<PolicyEngine>>,
pub budget: Arc<CoordinationBudget>,
pub concurrency: Option<ConcurrencyControl>,
pub gate_audit_scope: Option<String>,
}Expand description
Factory for creating Runtime instances with shared state, event log, and policies.
In a multi-agent system, all agents see the same state store and write to the same event log. Each agent gets its own tool set and executor.
A CoordinationBudget is always present (unbounded by default). Patterns
gate each spawn through begin_agent and report spend
through record_output, so budget enforcement is a
uniform, always-on code path that costs nothing when no limits are set.
Fields§
§state: Arc<StateStore>§log: Arc<Mutex<EventLog>>§policies: Arc<RwLock<PolicyEngine>>§budget: Arc<CoordinationBudget>§concurrency: Option<ConcurrencyControl>Opt-in concurrency-anomaly gating for the cross-agent commit barrier
(A5). None (the default) leaves coordination behaving exactly as
before; patterns that support gating consult this only when it is set.
gate_audit_scope: Option<String>Identifies one foreman invocation in a shared gate audit log. Internal correlation only; never changes policy evaluation.
Implementations§
pub fn new() -> Self
Build from EXISTING shared state/log/policies — e.g. a daemon session’s
Runtime parts (runtime.state, runtime.log, runtime.policies), so a
coordination pattern’s gate consults the operator’s registered policies
and its audit events land in the session’s event log, instead of a fresh
empty engine. Budget defaults to unbounded; chain with_budget to cap.
Sourcepub fn scoped_gate_audit(&self, scope: String) -> Self
pub fn scoped_gate_audit(&self, scope: String) -> Self
Make a run-scoped audit view without replacing any runtime handles.
Sourcepub fn with_budget(self, limits: BudgetLimits) -> Self
pub fn with_budget(self, limits: BudgetLimits) -> Self
Attach a coordination budget built from the given limits. Patterns run against this infra will refuse to start agents once a limit is crossed.
Attach a pre-built (possibly shared) coordination budget.
Sourcepub fn with_concurrency_control(self, control: ConcurrencyControl) -> Self
pub fn with_concurrency_control(self, control: ConcurrencyControl) -> Self
Enable concurrency-anomaly gating (A5) at the cross-agent commit barrier
with the given control. The isolated parallel swarm will instrument its
agents into an AgentOp schedule and gate the merge; a detected
causal-cascade aborts the batch, a stale generation rejects the offending
commit, and a write reorder is serialized deterministically.
Sourcepub fn with_concurrency_gating(self) -> Self
pub fn with_concurrency_gating(self) -> Self
Enable concurrency gating with the default policy (abort on causal cascade, require-approval on stale generation, auto-remediate reorders).
Sourcepub fn begin_agent(&self) -> Result<(), BudgetError>
pub fn begin_agent(&self) -> Result<(), BudgetError>
Reserve a budget slot for one agent. Ok(()) means the agent may run;
Err carries why it was denied. Patterns call this immediately before a
spawn and record a budget_skipped_output
on denial.
Sourcepub fn record_output(&self, out: &AgentOutput)
pub fn record_output(&self, out: &AgentOutput)
Record an agent’s reported token/cost spend against the budget.
Sourcepub async fn record_output_metered(&self, out: &AgentOutput)
pub async fn record_output_metered(&self, out: &AgentOutput)
Record spend against the budget AND emit a per-agent InferenceMetered
event (EPIC G / G3) so cost is attributable per agent
(EventLog::cost_by_agent) and a run’s spend is traceable to the agent
that incurred it. The event stamps agent (+ tools provenance) in
data and the token/cost/latency in the standardized metric keys, so
events.query {data_matches:{agent}} also surfaces it. A no-op emit when
the runner reported no token accounting.
Sourcepub fn make_runtime(&self) -> Runtime
pub fn make_runtime(&self) -> Runtime
Create a Runtime that shares this infra’s state, log, and policies.
Each runtime gets its own tool set, executor, and idempotency cache.
Sourcepub fn make_isolated_runtime(&self, agent_name: &str) -> (Runtime, AgentContext)
pub fn make_isolated_runtime(&self, agent_name: &str) -> (Runtime, AgentContext)
Create a Runtime with per-agent isolated state overlay.
Writes go to a local StateStore; reads fall through to shared state.
Call AgentContext::merge_to_parent() after the agent completes.
Trait Implementations§
Auto Trait Implementations§
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
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