A long-running code generation agent starts a session by deciding to use PostgreSQL as the database layer. After processing 80,000 tokens of code context, the agent begins generating SQLite queries in new modules, contradicting its earlier decision. No errors occur. What is causing this behavior?
Select an answer to reveal the explanation.
Short Explanation
You’re seeing context drift. The PostgreSQL decision got buried deep in the context window, so newer code context pushed it out of effective attention. Put that decision in a persistent decisions log and re-inject it every step.
Full Explanation
Context drift occurs in long-running agent sessions when early decisions or constraints are effectively lost because the context window is filled with newer content and the attention mechanism gives decreasing weight to distant earlier tokens. LLMs do not have perfect recall of all tokens in a very long context; information at the start of a long context is less reliably attended to than information near the current position. The architectural solution is to promote critical decisions — such as technology choices, architectural constraints, and scope boundaries — into a persistent decisions log that is maintained outside the agent's main context and re-injected into the context at the beginning of each reasoning step or periodically throughout a long session. This ensures foundational decisions remain in the high-attention portion of the context window regardless of how much other content has been processed. The memory-store-cleared explanation would produce a distinct symptom: the agent would lose all session context, not just the database choice. The scenario describes selective forgetting of an early decision while continuing to function correctly otherwise, which is consistent with context drift, not a memory wipe. The SQLite-file-override explanation is a possible contributing factor if a large SQLite-specific file appeared late in the session, but the root cause is the architecture's failure to reinforce the foundational PostgreSQL decision; the SQLite file is an opportunistic trigger, not the root cause. The tool-allow-list explanation would produce errors or refusals when PostgreSQL tools are invoked, not silent use of a different database, and the scenario says no errors occur. Decisions logs with periodic context re-injection prevent context drift in long-running agent sessions.