Skip to content

[Phase 2.5] ReactAgent wastes 30% of iteration budget on redundant file exploration #373

Description

@frankbria

Problem

The ReactAgent spends 9 out of 30 iterations (30%) reading files before creating its first file. On a 30-iteration budget where each file create + lint-fix cycle takes 3-5 iterations, this leaves only enough budget for 4-7 files — insufficient for most tasks.

Observed Behavior

Running codeframe work start <id> --execute --engine react --verbose on cf-test:

Iteration Tool Purpose
1 list_files Discover project structure
2-6 read_file (x5) Read individual files
7 search_codebase Search for patterns
8 list_files Re-discover structure
9 read_file Read one more file
10 create_file First write

Root Causes

1. Initial user message mandates reading (react_agent.py:237-238)

"Start by reading relevant files to understand the current "
"codebase, then make the necessary changes."

This creates a strong bias toward exploration before implementation.

2. System prompt includes file PATHS but not file CONTENTS (react_agent.py:509-524)

for fi in context.file_tree[:50]:
    tree_lines.append(f"  {fi.path}")  # PATHS ONLY, NO CONTENT

The agent sees the file tree but must call read_file tool to see what's actually in each file.

3. ContextLoader loads file contents but they're discarded (context.py:476-542 vs react_agent.py:497-551)

ContextLoader._load_file_contents() identifies relevant files and loads their content into context.loaded_files. But _build_system_prompt() never converts loaded_files into a prompt section. The prepared content is wasted.

4. System rules reinforce reading (react_agent.py:59-89)

- ALWAYS read a file before editing it. Never assume file contents.

Combined with the initial message, this creates a double mandate for exploration.

Proposed Fix

Three complementary changes:

  1. Include loaded file contents in system prompt: Add a "## Relevant Source Files" section in _build_system_prompt() using the already-loaded context.loaded_files. The ContextLoader already does the relevance scoring and token budgeting — the data just needs to be surfaced.

  2. Revise initial user message: Change from "Start by reading relevant files" to something like "Implement the task. The system prompt includes relevant context. Use tools to explore further only if needed."

  3. Soften the "always read before editing" rule: On small projects where context is pre-loaded, the agent doesn't need to re-read files it's about to create (which don't exist yet).

Expected Improvement

With relevant file contents pre-loaded:

  • Agent should start writing by iteration 2-3 (instead of 10)
  • Gains 7+ iterations for actual implementation
  • Could complete 2-3 more files per task

Files

  • codeframe/core/react_agent.py_build_system_prompt() (line 497), initial message (line 232), rules (line 59)
  • codeframe/core/context.py_load_file_contents() (line 476), TaskContext.loaded_files (line 119)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingphase-2Phase 2: Server Layer as Thin Adapter

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions