diff --git a/docs/reference/plan_execute.md b/docs/reference/plan_execute.md index 69c056a8b..5fdc50700 100644 --- a/docs/reference/plan_execute.md +++ b/docs/reference/plan_execute.md @@ -15,14 +15,78 @@ changeset capture through `ChangeSetStore`. ``` PlanExecutor -├── StrategizeStubActor (read-only, produces decision tree) -├── ExecuteStubActor (legacy stub: sandbox + ChangeSetCapture) -├── RuntimeExecuteActor (runtime: ToolRunner + ChangeSetStore) -├── PlanExecutionContext (plan metadata + resource bindings) -├── PlanLifecycleService (phase transitions, persistence) -└── ErrorRecoveryService (optional — error recording + retry logic) +├── StrategizeStubActor (read-only, produces decision tree) +├── ExecuteStubActor (legacy stub: sandbox + ChangeSetCapture) +├── RuntimeExecuteActor (runtime: ToolRunner + ChangeSetStore) +├── PlanExecutionContext (plan metadata + resource bindings) +├── PlanLifecycleService (phase transitions, persistence) +├── SubplanService (optional — spawn child plans from decisions) +├── SubplanExecutionService (optional — execute spawned child plans) +└── ErrorRecoveryService (optional — error recording + retry logic) ``` +## Subplan Spawning (v3.8.0+) + +When a plan's Strategize phase records `subplan_spawn` or +`subplan_parallel_spawn` decisions, the Execute phase automatically +spawns and executes child plans via the injected `SubplanService` and +`SubplanExecutionService`. + +### Wiring + +Both services are injected as optional constructor parameters: + +```python +from cleveragents.application.services.plan_executor import PlanExecutor +from cleveragents.application.services.subplan_service import SubplanService +from cleveragents.application.services.subplan_execution_service import ( + SubplanExecutionService, +) + +executor = PlanExecutor( + lifecycle_service=lifecycle, + tool_runner=runner, + execution_context=ctx, + subplan_service=subplan_svc, # optional + subplan_execution_service=exec_svc, # optional +) +``` + +When either service is `None`, all subplan spawning logic is skipped +(backward-compatible no-op). + +### Execution Flow + +After the actor completes the Execute phase: + +1. **`_spawn_subplans()`** — queries `SubplanService.get_spawn_decisions()` + for the plan, then calls `SubplanService.spawn()` for each decision, + creating child plan records. +2. **`_execute_subplans()`** — calls `SubplanExecutionService.execute_all()`, + routing sequential `subplan_spawn` decisions through ordered execution + and `subplan_parallel_spawn` groups through concurrent execution. +3. **`_apply_subplan_results_to_plan()`** — propagates child plan failure + information back to the parent plan. When one or more child plans fail, + the parent plan's `error_details` field is annotated with a + `failed_subplan_ids` list. + +### Properties + +| Property | Type | Description | +|----------|------|-------------| +| `subplan_service` | `SubplanService \| None` | Injected subplan service | +| `subplan_execution_service` | `SubplanExecutionService \| None` | Injected execution service | + +### Failure Handling + +Child plan failures are **annotated, not raised**. The parent plan +continues to the Apply phase even if child plans fail; the +`failed_subplan_ids` list in `error_details` allows downstream +consumers to detect and handle failures. + +See [`subplan_service.md`](subplan_service.md) and +[`subplans.md`](subplans.md) for full subplan API reference. + ## Execution Modes | Mode | Actor | Trigger | Output | diff --git a/docs/reference/session_cli.md b/docs/reference/session_cli.md index 852a9ec9c..12d2214b3 100644 --- a/docs/reference/session_cli.md +++ b/docs/reference/session_cli.md @@ -189,6 +189,45 @@ agents session export [--output ] [--force] [--format [--output ] [--force] [--format