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
EventDispatcheras the/agoracommand handler (scoped to the project room).Awaited at task-dispatch boundaries inside
_run_phaseso pause/abort can take effect between tasks (never mid-LLM-call).Passed into
ToolContextso 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
Mutable control surface for one project's orchestrator run — the bridge between the Matrix human-observer room and the run loop. |
Exceptions
Raised when /agora abort fires — transitions the project to FAILED. |
- exception agora.fleet.control.AbortedError[source]
Bases:
AgoraErrorRaised when /agora abort fires — transitions the project to FAILED.
- class agora.fleet.control.OrchestratorControl[source]
Bases:
objectMutable 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).
- matrix_client: MatrixClientProtocol
- pause_event: Event
- abort_event: Event
- task_card_events: dict[str, str]
event_id (of a write-event card we posted) → task_id it belongs to. Lets
handle_reaction()andhandle_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 theawait_user_decisioninner tool blocks on. Resolved byresolve_decision()when a poll response with a matchingPOLL_DECISION_ID_KEYarrives.
- 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 byregister_decision_poll().
- decision_reaction_map: dict[str, tuple[str, dict[str, str]]]
message_event_id → (decision_id, {emoji_key → answer_id})— populated byregister_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 onOrchestratorControlrather thanToolContextbecause a fresh ToolContext is constructed per task attempt, so the draft would otherwise be lost between theauthor_*stages and thefinalize_planstage. The plan-authoring tools inagora.fleet.inner_toolsresolve to this shared instance via the per-taskctx.controlattribute.
- async handle_command(room_id, cmd)[source]
Dispatcher callback. Ignores commands aimed at other rooms or /agora review.
- consume_notes()[source]
Take a snapshot of pending notes. Notes are kept so later turns still see them.
- 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.
- async handle_reaction(room_id, reaction)[source]
EventDispatcher callback. Two routing branches:
If the reaction targets a registered decision-question card, map the emoji to an answer and resolve the decision future.
Otherwise, if the target is a task-card, record the reaction in
task_reactionsfor 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 commentfor 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_idmapping so a laterm.poll.responsecan be routed to the right waiting future.The caller (typically the
await_user_decisiontool) must have already placed a Future inpending_decisions[decision_id]before calling this method.
- resolve_decision(decision_id, answer_id)[source]
Complete the Future for
decision_idwithanswer_id.Returns
Trueif a waiting future was actually resolved;Falseif the decision was already resolved or unknown (common if the user clicks twice). Always records the answer indecision_responses.
- 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.TimeoutErrorif no response arrives withintimeout_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='')