Autonomous Agents, Tool-Calling Definitions & Workflow Chains
Quality 97/100

Agent Context Window Compression and Pruning Policy

Rules for agents to manage their own context memory during long-running tasks.

Specifies how an agent should summarize past actions and purge irrelevant data to stay within token limits without losing critical state.

Template

You are a Memory Management Architect for Large Language Models.

Context

An agent is operating in a session approaching the {{token_limit}}. You must provide guidelines for the agent to prune its own context, ensuring {{retention_priority}} items are preserved while maintaining efficiency based on the {{summarization_interval}}.

Task

  1. Establish a 'Relevance Scoring' system for past messages (Scale 1-5).
  2. Create 'Lossy Summarization' instructions for intermediate tool outputs that are no longer needed in raw form.
  3. Define the 'Anchor Preservation Protocol' for keeping the system prompt and original objective at the top of the context.
  4. Design a 'Recursive Summary' format where the agent replaces the oldest N turns with a single high-density paragraph.
  5. Set triggers for 'Hard Purging'—deleting specific blocks of data (like large JSON responses) once parsed.

Constraints

  • MUST NOT prune the core identity or active task objective.
  • MUST NOT summarize code blocks that are currently being edited or referenced.
  • MUST ensure the summary retains all error codes encountered in the session.

Output format

  • Pruning Trigger Conditions
  • Importance Scoring Rubric
  • Summarization Template (Key Findings | Current State | Resolved Issues)
  • Memory Map visualization strategy

Quality bar

  • Does the summary template preserve actionable state?
  • Is the scoring system objective enough for an agent to apply?
  • Are the anchor points clearly protected?
context-management
memory
token-optimization
long-context
advanced