Skip to content

[Phase 4] Unify ReactAgent context assembly with TaskContextPackager #431

Description

@frankbria

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:

  1. External engines (Claude Code, OpenCode): TaskContextPackager.build() → prompt string → adapter
    Used in runtime.py line 687-688

  2. 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:

  1. Use TaskContextPackager.build_agent_context() for context assembly
  2. Keep ReactAgent's 3-layer formatting as a ReactAgent-specific renderer on top
  3. Remove direct ContextLoader usage from ReactAgent

Acceptance Criteria

  • ReactAgent uses TaskContextPackager internally for context loading
  • ReactAgent's 3-layer prompt format is preserved (no behavior change)
  • ContextLoader import can be removed from react_agent.py
  • Integration test confirms same effective prompt content

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    architectureSystem architecture and design patternsenhancementNew feature or requestphase-4.1Phase 4.1: Agent Adapter Foundation (protocol, registry, verification wrapper)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions