Skip to content

Reduce wasted context: AGENTS.md is re-injected in full on every tool-result <system-reminder> #46208

Closed as not planned

Description

@ChHerman

Problem

Every time a tool result is returned, the runtime appends the full matched AGENTS.md as a <system-reminder> to the context. Because LLM context is cumulative, the same full AGENTS.md ends up occupying the window N times (once per tool result), even though nothing changed.

Measured: a single simple status query triggering 2 tool reads re-injected a ~12-15k-token AGENTS.md twice, i.e. ~25-30k tokens of pure waste for one trivial query.

Root cause

  • Injection point is per tool-result, not per assistant turn.
  • No content-fingerprinting; identical content is re-appended verbatim.
  • The destination model treats each reminder as authoritative instructions, so none get trimmed.

Proposed designs (composable)

  1. Content-fingerprint dedup — store (path -> {hash, content}); inject full content only on first message; on later messages with unchanged hash, emit a one-line 'unchanged' marker; on change, emit the diff. Prefer file-content hash (or git blob id) over git ref, since uncommitted changes must also be detected.
  2. On-demand instruction loading — keep only a thin scenario->file/section routing table (<2k) resident; fetch sections via a tool (fetch_instruction(file, section)), decoupled from tool returns.
  3. Batching / fewer injection points — merge multiple independent reads in one turn into a single returned batch, reducing per-result reminder emissions.
  4. Layered mounting — resident layer (identity anchors, hard prohibitions, secret red-lines) always on + deduped; scenario layer loaded only on keyword match; on-demand layer loaded via tools.

Acceptance criteria

  • Identical instruction file across K consecutive tool returns appears once as real content + (K-1) 'unchanged' markers.
  • A content change is reflected by the next return.
  • Safety/resident red-line layer is never dropped by dedup.
  • First message still includes full content (avoid cold-start misread).

Non-goals

  • Not changing the role of per-scenario files; dedup targets the injection mechanism, not scenario-loading responsibilities.
  • Out of scope: multi-session write-locking, inter-instruction relative-link validation.

Local mitigation already applied (project-side, for reference)

  • Slimmed the sub-project AGENTS.md (moved large reference tables into per-scenario docs, kept all red-lines/resident rules inline).
  • Status queries now read a single authoritative source in one merged call.

Activity

  1. github-actions commented on Aug 30, 2026

    @github-actions
    Contributor

    This issue doesn't fully meet our contributing guidelines.

    What needs to be fixed:

    • The issue does not use one of the required templates (Bug Report, Feature Request, or Question). Feature requests must have a title starting with [FEATURE]: and use the feature request template with a verification checkbox and description. If this is a bug report, please use the bug report template with the required Description field.

    Please edit this issue to address the above within 2 hours, or it will be automatically closed.


    This issue might be a duplicate of existing issues. Please check:

    If you believe this was flagged incorrectly, please let a maintainer know.

  2. github-actions commented on Aug 30, 2026

    @github-actions
    Contributor

    This issue has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

    Feel free to open a new issue that follows our issue templates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions