Skip to main content

SharedInfra

Struct SharedInfra 

Source
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§

Source§

impl SharedInfra

Source

pub fn new() -> Self

Source

pub fn with_shared( state: Arc<StateStore>, log: Arc<TokioMutex<EventLog>>, policies: Arc<TokioRwLock<PolicyEngine>>, ) -> 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.

Source

pub fn scoped_gate_audit(&self, scope: String) -> Self

Make a run-scoped audit view without replacing any runtime handles.

Source

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.

Source

pub fn with_shared_budget(self, budget: Arc<CoordinationBudget>) -> Self

Attach a pre-built (possibly shared) coordination budget.

Source

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.

Source

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).

Source

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.

Source

pub fn record_output(&self, out: &AgentOutput)

Record an agent’s reported token/cost spend against the budget.

Source

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.

Source

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.

Source

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§

Source§

impl Default for SharedInfra

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more