Runs queued entries (Stage 5 W2, design 4.56): it takes entries from a store's RunQueue and runs them on the agents it was built with, whose runtimes are over the same store, at most settings.concurrency at once. Built with AgentWorker.apply, started with start, stopped with shutdown.
For each entry it takes it:
- holds the entry's lease, renewing it every
lease.renewEverybeside the run's claim, which the run's runtime renews; a renewal the queue refuses (another worker took the entry over, or it closed) cancels the run, which then writes nothing more, rather than run on beside the entry's next attempt; - defers to a live claim on the thread - a run there, queued or direct, on any machine - by giving the entry back (
RunQueue.release) without recording an attempt, so deferring never spendsmaxAttempts; - leaves an entry whose thread its agent's graph cannot take on - another graph version's run in flight, during a rolling upgrade - for a worker that can, passing over it for a while, and closes it
Failed(Unrunnable)once it has waitedsettings.unrunnableAfterby the store's clock; - records the attempt with a new
RunId.random()before touching the thread (rule 4), then acts on AttemptPlan: starts the input, recovers the thread, or closes the entry from the thread's state; - closes the entry from the thread's state once its run has ended at rest, or - for a run that failed - leaves it to come back when its lease expires, for an attempt that recovers it, until its attempts run out;
- on
AttemptStart.Exhausted, settles the thread first if its input was admitted - each tool call left without a result gets a synthetic one and aFailedcheckpoint is committed under the thread's claim - and closes the entryFailed(AttemptsExhausted); - stops the run when a stop is asked of the entry (W3, design 4.57), which it learns of from its lease renewals: a cancel (RunQueue.cancel) at once, as
AgentRun.canceldoes, an interrupt (a laterInterruptentry) at the run's next superstep boundary. It waits for the run to exit, and the run settles itself as it stops - aFailedcheckpoint, every tool call left without a result given AgentWorker.CancelledResult or AgentWorker.InterruptedResult, committed under the run's own claim - so the thread is at rest and the next entry starts normally. It then closes the entry from how the run ended:CancelledorInterruptedif the stop ended it, the run's own outcome if it reached rest first. A stop asked of an entry no run is running - its worker died - is acted on by the worker that next takes it, recording no attempt: the thread is settled the same way, under a claim of its own, if the entry's run is its incomplete latest.
A crashed worker's entries come back when their leases expire, by the store's clock, and the worker that takes one recovers its thread, once the crashed run's claim - on the same clock - has expired too.
With settings.sweepEvery set it also runs the store-wide retention sweep (Checkpointer.sweep, with a guard that keeps every open entry's runs and its thread's tombstone) and reclaims closed entries past their ticket lifetime, one instance of the fleet at a time: the sweep holds a store claim on a reserved thread id while it runs.
Built with a MetricsCollector, it records the run queue's and its own metrics (org.llm4s.agent.metrics.AgentMetrics, design 4.59): lease expiries, waits, attempts and what they did, deferrals, lease lapses and losses, closes by outcome, sweep passes and drains, and every settings.queueDepthEvery its agents' queue depth. The runs, claims and commits its agents make are a MeteredCheckpointer's to record.
Attributes
- Companion
- object
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any