Expand description
Backend-agnostic batch scheduler for agent workloads.
This module provides a pipeline scheduler that groups work items by model, prefix hash, and context length for optimal cache utilization across different LLM backends (Anthropic Batch API, Ollama, etc.).
§Architecture
The scheduler operates as a pipeline where batches are interleaved:
Batch 1 [agents A,B,C]: PERCEIVE → submit THINK → poll → ACT → submit REFLECT
Batch 2 [agents D,E,F]: PERCEIVE → submit THINK → poll → ACT ...
(D,E,F see A,B,C's committed actions in their perceptions)This ensures agents in later batches observe earlier batches’ actions, creating a natural information flow without strict phase barriers.
§Grouping
Work items are grouped by priority:
- Model — most expensive to switch (weight loading / pricing)
- Prefix hash — KV cache reuse on both Anthropic and Ollama
- Context length — avoid memory reallocation on Ollama
Items waiting too long are promoted regardless of grouping optimality to prevent starvation.
Structs§
- Batch
Group - A group of work items that should be submitted together.
- Grouping
Config - Configuration for the grouping algorithm.
- Scheduler
- Pipeline scheduler that manages batch submission and interleaving.
- Scheduler
Config - Configuration for the pipeline scheduler.
- Work
Item - A unit of work: one agent’s prompt for one cycle step.
- Work
Result - Result of processing a single work item.
Enums§
- Batch
Error - Errors that can occur during batch processing.
- Batch
State - The state of a polled batch.
- Cycle
Step - Identifies what step in the agent cycle a work item represents.
Traits§
- Batch
Backend - Backend-agnostic interface for submitting and polling batch work.
- Pending
Handle - A handle to a submitted batch, returned by
BatchBackend::submit.
Functions§
- group_
work_ items - Group work items into
BatchGroups by (model, prefix_hash, context_bucket).