agora.fleet.stage_runner

Micro-stage task execution.

A StagedTask splits one logical task into a sequence of focused LLM calls. Each Stage gets its own fresh message history, a small max_iterations cap, and only the files it needs pre-loaded into the user message. The task’s postconditions are evaluated once at the end over whatever the cumulative stages produced.

Two wins for weak models:
  1. Fresh context per stage — no 37-message accumulation blowing past num_ctx.

  2. One action per stage — the model decides less, hallucinates less.

Classes

Stage

One focused LLM call in a staged task — OR a declarative decision stage.

StageRunner

Execute a StagedTask stage-by-stage, then evaluate the task spec.

StagedTask

A Task augmented with an ordered sequence of stages.

class agora.fleet.stage_runner.Stage[source]

Bases: object

One focused LLM call in a staged task — OR a declarative decision stage.

When kind == "llm" (the default), instruction + context_files feed a user-message into the agent’s tool-use loop bounded by max_iterations. When kind == "decision", decision_id / question / options / output_path describe a Matrix poll + reaction card the framework posts on the LLM’s behalf; no LLM call is made. The dispatch happens in StageRunner.execute_staged_task.

instruction: str = ''

The user-message for this stage. Should describe ONE action. Empty when kind='decision'.

context_files: tuple[str, ...] = ()

Files (relative to work_dir) to include verbatim in the user message.

max_iterations: int = 5

Per-stage iteration cap — much smaller than a normal task’s 20.

validation: Callable[[ToolContext], tuple[bool, str]] | None = None

Optional check run after the stage completes. Returns (ok, reason).

name: str = ''

Optional identifier for logging.

kind: str = 'llm'
decision_id: str = ''
question: str = ''
options: tuple[str, ...] = ()
output_path: str = ''
validation_args: dict[str, str]
hide_tools: tuple[str, ...] = ()
__init__(instruction='', context_files=(), max_iterations=5, validation=None, name='', kind='llm', decision_id='', question='', options=(), output_path='', validation_args=<factory>, hide_tools=())
class agora.fleet.stage_runner.StagedTask[source]

Bases: object

A Task augmented with an ordered sequence of stages.

The wrapped Task provides the id, spec, postconditions, and agent assignment. The stages drive the actual LLM calls.

task: Task
stages: list[Stage]
__init__(task, stages=<factory>)
class agora.fleet.stage_runner.StageRunner[source]

Bases: object

Execute a StagedTask stage-by-stage, then evaluate the task spec.

Built for hard-to-generate tasks where a single 20-iteration loop blows past num_ctx or lets the model drift. The runner reuses the underlying AgentRuntime machinery (system prompts, tool execution, postcondition evaluation) but resets the message history at every stage boundary, capping per-stage iterations aggressively. Two wins for weak models: fresh context per stage so accumulated tokens don’t pile up, and one-action stages so the model decides less and hallucinates less.

Three stage kinds are dispatched here:

  • "llm" (default) — a focused agent turn against the configured LLM.

  • "decision" — bypasses the LLM, posts a Matrix poll + reaction card, waits for the user’s answer, writes the chosen option id to stage.output_path.

  • "framework" — pure mechanical step (e.g. framework_finalize_plan) that the framework executes itself rather than asking the LLM.

__init__(runtime)[source]
async execute_staged_task(staged, identity)[source]

Run every stage in order, then evaluate the wrapped task’s postconditions.

Returns the same TaskResult shape as a non-staged task — postconditions are checked once at the end over the cumulative artefacts, so callers can treat staged and non-staged tasks uniformly.

On stage failure (validation predicate returns False, decision-stage timeout, framework-stage exception), the runner short-circuits and returns a failure result without running later stages. The remaining stages do not execute.