Skip to content

[Phase 2.5-C] Implement ReactAgent core loop with system prompt builder #347

Description

@frankbria

Summary

Create codeframe/core/react_agent.py — the core ReAct loop agent that replaces Plan-and-Execute for code generation. This is the central module of the Phase 2.5 redesign.

Acceptance Criteria

  • ReactAgent class in codeframe/core/react_agent.py:
    • run(task_id: str) -> AgentState — main entry point
    • ReAct loop: LLM call with tools → execute tool calls → append results → repeat
    • Max 30 iterations hard cap
    • Termination: text-only response (no tool calls) = agent thinks it's done
    • Temperature 0.0 for deterministic execution
  • System prompt builder with 3-layer structure:
    • Layer 1 (Base): Agent identity, tool descriptions (auto-generated from schemas), core rules, code quality constraints, termination conditions, decision-making autonomy
    • Layer 2 (Project): AGENTS.md/CLAUDE.md content (from agents_config.py), tech stack, file tree summary
    • Layer 3 (Task): Task title/description, PRD content (truncated to 5K), answered blockers
  • Conversation management: builds proper Anthropic API message format with tool_calls and tool_results
  • Intent preview: for HIGH complexity or greenfield tasks, system prompt instructs agent to outline approach before coding
  • Uses adapters/llm/base.py types: Tool, ToolCall, ToolResult
  • Delegates tool execution to tools.py:execute_tool()
  • Final verification: when agent stops calling tools, run all gates (ruff + pytest)
  • If final verification fails: re-enter loop for up to 5 more iterations with error context
  • Tests in tests/core/test_react_agent.py:
    • Loop terminates on text-only response
    • Loop terminates at max iterations
    • Tool calls dispatched correctly
    • System prompt contains all 3 layers
    • Final verification triggered on completion
    • Uses mock LLM provider for unit tests
  • All existing tests pass

Implementation Notes

  • The existing Agent class in agent.py is NOT modified — ReactAgent is a parallel implementation
  • Use MockLLMProvider from adapters/llm/mock.py for testing
  • Verify that the Anthropic adapter can handle multi-turn tool-use conversations (may need minor update to anthropic.py)
  • The system prompt rules from docs/AGENT_V3_UNIFIED_PLAN.md "Base Prompt (Layer 1)" section should be used verbatim
  • context.py:ContextLoader is reused for initial context loading

Dependencies

Subsumed Issues

Reference

  • docs/AGENT_V3_UNIFIED_PLAN.md (Architecture, System Prompt Design)
  • docs/REACT_AGENT_ARCHITECTURE.md (Section 2, 6)
  • docs/AGENT_ARCHITECTURE_CRITIQUE.md (Section 2.2 — hybrid approach)

Metadata

Metadata

Assignees

No one assigned

    Labels

    architectureSystem architecture and design patternsphase-2.5Phase 2.5: Agent Execution Redesign (ReAct)phase-2.5-CPhase C: ReAct Agent Core

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions