feat(context): pluggable fold policy (choose what to fold and how)

Open
#385 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
18/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
python
Domain
ai

Research direction

This is design work, not a starter task. Read the fold logic in ContextAssembler (AD-14 age-based folding, AD-15 head and tail elision) and the tombstone rendering it uses, plus how Harness and providers.yaml are wired. The first step is settling the open questions: which surface comes first, and whether the budget always wins. Done means a written design that keeps the default policy unchanged and passes the golden traces.

Written by the indexing model from the issue text.

Description

enhancement help wanted

Problem

Folding (AD-14, Rule 5) decides when and how much to fold: it is driven by age (K, auto 2 to 8, or a fixed --fold-after N) and by size (the --context-tokens budget, AD-15 head + tail elision). A user cannot decide what to fold or how:

  • which observations to keep live longer or fold sooner, by command (pytest output vs web fetch pages vs --help);
  • what a folded observation turns into (today always the one-line tombstone [obs_N folded: ... | use mem recall obs_N to expand]).

Today the only levers are the window size, the fold age and mem pin for facts. A skill or SDK user who knows their task (a research skill that reads many pages, a coding skill that lives on test output) cannot tune folding for it without patching ContextAssembler.

Proposal

A pluggable fold policy, opt-in, with the current behaviour (AD-14) as the default and unchanged:

  1. Declarative rules (skill frontmatter, providers.yaml, Harness(...)), e.g. per command prefix: keep_live (never fold the latest one), fold_after: N, fold_first (fold before others when over the target).
  2. SDK hook: Harness(fold_policy=...), a small protocol that ranks fold candidates and/or renders the tombstone text, registered like register_provider / register_normalizer.

Constraints (Philosophy Gate, Golden Rules):

  • Deterministic by default: no model call in the default path (a model-written summary, if ever added, is a separate opt-in that has to show a bench gain).
  • 0 static prompt tokens; the prefix and tools array never change (Rule 1). Tombstone text stays bounded, with a unit test (AD-18).
  • Nothing is lost: everything stays in SQLite and mem recall / mem search keep working (AD-9).
  • No new dependency (Rule 7). Golden traces unchanged for the default policy.

How it moves the north star

Not directly: the default stays as is, so qwen3.5:9b Polyglot-Python must be flat. It makes folding experiments (for example keeping the last test run live, or folding web fetch pages first) possible without forking the core, each measured on its own against the north star before it can become a default.

Open questions

  • Which surface first: declarative rules only, or the SDK hook too?
  • Should a policy be allowed to fold less than AD-14 when that would blow the window, or is the window budget always the last word? (Proposed: the budget always wins.)

Raised from a question at the Pylestras Fortaleza (PUG-CE) talk prep: "can I choose what to compact, like Claude Code's /compact <instructions>?"

north star: n/a (opt-in, default unchanged) -> must stay flat


Generated by Claude Code

Dominant language
Python
Stars
3
Forks
1
Avg merge
1h 10m
Merged PRs (30d)
175

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from igormcsouza/tether

All issues in igormcsouza/tether

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.