agora.fleet.control

Per-project orchestrator control: pause/abort/redirect/note plumbing.

OrchestratorControl is constructed once per run_project call and:

  • Registered on the project’s EventDispatcher as the /agora command handler (scoped to the project room).

  • Awaited at task-dispatch boundaries inside _run_phase so pause/abort can take effect between tasks (never mid-LLM-call).

  • Passed into ToolContext so agent runtimes consume fresh observer notes + any pending redirect at the start of each turn.

The only mutable state is a few asyncio primitives plus two dicts; all mutations happen on the same event loop.

Classes

OrchestratorControl

Mutable control surface for one project's orchestrator run — the bridge between the Matrix human-observer room and the run loop.

Exceptions

AbortedError

Raised when /agora abort fires — transitions the project to FAILED.

exception agora.fleet.control.AbortedError[source]

Bases: AgoraError

Raised when /agora abort fires — transitions the project to FAILED.

class agora.fleet.control.OrchestratorControl[source]

Bases: object

Mutable control surface for one project’s orchestrator run — the bridge between the Matrix human-observer room and the run loop. Holds the pause / abort events the loop polls at turn boundaries, plus the redirect / note / comment channels a human uses to steer a live run (keyed so a reaction or reply on a posted write-event card resolves back to its task).

project_room_id: str
matrix_client: MatrixClientProtocol
pause_event: Event
abort_event: Event
notes: list[str]
agent_redirects: dict[str, str]
task_comments: dict[str, list[str]]
task_card_events: dict[str, str]

event_id (of a write-event card we posted) → task_id it belongs to. Lets handle_reaction() and handle_reply() resolve a reactor’s target back to the task it affects.

task_reactions: dict[str, list[tuple[str, str]]]

task_id -> [(sender, emoji_key), ...] aggregate of all reactions on task cards belonging to that task. Surfaced at REVIEW time so the reviewer sees quick signal without scrolling.

pending_decisions: dict[str, Future[str]]

decision_id → asyncio.Future — the primitive the await_user_decision inner tool blocks on. Resolved by resolve_decision() when a poll response with a matching POLL_DECISION_ID_KEY arrives.

decision_responses: dict[str, str]

decision_id → answer_id — populated as decisions resolve, kept as a record of what the user chose (useful for debugging and for late-arriving tool calls that raced the poll response).

poll_event_to_decision: dict[str, str]

poll_event_id → decision_id — lookup so the dispatcher can route a poll response event (which only knows the poll event id) to the right decision future. Populated by register_decision_poll().

decision_reaction_map: dict[str, tuple[str, dict[str, str]]]

message_event_id → (decision_id, {emoji_key → answer_id}) — populated by register_decision_reactions() when a decision-stage posts its question card. When a reaction arrives on a registered message, the mapped answer resolves the decision. This is the Element-native fallback when MSC3381 poll widgets don’t render for a user’s client.

plan_draft: Any = None

Mutable plan-authoring draft shared across ALL tasks in a single run_project. Lives on OrchestratorControl rather than ToolContext because a fresh ToolContext is constructed per task attempt, so the draft would otherwise be lost between the author_* stages and the finalize_plan stage. The plan-authoring tools in agora.fleet.inner_tools resolve to this shared instance via the per-task ctx.control attribute.

abort_reason: str = ''
async handle_command(room_id, cmd)[source]

Dispatcher callback. Ignores commands aimed at other rooms or /agora review.

async wait_unpaused()[source]

Await at task-dispatch boundaries. Blocks while paused.

is_aborted()[source]
raise_if_aborted()[source]
consume_notes()[source]

Take a snapshot of pending notes. Notes are kept so later turns still see them.

consume_redirect(agent_name)[source]

Pop a pending redirect for agent_name (one-shot).

consume_task_comments(task_id)[source]

Drain and return any queued comments for task_id.

Comments are consumed one-shot — they’re injected into the next task attempt’s system prompt and then cleared. On loopback the reviewer can queue new comments based on what they observed.

register_task_card(event_id, task_id)[source]

Remember the event_id a write-event card was posted under, so later reactions / replies to that card can be resolved to task_id.

resolve_task_from_event(event_id)[source]

Which task a given card event belongs to, if known.

async handle_reaction(room_id, reaction)[source]

EventDispatcher callback. Two routing branches:

  1. If the reaction targets a registered decision-question card, map the emoji to an answer and resolve the decision future.

  2. Otherwise, if the target is a task-card, record the reaction in task_reactions for later review-summary rendering.

A reaction can only refer to one prior event, so the branches don’t collide — the same dispatcher feeds both code paths unambiguously.

async handle_reply(room_id, reply)[source]

EventDispatcher callback. When the reply targets a known task card, route its body as an implicit /agora comment for that task.

register_decision_reactions(decision_id, message_event_id, emoji_to_answer)[source]

Map a plain-message question card to its decision + emoji→answer table.

Called by decision stages right after posting the question so a user reacting with one of the registered emojis will resolve the pending future via handle_reaction().

register_decision_poll(decision_id, poll_event_id)[source]

Record the poll_event_id → decision_id mapping so a later m.poll.response can be routed to the right waiting future.

The caller (typically the await_user_decision tool) must have already placed a Future in pending_decisions[decision_id] before calling this method.

resolve_decision(decision_id, answer_id)[source]

Complete the Future for decision_id with answer_id.

Returns True if a waiting future was actually resolved; False if the decision was already resolved or unknown (common if the user clicks twice). Always records the answer in decision_responses.

decision_id_for_poll(poll_event_id)[source]

Reverse lookup used by the sync dispatcher.

async await_decision(decision_id, timeout_seconds=300.0)[source]

Block until the user resolves the decision. Creates the Future lazily.

If the decision was already resolved (e.g. the user clicked before the tool wired its future), returns the cached answer immediately. Raises asyncio.TimeoutError if no response arrives within timeout_seconds.

__init__(project_room_id, matrix_client, pause_event=<factory>, abort_event=<factory>, notes=<factory>, agent_redirects=<factory>, task_comments=<factory>, task_card_events=<factory>, task_reactions=<factory>, pending_decisions=<factory>, decision_responses=<factory>, poll_event_to_decision=<factory>, decision_reaction_map=<factory>, plan_draft=None, abort_reason='')