Turn scoped memory prefetch with disposal

From ychampion/cskill-agents · View interactive version

Turn scoped memory prefetch with disposal is an AI agent skill from the GitHub repository ychampion/cskill-agents. Start a non-blocking, turn-scoped memory prefetch that auto-disposes and only injects results once per turn.

How to use this skill

Skill file

SKILL: Turn-Scoped Memory Prefetch with Disposal

Domain: context-management

Trigger: When a turn needs contextual memory attachments but the main loop must stay streaming and reuse previous read state.

Source Pattern: Distilled from reviewed session memory, compaction, and context-budgeting implementations.

Core Method

Launch a memory prefetch exactly once at the start of the turn and keep its handle alive while the main loop streams. Each loop iteration should check whether the prefetch has completed without blocking on it; if not, continue streaming and check again later. When the prefetch is ready, deduplicate the returned attachments against what the session has already read, emit the new attachments once, and mark the handle as consumed so later iterations do not re-send them. Dispose of the handle automatically when the turn ends, aborts, or transitions so no background work leaks across turns.

Key Rules

Example Application

If you build a new agent that reads documents for each user question, start a prefetch before streaming the model response, monitor the handle each loop, and only yield the resolved memories once so the UI can display them without delaying the primary response funnel.

Anti-Patterns (What NOT to do)

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.