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:
-
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.
-
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."
-
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)
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 --verboseon cf-test:list_filesread_file(x5)search_codebaselist_filesread_filecreate_fileRoot Causes
1. Initial user message mandates reading (react_agent.py:237-238)
This creates a strong bias toward exploration before implementation.
2. System prompt includes file PATHS but not file CONTENTS (react_agent.py:509-524)
The agent sees the file tree but must call
read_filetool 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 intocontext.loaded_files. But_build_system_prompt()never convertsloaded_filesinto a prompt section. The prepared content is wasted.4. System rules reinforce reading (react_agent.py:59-89)
Combined with the initial message, this creates a double mandate for exploration.
Proposed Fix
Three complementary changes:
Include loaded file contents in system prompt: Add a "## Relevant Source Files" section in
_build_system_prompt()using the already-loadedcontext.loaded_files. The ContextLoader already does the relevance scoring and token budgeting — the data just needs to be surfaced.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."
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:
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)