Skip to content

feat(loop-context): stateful memory manager with pruner + circuit breaker#4

Merged
KhaiTrang1995 merged 1 commit into
mainfrom
feat/stateful-memory-manager
Jul 2, 2026
Merged

feat(loop-context): stateful memory manager with pruner + circuit breaker#4
KhaiTrang1995 merged 1 commit into
mainfrom
feat/stateful-memory-manager

Conversation

@KhaiTrang1995

@KhaiTrang1995 KhaiTrang1995 commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Adds tools/loop-context — a deterministic, dependency-free manager that sits between an agent loop and its durable memory to prevent the two classic long-run failures: context overflow/rot and stagnant/no-progress loops.

Before each iteration it can:

  • summarize what has been tried (factual rollup, no LLM needed),
  • prune verbose stack traces, collapse repeated errors, and keep only a recent window of attempts,
  • inject a compact context block into the next prompt.

The circuit breaker escalates to a human on stagnation (same error N× in a row), no-progress (N consecutive failures), token budget, or iteration cap — instead of burning tokens in a hopeless loop. Errors are normalized to a stable signature so "the same error" is recognized across volatile details (line numbers, ports, addresses, temp paths).

Ships a CLI (--check/--prune/--inject/--summary/--status, stdin or --ledger) with escalate=exit 2, a library API, 18 tests, and CI gate + build wiring.

Summary

Changes

  • New pattern or starter (followed templates/pattern-template.md + updated registry.yaml)
  • Doc / example improvement
  • Tool change (loop-audit)
  • Story (includes real failure or surprise + lesson)

Checklist (from CONTRIBUTING)

  • All required sections present for patterns
  • Links work from README, patterns/README, starters/README, docs/index
  • No secrets, tokens, internal company URLs
  • STATE.md* examples use .example suffix
  • Safety-related content references docs/safety.md
  • Ran node tools/loop-audit/dist/cli.js . (or on the starter) and addressed findings

Testing / Dogfood

  • loop-audit passes on affected starters or this repo
  • Manual review of generated state / skill output

Screenshots / Examples (if UI or command output)


This template enforces the high bar this reference is known for.

…aker

Adds tools/loop-context — a deterministic, dependency-free manager that sits
between an agent loop and its durable memory to prevent the two classic
long-run failures: context overflow/rot and stagnant/no-progress loops.

Before each iteration it can:
- summarize what has been tried (factual rollup, no LLM needed),
- prune verbose stack traces, collapse repeated errors, and keep only a
  recent window of attempts,
- inject a compact context block into the next prompt.

The circuit breaker escalates to a human on stagnation (same error N× in a
row), no-progress (N consecutive failures), token budget, or iteration cap —
instead of burning tokens in a hopeless loop. Errors are normalized to a
stable signature so "the same error" is recognized across volatile details
(line numbers, ports, addresses, temp paths).

Ships a CLI (--check/--prune/--inject/--summary/--status, stdin or --ledger)
with escalate=exit 2, a library API, 18 tests, and CI gate + build wiring.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@KhaiTrang1995 KhaiTrang1995 merged commit 76e73f0 into main Jul 2, 2026
2 checks passed
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

Loop Readiness Audit

Score: 100/100 (L3)

Strong loop readiness — good candidate for L3 with explicit gates.

Top suggestions

  • Create loop-constraints.md with denylist paths, push/merge rules, and human gates (see templates/loop-constraints.md)

Posted by audit.yml · loop-audit docs

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant