AI/Tasks/OrchestratorUpgrades/Orchestrator_Phase01_StateModelAndDecisionPipeline_Implementation.txt

PHASE 01 IMPLEMENTATION PROMPT - STATE MODEL AND DECISION PIPELINE
 
Goal:
Implement an explicit state model and typed decision pipeline so the orchestrator owns a predictable run lifecycle without hidden mutable state.
 
Inputs:
- AI/Tasks/OrchestratorUpgrades/Orchestrator_Phase01_StateModelAndDecisionPipeline_Strict.txt
- AI/Tasks/OrchestratorUpgrades/Overview.txt
 
Required code work:
- Replace or wrap the mutable run-loop state with explicit state records and reducer-friendly flow contracts.
- Split `ProcessIterationAsync` or equivalent orchestration logic into named phases with typed outcomes.
- Define a clear transition model that captures continue, retry, finalize, require clarification, fail, and block states.
- Centralize state mutation and attach invariants to finalization or required-output transitions.
- Keep the new transition model compatible with the existing orchestrator entry points.
 
Implementation constraints:
- Keep policy, authorization, and retry behavior separate from this state model refactor.
- Preserve current behavior except where hidden transition logic is made explicit.
- Do not implement full tool registry, authorization hardening, retry budgets, or telemetry privacy changes in this phase.
 
Minimum tests to add/update:
- State transition tests covering valid and invalid transitions.
- Phase-order tests for planning, validation, tool execution, and finalization.
- Invariant tests for required-output and finalization conditions.
- Regression tests for state mutation and hidden side-effect removal.
 
Validation commands:
- dotnet build src/TechToolbox.Agent/TechToolbox.Agent.csproj -c Release
- dotnet test src/TechToolbox.Agent/Tests/TechToolbox.Agent.Tests.csproj -c Release --filter "Orchestrator|State|Decision|Pipeline|Transition|Strict"
 
Deliverable:
Return changed files, the final state model shape, and proof that orchestration transitions are explicit and deterministic.