Auto-Read Injection for Edit Tool (proposal + example implementation) #1655
DirkScharff
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
When using smaller models (like devstral), they frequently attempt to use the Edit tool without first reading the file, causing failures and requiring manual retry loops. This creates a frustrating UX and doesn't help the model learn the correct pattern.
Proposed Solution
When an Edit tool call fails due to "no prior read", automatically inject a Read operation into the conversation history, making it appear as if the model executed the correct sequence all along.
Current Flow (Broken)
Model → Edit tool (without reading first)
Tool → ❌ Error: "File must be read before editing"
Model → Must see error and retry
Proposed Flow (Auto-Corrected)
Model → Edit tool (without reading first)
Tool → Detects missing read, performs it automatically
Rewrites conversation context to show:
✓ Read tool call (injected)
✓ Read result (actual file contents)
✓ Edit tool call (original request)
✓ Edit result (success/failure based on validity)
Model → Sees correct Read→Edit pattern in context
Benefits
Implementation
The key insight is that the Read requirement exists to prevent blind edits - but if the tool orchestrator does the read internally before executing the edit, that safety goal is still achieved. We just rewrite the context to show what should have happened.
I have a working implementation in a fork that demonstrates this behavior. The context injection happens at the conversation orchestrator level, tracking read state per-turn and intercepting edit failures.
I have made a (agentic driven) implementation without any real (human) review in https://github.com/DirkScharff/crush/tree/feat/edit-tool-auto-read if anyone is interested. I'm not even proficient in Golang so I'd rather not be responsible for a real PR. Feel free to incorporate the idea if you think its a good idea.
Basic implementation spec for the agent attached.
edit-tool-auto-read-proposal.md
Beta Was this translation helpful? Give feedback.
All reactions