pub struct Scheduler { /* private fields */ }Expand description
Concurrency-controlled agent scheduler. Held as Arc<Scheduler> and shared
across orchestration coroutines.
Implementations§
Source§impl Scheduler
impl Scheduler
pub fn new( config: SchedulerConfig, registry: BackendRegistry, journal_callback: Option<Arc<dyn JournalCallback>>, ) -> Arc<Self>
pub fn config(&self) -> &SchedulerConfig
Sourcepub fn init_run(
&self,
run_id: RunId,
event_capacity: usize,
) -> Receiver<AgentEvent>
pub fn init_run( &self, run_id: RunId, event_capacity: usize, ) -> Receiver<AgentEvent>
Initialise per-run state. Must be called before any run_agent.
Returns the broadcast receiver; further consumers use resubscribe().
Sourcepub fn init_run_with(&self, run_id: RunId, events: EventSender)
pub fn init_run_with(&self, run_id: RunId, events: EventSender)
Initialise per-run state using an externally-owned event sender.
This lets the orchestration layer share a single event bus between the
scheduler (AgentStarted/AgentDone, plus the RunContext handed to
backends) and the runtime SDK (phase/log/pipeline/RunDone).
Sourcepub async fn run_agent(
&self,
run_id: RunId,
task: AgentTask,
backend_id: Option<&str>,
) -> Result<AgentResult, SchedulerError>
pub async fn run_agent( &self, run_id: RunId, task: AgentTask, backend_id: Option<&str>, ) -> Result<AgentResult, SchedulerError>
Schedule and run a single agent task: quota check → permit → retry loop →
events. Cancellation flows via RunContext::cancel.
The agent span carries run_id/agent_id/phase_id/model so every
log emitted on this task’s async path inherits them (see
docs/design/program-logging.md).
Sourcepub async fn run_parallel(
&self,
run_id: RunId,
tasks: Vec<(AgentTask, Option<String>)>,
) -> Vec<Result<AgentResult, SchedulerError>>
pub async fn run_parallel( &self, run_id: RunId, tasks: Vec<(AgentTask, Option<String>)>, ) -> Vec<Result<AgentResult, SchedulerError>>
Run a batch of tasks concurrently (the parallel() primitive). Bounded
by the same global semaphore; does not short-circuit on failure — results
preserve input order.
Sourcepub fn cancel_agent(&self, run_id: RunId, agent_id: AgentId)
pub fn cancel_agent(&self, run_id: RunId, agent_id: AgentId)
Cancel one agent (fires its token; the backend observes ctx.cancel).
Sourcepub fn cancel_run(&self, run_id: RunId)
pub fn cancel_run(&self, run_id: RunId)
Cancel the whole run (all child agent tokens fire).
Sourcepub fn active_concurrency(&self) -> usize
pub fn active_concurrency(&self) -> usize
Current global active concurrency.
Sourcepub fn quota_used(&self, run_id: RunId) -> Option<u32>
pub fn quota_used(&self, run_id: RunId) -> Option<u32>
Quota consumed by a run, if initialised.