automaton.pool¶
WARNING
This documentation is almost entirely "vibe coded"; while a helpful resource for humans and agents to understand this codebase, it should not be considered a source of ground truth in the way documentation normally is, and the user is responsible for verifying that all instructions given here are safe.
automaton.pool
¶
Automaton agent pool: coordinate embarrassingly-parallel agent jobs.
An :class:AgentPool runs a batch of caller-defined agent jobs in parallel
and gathers their outputs under a single checkpoint root, with crash-safe,
definitive per-job completion markers and no resuming of unfinished agents.
Automaton stays content-free about what a job does: the caller supplies a
runner callable that performs the work (typically building a
:class:~automaton.sandbox.Sandbox run) and writes artifacts into each job's
output_dir.
The concrete :class:MPIAgentPool requires mpi4py (the automaton[mpi]
extra). It is imported lazily here so that import automaton.pool works even
without mpi4py installed; accessing :class:MPIAgentPool in that case raises a
clear :class:ImportError.
AgentPool
¶
AgentPool(jobs: Iterable[Any], runner: Runner, *, checkpoint_root: Path, resume: bool = True, done_check: DoneCheck | None = None, clean_job: CleanJob | None = None, write_marker: bool = True, stop_check: 'StopCheck | None' = None)
Bases: ABC
Abstract coordinator for a batch of parallel agent jobs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
jobs
|
Iterable[Any]
|
Opaque, caller-defined job payloads. They are canonicalized into
:class: |
required |
runner
|
Runner
|
Callable that executes a single job and writes its artifacts into the
job's |
required |
checkpoint_root
|
Path
|
Root directory holding per-job subdirectories and the manifest. |
required |
resume
|
bool
|
If True (default), jobs with a valid done marker are skipped; any unfinished job directory is wiped and re-run. If False, all job directories are wiped and every job re-run. |
True
|
done_check
|
DoneCheck
|
Predicate deciding whether a job is already done (and skippable on
resume). Defaults to the built-in :data: |
None
|
clean_job
|
CleanJob
|
Callable that prepares a clean slate for a job that is about to run.
Defaults to :func: |
None
|
write_marker
|
bool
|
If True (default), a :data: |
True
|
stop_check
|
StopCheck
|
Predicate polled by the scheduler between dispatches. When it returns
True, no further new jobs are dispatched; jobs already running are
left to finish. Defaults to |
None
|
Source code in automaton/pool/base.py
pending_jobs
¶
pending_jobs() -> list[AgentJob]
Return jobs still needing execution, honoring the checkpoint store.
With resume=True, jobs judged done (by :meth:_is_done) are skipped
and any unfinished remnant is cleaned. With resume=False, every job
is cleaned and returned. Never resume an unfinished agent — clean and
start fresh.
Source code in automaton/pool/base.py
completed_results
¶
completed_results() -> list[JobResult]
Load recorded results for all already-done jobs.
When the built-in marker is used, the recorded :class:JobResult is
loaded from it. When a custom done_check reports done but no marker
is present (e.g. write_marker=False), a minimal success result is
synthesized so the returned batch still covers every done job.
Source code in automaton/pool/base.py
execute_job
¶
Run one job via the runner, writing a done marker on success only.
A runner exception is caught and reported as a failed
:class:JobResult; no done marker is written, so the job is retried on
a subsequent resume.
Source code in automaton/pool/base.py
run
abstractmethod
¶
run() -> list[JobResult]
Execute all pending jobs and return results for the full batch.
Implementations must include results for jobs already completed in a
prior run (via :meth:completed_results) so the return value covers the
entire job set, not just the ones run this invocation.
Source code in automaton/pool/base.py
AgentJob
dataclass
¶
A single unit of work handed to an :class:AgentPool.
Job identity is canonical and assigned by the pool at ingest time from the job's position in the input sequence; it is stable across resumes.
Attributes:
| Name | Type | Description |
|---|---|---|
index |
int
|
Canonical ordinal assigned by insertion order into the pool. |
job_id |
str
|
Canonical, filesystem-safe identifier derived from :attr: |
payload |
Any
|
Opaque, caller-defined description of the work. The pool never inspects this; it is passed verbatim to the runner callable. |
output_dir |
Path
|
Per-job directory ( |
JobResult
dataclass
¶
JobResult(job_id: str, success: bool, output_dir: str, returncode: int | None = None, summary: dict[str, Any] = dict(), error: str | None = None)
Lightweight, JSON-serializable result of a finished job.
This is the only thing that crosses the MPI boundary from a worker back
to the coordinator. Heavy artifacts stay on the (shared) filesystem in the
job's :attr:AgentJob.output_dir; here we carry paths as strings and keep
summary small.
Attributes:
| Name | Type | Description |
|---|---|---|
job_id |
str
|
Canonical job identifier this result corresponds to. |
success |
bool
|
Whether the runner completed the job cleanly. |
output_dir |
str
|
String path to the job's output directory (artifacts live here). |
returncode |
int | None
|
Optional process return code reported by the runner. |
summary |
dict
|
Small, caller-defined, JSON-serializable summary (e.g. usage totals). |
error |
str | None
|
Failure detail when |
to_dict
¶
Return a plain JSON-serializable dict representation.
Source code in automaton/pool/job.py
from_dict
classmethod
¶
from_dict(data: dict[str, Any]) -> JobResult
Reconstruct a :class:JobResult from :meth:to_dict output.
Source code in automaton/pool/job.py
JobStatus
¶
Bases: str, Enum
Lifecycle status of a job within a pool run.
SerialAgentPool
¶
SerialAgentPool(jobs: Iterable[Any], runner: Runner, *, checkpoint_root: Path, resume: bool = True, done_check: DoneCheck | None = None, clean_job: CleanJob | None = None, write_marker: bool = True, stop_check: 'StopCheck | None' = None)
Bases: AgentPool
Run all pending jobs sequentially in the current process.
The returned list covers the full job batch (previously-completed plus freshly-run), ordered by canonical job index.