feat: inject periodic mid-loop reminder every 5 turns to counter instruction drift#211
Conversation
Review: feat: inject periodic mid-loop reminder every 5 turnsWhat's good: The implementation is clean and well-contained. Concerns1. Wording diverges from
On any turn where a write call first occurs and it's a multiple-of-5 (e.g. the very first write happens at turn 5), both sets fire in the same tool result and the model receives two slightly different phrasings of the same rule back-to-back. Using the exact text from 2. No opt-out path for custom system prompts Operators overriding the default instructions via RecommendationMerge after addressing concern #1 (wording consistency) or adding a comment explaining why the divergent phrasing is intentional. Concern #2 is lower priority — acceptable to track as a follow-up if the feature ships first. Generated by Claude Code |
Long sessions cause models to forget earlier constraints (git rules, edit discipline, test requirements). The event-driven reminders in AGENT_REMINDERS fire at most once per run; they don't re-anchor the model after many turns. This adds a lightweight periodic reminder that appends a short [reminder: ...] block to the last tool result every PERIODIC_REMINDER_INTERVAL (5) turns — cheap (~10 tokens) and effective at preventing drift without disrupting short sessions. Part of #19 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
5ac91fe to
cf92fdc
Compare
|
Rebased onto current
All 716 tests pass (6 new from this PR). Branch is now conflict-free and ready for review. Generated by Claude Code |
Re-review: feat: inject periodic mid-loop reminder every 5 turns (post-rebase, SHA
|
The periodic reminder text diverged from AGENT_REMINDERS, teaching the model slightly different versions of the same rules across two channels (e.g. "commit only when explicitly asked" vs "never commit or push without an explicit user request"). Derive PERIODIC_REMINDER_TEXT from AGENT_REMINDERS so both channels use identical wording and can't drift apart as reminders are added or changed. Also moves AGENT_REMINDERS before the periodic reminder block to reflect the new dependency order. Part of #19 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Addressed concern #1 from the re-review (commit What changed:
This means both reminder channels now use identical phrasing and can't drift apart as entries are added or changed in the future. Concern #2 (no opt-out path for Generated by Claude Code |
|
Re-review following the wording fix in commit Generated by Claude Code |
Summary
buildPeriodicReminder(turn)tosrc/core/prompt.tsthat returns a compact[reminder: ...]block everyPERIODIC_REMINDER_INTERVAL(5) turns, and empty string otherwiseapplyReminderToLastResultinsrc/core/agent.tsalongside the existing event-driven remindersprompt.test.tsand 3 integration tests inagent.test.tscovering: fires at multiples of the interval, silent before the interval, fires again at the second multipleRelated issue
Part of #19 — item 5: "Mid-loop system-reminder injection"
Why
Event-driven reminders (
AGENT_REMINDERS) fire at most once per run and only when specific tools are called (writes, git). In long sessions the model drifts from git rules, edit discipline, and testing requirements. A periodic reminder re-anchors it cheaply (~10 tokens every 5 turns) without disrupting short sessions where the interval is never reached.Test plan
npm run typecheck && npm run lint && npm run format:check && npm test— all pass (654 tests, 0 failures)buildPeriodicReminderunit tests: fires at turn 5, 10; silent at turns 1–4; silent at turn 0tool_resultevent at exactly turn 5 and turn 10; absent before🤖 Generated with Claude Code
Generated by Claude Code