Summary
ReactAgent._build_system_prompt() and TaskContextPackager both assemble context from the same sources (TaskContext, PRD, preferences, tech stack, files) but via independent code paths. This creates a maintenance risk where changes to context assembly need to be made in two places.
Parent issue: #408
Current State
Two parallel context assembly paths exist:
-
External engines (Claude Code, OpenCode): TaskContextPackager.build() → prompt string → adapter
Used in runtime.py line 687-688
-
Internal ReactAgent: ReactAgent._build_system_prompt() → 3-layer system prompt
Directly calls ContextLoader.load() and formats its own prompt
Both pull from the same ContextLoader + TaskContext but format independently.
Proposed Change
Refactor ReactAgent._build_system_prompt() to:
- Use
TaskContextPackager.build_agent_context() for context assembly
- Keep ReactAgent's 3-layer formatting as a ReactAgent-specific renderer on top
- Remove direct
ContextLoader usage from ReactAgent
Acceptance Criteria
Risk Assessment
Medium risk — ReactAgent's prompt is complex (3-layer, adaptive complexity hints, token budget management). The refactor must not change the effective prompt content or break the agent's reasoning.
Dependencies
Summary
ReactAgent._build_system_prompt() and TaskContextPackager both assemble context from the same sources (TaskContext, PRD, preferences, tech stack, files) but via independent code paths. This creates a maintenance risk where changes to context assembly need to be made in two places.
Parent issue: #408
Current State
Two parallel context assembly paths exist:
External engines (Claude Code, OpenCode):
TaskContextPackager.build()→ prompt string → adapterUsed in
runtime.pyline 687-688Internal ReactAgent:
ReactAgent._build_system_prompt()→ 3-layer system promptDirectly calls
ContextLoader.load()and formats its own promptBoth pull from the same
ContextLoader+TaskContextbut format independently.Proposed Change
Refactor
ReactAgent._build_system_prompt()to:TaskContextPackager.build_agent_context()for context assemblyContextLoaderusage fromReactAgentAcceptance Criteria
Risk Assessment
Medium risk — ReactAgent's prompt is complex (3-layer, adaptive complexity hints, token budget management). The refactor must not change the effective prompt content or break the agent's reasoning.
Dependencies