gptme-attention-tracker

Decide which workspace files deserve a place in an agent's context window: plugins/gptme-attention-tracker View on GitHub

gptme-attention-tracker — HOT/WARM/COLD context tiers and context-usage history

Decide which workspace files deserve a place in an agent's context window: files gain attention when their keywords come up, decay when unused, and are sorted into HOT (include fully), WARM (include header only) and COLD (leave out) tiers. A companion history log records what was in context each turn, so you can find files that are never used or always co-occur.

Status: experimental. The tools are advisory: they compute tiers and recommendations, but do not themselves rewrite gptme's context. You (or your agent's context script) decide what to include.

Why / when to use it

Agents with large always-included context (lessons, knowledge docs, task files) pay for every token on every turn. This plugin is a building block for trimming that:

Related: gptme-ace (hybrid lesson retrieval), gptme-retrieval, and gptme-tooloutput-trimmer for trimming tool output instead of static context.

Install

There is no package entry point; load it as a folder plugin from a gptme-contrib checkout:

# gptme.toml
[plugins]
paths = ["path/to/gptme-contrib/plugins/gptme-attention-tracker"]
enabled = ["gptme_attention_tracker"]   # only needed if you use an allowlist

This registers two tools, attention_router and attention_history, whose functions are callable from gptme's Python (ipython) tool. Inside the gptme-contrib uv workspace the package is also importable as gptme_attention_tracker.

Quickstart

from gptme_attention_tracker.tools.attention_router import (
    register_file, process_turn, get_context_recommendation,
)
from gptme_attention_tracker.tools.attention_history import (
    record_turn, query_coactivation,
)

# Track a file; keyword hits push it to HOT. Pinned files never drop below WARM.
register_file("lessons/workflow/git-workflow.md",
              keywords=["git", "commit", "branch"], pinned=True)

# Updates are batched by default (flushed after 10 turns or on cache
# invalidation); apply_now=True applies them immediately.
process_turn("How do I commit changes with git?", apply_now=True)

rec = get_context_recommendation(max_hot=10, max_warm=20)
print("HOT:", rec["include_full"])     # include full content
print("WARM:", rec["include_header"])  # include header only

record_turn(turn_number=1,
            hot_files=rec["include_full"],
            warm_files=rec["include_header"],
            activated_keywords=["git", "commit"])

for p in query_coactivation()[:5]:
    print(f"{p['file1']} <-> {p['file2']}: {p['count']}")

How scoring works

Tier Score Recommendation
HOT ≥ 0.8 include full content
WARM 0.25 – 0.8 include header (first 30 lines, see extract_header)
COLD < 0.25 exclude

API

attention_router: register_file, unregister_file, process_turn, flush_pending_updates, get_tiers, get_score, set_score, get_context_recommendation, extract_header, get_status, reset_state.

attention_history: record_turn, start_new_session, query_session, query_file, query_coactivation, query_keyword_effectiveness, get_summary, find_underutilized, clear_history.

State files

Both paths are relative to the current working directory: