pub struct PipelineWorld { /* private fields */ }Expand description
The shared ECS world that hosts and drives every agent.
Implementations§
Source§impl PipelineWorld
impl PipelineWorld
Sourcepub fn new(
providers: ProviderRegistry,
tool_service: Arc<dyn ToolService>,
pool_config: InferencePoolConfig,
tool_concurrency: usize,
runs_dir: PathBuf,
runtime: Handle,
) -> Self
pub fn new( providers: ProviderRegistry, tool_service: Arc<dyn ToolService>, pool_config: InferencePoolConfig, tool_concurrency: usize, runs_dir: PathBuf, runtime: Handle, ) -> Self
Build a world: wire the pool/bridge resources, register the providers and
tool service, spawn the tool worker onto runtime, and assemble the tick
schedule. Agents are added later via Self::spawn_agent.
Sourcepub fn world_mut(&mut self) -> &mut World
pub fn world_mut(&mut self) -> &mut World
Mutable access to the underlying ECS world, for spawning agents (the CLI / daemon builds each agent’s component bundle) and inspection.
Sourcepub fn set_exact_token_counting(&mut self, enabled: bool)
pub fn set_exact_token_counting(&mut self, enabled: bool)
Enable (or disable) the opt-in exact pre-inference budget guard for this
world - see inference_bridge::InferenceJob::exact_token_counting.
Call once at startup when the run config requests it, before serving.
Sourcepub fn insert_interaction_hub(&mut self, hub: InteractionHub)
pub fn insert_interaction_hub(&mut self, hub: InteractionHub)
Install the shared interaction hub as a world resource and attach this
world’s wake handle to it, so opening/answering a prompt wakes the driver
and reflect_interaction_status
mirrors the change into agent status. Call once at startup, before
serving. Without this, that system is a no-op (test worlds).
Sourcepub fn spawn_agent(&mut self, bundle: impl Bundle) -> Entity
pub fn spawn_agent(&mut self, bundle: impl Bundle) -> Entity
Spawn an agent from its pre-built component bundle and wake the driver so the next fixed-point picks it up. Returns the new entity.
Sourcepub fn spawn_from_blueprint(
&mut self,
agent_id: String,
blueprint: Blueprint,
task: &str,
stages: Vec<ResolvedStage>,
global_batch_tool_hint: bool,
) -> Result<Entity, String>
pub fn spawn_from_blueprint( &mut self, agent_id: String, blueprint: Blueprint, task: &str, stages: Vec<ResolvedStage>, global_batch_tool_hint: bool, ) -> Result<Entity, String>
Spawn an agent from a blueprint + task + per-stage resolution (see
crate::pipeline::spawn_agent) and wake the driver. Returns the new
entity, or an error if the first stage’s system prompt doesn’t fit.
Sourcepub fn send_message(&self, msg: AgentMessage) -> Result<(), ProviderError>
pub fn send_message(&self, msg: AgentMessage) -> Result<(), ProviderError>
Deliver a message to a running agent (routed to its inbox on the next tick) and wake the driver.
Sourcepub fn wake_handle(&self) -> Arc<Notify> ⓘ
pub fn wake_handle(&self) -> Arc<Notify> ⓘ
A clone of the wake handle, so external producers (e.g. a control socket) can nudge the driver after mutating the world directly.
Sourcepub fn shutdown_handle(&self) -> Arc<Notify> ⓘ
pub fn shutdown_handle(&self) -> Arc<Notify> ⓘ
A clone of the shutdown handle, so a supervisor can stop a Self::run
loop that has taken ownership of the world on another task.
Sourcepub async fn flush_and_stop(&mut self)
pub async fn flush_and_stop(&mut self)
Cleanly stop the world, guaranteeing every queued snapshot reaches disk.
The persistence lane is async and fire-and-forget, so a plain shutdown (the
Self::run/serve loop returning, then the world dropping) can lose
snapshots still queued in the channel. This method closes that gap: it
signals shutdown, drives one last fixed point so any state that settled
after the loop parked is dispatched to the lane, then closes the lane and
awaits the worker so all queued writes (meta.json / context.json /
run.lvr) land before it returns.
Call it after the serve loop has returned (the tokio runtime must still be alive for the worker to be scheduled). Idempotent: a second call is a no-op because the persistence resource is already removed and the task taken.
Sourcepub fn agent_status(&self, entity: Entity) -> Option<AgentStatus>
pub fn agent_status(&self, entity: Entity) -> Option<AgentStatus>
The status of an agent, if it still exists.
Sourcepub fn set_status(&mut self, entity: Entity, status: AgentStatus) -> bool
pub fn set_status(&mut self, entity: Entity, status: AgentStatus) -> bool
Set an agent’s status and wake the driver. Returns false if the agent no
longer exists. The async-starting dispatchers only act on Active agents,
so this is how the world pauses/resumes/cancels an agent - a non-Active
agent is simply data the systems skip until it is Active again.
Sourcepub fn pause(&mut self, entity: Entity) -> bool
pub fn pause(&mut self, entity: Entity) -> bool
Pause an agent (it finishes any in-flight step, then stops before starting
new work). Returns false if the agent no longer exists.
Sourcepub fn cancel(&mut self, entity: Entity) -> bool
pub fn cancel(&mut self, entity: Entity) -> bool
Cancel an agent (it stops starting new work; in-flight results still land).
Sourcepub fn tick(&mut self) -> TickOutcome
pub fn tick(&mut self) -> TickOutcome
Run one schedule tick over every agent, catching a panic from any system so one bad agent can’t crash the daemon and take every other hosted agent with it.
When the panic can be traced to a specific agent (the usual case - see
tick_scope), that agent is failed with the panic message so it
stops being driven, its run is persisted as errored, and the host reaps
it. Without that, the world would re-tick the same unchanged state on
every wake and panic again indefinitely.
Sourcepub fn run_to_fixed_point(&mut self)
pub fn run_to_fixed_point(&mut self)
Drive the schedule until a tick changes nothing (quiescence). Public so a host loop can interleave control operations between quiescent points.
Sourcepub async fn run_until_idle(&mut self, max_waits: usize)
pub async fn run_until_idle(&mut self, max_waits: usize)
Drive every agent as far as it can go right now, then, while async
work is in flight, wait for each completion and drive again - returning
once the world is fully quiescent with nothing in flight. Bounded by
max_waits wake-waits as a safety valve so a lost/never-arriving wake
can’t hang a caller (e.g. a test) forever.
Sourcepub async fn run(&mut self)
pub async fn run(&mut self)
Run forever: drive to quiescence, then park until an async completion or
an external send_message/spawn_agent wakes the driver. Returns when
Self::shutdown is signalled.
Auto Trait Implementations§
impl !Freeze for PipelineWorld
impl !RefUnwindSafe for PipelineWorld
impl !UnwindSafe for PipelineWorld
impl Send for PipelineWorld
impl Sync for PipelineWorld
impl Unpin for PipelineWorld
impl UnsafeUnpin for PipelineWorld
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> ConditionalSend for Twhere
T: Send,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.