ExecutionPlan — typed multi-step workflow tracking¶
When an agent decomposes a user request into discrete steps (mesh →
solve → analyze, research → synthesize → respond, …), the consumer
usually wants to visualize progress: a task list in the UI with per-
task status updates streaming in as work happens. Before
ExecutionPlan, every consumer maintained its own Pydantic model,
its own status-flip method, and its own hand-rolled EventBus glue
to notify the frontend.
ExecutionPlan is the canonical primitive. It wraps a list of
PlanTasks (optionally with PlanSubtasks), exposes a single
set_task_status() that flips state and emits a typed
plan.task.updated event, and keeps to_sse_init() byte-stable for
frontend compatibility across Orqest releases.
Minimal example¶
import asyncio
from orqest import ExecutionPlan, PlanTask, PlanSubtask
from orqest.observability import EventBus
async def main() -> None:
plan = ExecutionPlan(
tasks=[
PlanTask(
id="mesh",
title="Generate mesh",
subtasks=[PlanSubtask(id="mesh.geo", title="Write .geo")],
),
PlanTask(id="solve", title="Run solver", dependencies=["mesh"]),
]
)
bus = EventBus()
bus.subscribe_all(lambda e: print(f"{e.event_type}: {e.data}"))
# Initial payload the frontend renders once
await plan.emit_init(bus, agent_name="orchestrator")
# Later — flip a subtask as work starts and completes
await plan.set_task_status(
"mesh", "in-progress", subtask_id="mesh.geo", bus=bus,
agent_name="orchestrator",
)
await plan.set_task_status(
"mesh", "completed", subtask_id="mesh.geo", bus=bus,
agent_name="orchestrator",
)
asyncio.run(main())
Schema contract¶
Two payload shapes are stable — frontend code depends on them:
to_sse_init() → {"tasks": [...]} where each task has id,
title, description, status, priority, level,
dependencies, subtasks.
set_task_status() return value → {"task_id": ..., "status": ...}
plus "subtask_id": ... when updating a subtask. The same shape lands
on the EventBus as the data payload of plan.task.updated events.
Statuses¶
PlanStatus = "pending" | "in-progress" | "completed" | "failed" |
"skipped". No additional values are introduced without a frontend
coordination change.
When to reach for this¶
- You want a typed plan model instead of a handful of dict utilities.
- You want plan updates to flow onto your existing
EventBussubscribers (metrics, SSE sidecar, logging) without extra wiring. - You want a consistent wire format across multiple Orqest consumers so their frontends can share rendering code.
Reference¶
ExecutionPlan ¶
Ordered list of tasks + helpers to emit status updates.
Tasks are mutable: set_task_status rewrites a task (or subtask)
in place and returns the payload the consumer should forward to the
frontend. When an EventBus is attached, the same payload is also
emitted as an :class:AgentEvent so any subscriber (e.g. the SSE
sidecar) can observe the change.
enable_ui_events ¶
Opt into dual-emission of typed ui.plan.{init,delta} events.
When enabled, :meth:set_task_status and :meth:emit_init
emit a parallel typed event alongside the legacy plan.init
/ plan.task.updated events. The legacy events stay
identical so existing consumers continue to work; new
consumers subscribe to the typed channel via
:class:UIEmitter conventions.
Returns self for chaining.
Source code in orqest/plan/execution_plan.py
to_sse_init ¶
as_component ¶
Wrap this plan as a :class:PlanComponent for the
generative-UI pipeline.
Source code in orqest/plan/execution_plan.py
set_task_status
async
¶
set_task_status(
task_id: str,
status: PlanStatus,
*,
subtask_id: str | None = None,
bus: EventBus | None = None,
agent_name: str = "unknown",
) -> dict[str, Any]
Flip a task (or subtask) status and return the update payload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_id
|
str
|
ID of the :class: |
required |
status
|
PlanStatus
|
New status value. |
required |
subtask_id
|
str | None
|
If provided, update the matching subtask rather than the parent task. |
None
|
bus
|
EventBus | None
|
Optional :class: |
None
|
agent_name
|
str
|
Tagged on emitted events for source attribution. |
'unknown'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dict carrying |
dict[str, Any]
|
|
dict[str, Any]
|
consumer forwards to the frontend, so it must remain stable. |
Source code in orqest/plan/execution_plan.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
emit_init
async
¶
Publish the initial plan to bus as a plan.init event.
Convenience for consumers that always want the plan mirrored to
the bus right after construction. Returns the same payload as
:meth:to_sse_init so the caller can also stream it inline.
Source code in orqest/plan/execution_plan.py
from_tasks_json
classmethod
¶
Construct from either a JSON string, a bare task list, or a
{"tasks": [...]} dict. Useful when an LLM produces the plan
as an opaque JSON string.
Source code in orqest/plan/execution_plan.py
PlanTask ¶
A top-level task in an :class:ExecutionPlan.
PlanSubtask ¶
A subtask nested under a :class:PlanTask.