LLM_log #032: Beyond the Context Window — Authored Skills and External Memory for AI Agents

LLM_log #032: Beyond the Context Window — Authored Skills and External Memory for AI Agents

Beyond the Context Window — Authored Skills and External Memory for AI Agents

Highlights: Daniel Fried’s lecture in CMU 11-768 AI Agents (Fall 2026) examines how autonomous agents extract reusable operational skills and manage structured memory across multi-step tasks. We walk through the AgentSkills specification standard, progressive disclosure mechanisms that protect context windows, and benchmarked gains on SkillsBench. Finally, we explore tiered storage in MemGPT, memory reconciliation in Mem0, and trajectory reflection frameworks like Reflexion and ExpeL.

  • Trajectory invariance: Agents extract shared, repeated action sequences across distinct tasks into modular subroutines, avoiding costly trial-and-error exploration.
  • Progressive disclosure: The AgentSkills standard indexes minimal YAML frontmatter in system prompts, loading full markdown instructions, scripts, and references only on demand.
  • SkillsBench evaluation: Equipping agents with one to three concise, curated skills increases pass rates from 33.9% to 50.5%, whereas providing four or more skills degrades performance.
  • Memory reconciliation: Mem0 identifies factual contradictions against retrieved candidate records and executes discrete ADD, UPDATE, DELETE, or NOOP database operations to maintain state.
  • Trajectory conditioning: Reflexion and ExpeL convert task feedback into natural-language critiques and retrieve historical execution traces as in-context demonstrations without modifying model weights.

Tutorial Overview:

  1. Trajectory Invariance and Agent Updating Trade-offs
  2. Agent Experience and Operational Skills
  3. Skill Package Directory Layout and Anatomy
  4. Standardized Package Conventions Across Agent Frameworks
  5. Progressive Disclosure: Indexing Metadata in System Prompts
  6. Progressive Disclosure: Tool-Driven Skill Loading
  7. Benchmarking Skill Efficacy on SkillsBench
  8. Auditing and Maintaining Production Skills
  9. Tiered Memory Architectures and Tool-Driven Storage
  10. Resolving Memory Conflicts in Mem0
  11. Trajectory Reflection and Self-Correction with Reflexion
  12. Cross-Trajectory Conditioning in ExpeL
  13. Inducing Procedural Skills
  14. Summary

1. Trajectory Invariance and Agent Updating Trade-offs

In short
– Agents extract shared procedural workflows across distinct tasks into modular, reusable skills.
– Raw execution traces divide into episodic memory, declarative facts, and procedural skills.
– External artifacts provide portable, inspectable updates superior to context limits or opaque weights.

1.1 Shared Task Structures Across Search Procedures

Fried introduces skill induction (automated extraction of reusable subroutines from prior experience) to retain operational knowledge across tasks.

  • Skills as instructions: human experts author operational rules and established best practices with clear provenance.
  • Skills as learning: agents discover reusable routines autonomously by evaluating their own execution traces and outcomes.
  • Refinement cycle: agents mine trajectories (chronological sequences of observations and actions) for review, refining rules empirically.
  • Three design questions: systems must resolve procedure representation format, induction noise filtering, and lifecycle update strategies.
  • Programmatic tools: executable code skills permit automated test verification and hierarchical composition into workflows.
  • Search invariance: identical navigation, input, and search steps precede headphone selection or keyboard price checks.

External subroutines prevent agents from repeating costly trial-and-error exploration across independent tasks. Modular code tools execute efficiently in a single step.

1.2 Invariance in Workflows and Trajectories

Fried decomposes interactive web workflows into shared search backbones and divergent terminal finishes.

Execution follows a two-stage sequence:
1. Shared search procedure: When instructed to add Sony headphones to a wish list, the agent navigates to the storefront, locates the search input, enters the product query, and clicks search before adding the selected item to the wish list.
2. Divergent task finish: The trajectory diverges to add the item or extract wireless keyboard price ranges.

  • Episodic memory (historical traces of observations and actions): records complete execution details but consumes substantial token budgets with redundant noise.
  • Declarative facts (persistent environmental truths): compact statements capturing enduring properties, such as retailers displaying prices only on dedicated pages.
  • Procedural skills (reusable action sequences abstracting entities): generalized routines capturing how to act across repeated tasks without entity instances.
  • Context minimization: condensing episodes into modular skills prevents agents from re-deriving basic interaction sequences every run.

Decomposition of two shopping tasks sharing an identical search procedure before diverging at task completion.

Fig 1. Shared search procedures remain invariant across shopping tasks before diverging at task completion.

Abstracting invariant routines isolates reusable actions from redundant task-specific noise. This preserves generalizable behavior while minimizing working context overhead.

1.3 Updating Trade-offs Across Memory Locations

Updating agent behavior balances context limits, engineering overhead, and cross-model checkpoint portability.

Storage Location Primary Mechanism Key Advantages Major Disadvantages
Context window Active prompt ReAct history High fidelity to recent task events Token exhaustion and high noise
External artifacts File systems or databases Transparent, editable, and model-portable Requires active induction and maintenance
Model weights Fine-tuning or reinforcement learning Fast inference, broad behavioral shifts Opaque, slow training, zero portability
  • 1,000,000 token limit: context windows inevitably exhaust capacity during long-running, multi-task workflows.
  • Zero-retraining transfer: text or code skills authored on one model immediately transfer across model families.
  • Human-system boundary: external files allow engineers to directly inspect, audit, and patch textual rules.
  • Over-specification defect: authoring models frequently over-infer task constraints, writing rigid steps downstream agents follow literally.
  • Downstream peer prompting: simulating peer theory of mind and interpretative limitations produces concise, reliable documentation.

Trade-offs among updating agent behavior via the context window, external artifacts, and model weights.

Fig 2. External artifacts provide portable and editable storage that scales beyond context window limits.

Prompting models to simulate peer interpretative limits eliminates unintended operational side effects. External rules remain transparent, unlike opaque parametric weights in black-box models.


2. Agent Experience and Operational Skills

In short
– Agent experience divides into episodic traces, declarative facts, and procedural skills.
– Codified skills eliminate repetitive manual prompting for recurring workflows like code reviews.
– The AgentSkills standard uses progressive disclosure to protect active context windows.

2.1 Distinguishing Memories and Skills

Fried organizes agent experience outside active prompts into distinct abstraction layers to prevent repeated exploration errors.

Experience Type Target Content System Scope
Episodic memory Full past observations and actions Interaction logs such as past purchases
Declarative facts Explicit user and environment statements Static rules like prices appearing on product pages
Procedural skills Reusable task action sequences Abstract subroutines like filling search forms
  • Running wish list example: navigating storefronts, entering Sony headphones, and clicking submit demonstrates procedural routines.
  • Context compaction: prompts models in ChatGPT and Anthropic to distill conversational histories into stored profile facts.
  • Memory versus skill: memories record internal past interactions; skills provide external reusable guidance like deployment checklists.
  • Skills as instructions: human-authored procedures enforce known policies with high quality and clear operational provenance.
  • Skills as learning: agents discover procedures via skill induction (extracting reusable subroutines from prior execution experience).

Three types of agent experience: episodes, facts, and skills.

Fig 3. Agent experience separates into episodic interaction traces, declarative facts, and reusable procedural skills.

External storage prevents prompt saturation across sessions. Agents generalize knowledge without repeating past exploratory failures.

2.2 Codifying Guidelines as Skills

Developers repeatedly enter identical multi-step review instructions during coding interactions in OpenHands.

  • 88-character line limit: Black formatting standard required across all modified Python files.
  • Ruff linting: configures customized repository rules to maintain consistent code hygiene.
  • Public API typing: mandates type hint annotations across all exported functions.
  • Google-style docstrings: requires standard documentation format across all modified repository modules.
  • Pytest verification: executes automated unit test suites for every newly introduced function.
  • Workflow triggers: packages recurring tasks like code review, test runs, and dependency upgrades into skills.

A human-authored code review skill replacing repetitive prompt instructions.

Fig 4. Human-authored skills eliminate repetitive prompting by bundling multi-step quality checks into reusable routines.

Retyping instructions consumes developer effort and context tokens. Encapsulating guidelines ensures reliable compliance across repeated tasks.

2.3 The AgentSkills Specification Standard

The AgentSkills specification organizes recurring procedures into modular, self-contained directory structures for execution.

  • SKILL.md: pairs YAML frontmatter (a structured metadata header) with complete task execution instructions.
  • scripts/ directory: contains optional executable tools like standalone linting scripts and test harnesses.
  • references/ directory: supplies supplementary documentation including organization style manuals and API reference guides.
  • assets/ directory: provides static resources including code generation scaffolding and Jinja templates.
  • Progressive disclosure: exposes lightweight metadata upfront and loads detailed instructions on demand (a tiered loading strategy).

Preloading entire skill manuals saturates limited context windows. Selective loading keeps prompts compact while retaining access to deep instructions.


3. Skill Package Directory Layout and Anatomy

In short
– Modular skill directories turn ad-hoc prompts into versioned, testable software engineering artifacts.
– The core SKILL.md file combines machine routing metadata with natural-language execution rules.
– Progressive disclosure loads lightweight metadata first, retrieving heavy code and documentation on demand.

3.1 Directory Structure of a Skill Package

The AgentSkills specification standardizes reusable capabilities into versioned directory trees across four essential components.

  • Root definition: SKILL.md holds operational instructions, configuration metadata, and activation triggers.
  • Executable code: scripts/ stores deterministic automation scripts such as linters and test runners.
  • Supplementary docs: references/ houses reference material, API schemas, and specialized style guides.
  • Static resources: assets/ stores boilerplate prompt fragments, data files, and Jinja templates.

Fried notes that versioned directories transform brittle prompt strings into maintainable engineering artifacts. Isolated directories allow developers to unit-test tools before deploying them.

3.2 Defining Interfaces with SKILL.md

The SKILL.md document serves as the operational interface, pairing YAML frontmatter (a structured header block at the top of a skill file that specifies metadata such as the skill’s name, description, and triggers) with procedural execution rules.

  • Standardized reviews: OpenHands uses a python-review package instead of typing repetitive review prompts into pull requests (PRs).
  • Trigger routing: declarations like “code review” alert the agent to invoke the specific skill.
  • Strict constraints: 88-character line limits and mandatory full test suites enforce code quality standards.
  • Inspectable workflows: Markdown allows engineers to audit operational rules directly inside repository pull requests.
  • Deterministic actions: models translate human-readable execution guidelines directly into precise browser or environment tool calls.

SKILL.md sits at the heart of every skill package, combining machine-readable metadata headers with human-readable execution rules.

Fig 5. SKILL.md pairs machine-readable routing metadata with human-readable operational constraints.

Authors write skills in Markdown so both humans and language models easily parse them. This dual readability ensures agents follow exact procedural instructions without sacrificing human oversight.

3.3 Bundling Programmatic Tools and Scripts

Skill packages bundle deterministic executables into dedicated folders instead of forcing language models to generate procedural shell commands from scratch.

  • Isolated execution: HermesAgent runs python scripts/run_checks.py src/ to automate code reviews deterministically.
  • Clean context: script standard output returns as an observation, keeping raw source code out of context.
  • Demand-driven docs: agents read specialized reference files like references/docstring-style.md only when syntax questions arise.
  • Modular testing: developers execute standalone unit tests against programs inside scripts/ before deployment.
  • Static assets: Jinja templates and boilerplate configurations load conditionally during generation tasks.

Segregating code from instructions prevents prompt bloat while enforcing reliable task execution across models. Keeping raw script implementations outside working context minimizes token consumption.

3.4 Progressive Disclosure and Resource Segregation

Loading entire skill catalogs exhausts working context, so the specification implements progressive disclosure (a tiered loading strategy that exposes only lightweight metadata upfront and retrieves detailed instructions and code on demand).

  1. Level 1 (Index): 3,000 tokens of YAML metadata remain in the HermesAgent system prompt index.
  2. Level 2 (Body): SKILL.md loads via skill_view only when task triggers match the request.
  3. Level 3 (Resources): auxiliary scripts, references, and static assets load through explicit on-demand tool calls.

Tiered loading mirrors operating system memory hierarchies by keeping unneeded instructions on the file system. Isolating detailed instructions prevents model distraction, tool misuse, and drift from user specifications.


4. Standardized Package Conventions Across Agent Frameworks

In short
– AgentSkills standardizes modular capability directories anchored by a required root SKILL.md file.
– Progressive disclosure loads metadata first, fetching detailed instructions and scripts on demand.
– HermesAgent and OpenHands automate skill indexing, tool invocation, and lifecycle authoring.

4.1 The AgentSkills directory layout

Agent capabilities organize into portable, version-controlled folders that standardize multi-step operational workflows.

python-review/
├── SKILL.md          # Required: instructions + metadata
├── scripts/          # Optional: executable code
├── references/       # Optional: documentation
└── assets/           # Optional: templates, resources
  • Root file: SKILL.md contains core operational instructions, guidelines, and schemas.
  • YAML frontmatter (a structured header block at the top of a skill file that specifies metadata such as the skill’s name, description, and triggers.): headers record the package name, description, and trigger keywords.
  • Executable code: the scripts/ folder stores standalone helper tools and linters.
  • Reference documents: the references/ folder stores extended documentation, schemas, and styling manuals.
  • Asset templates: the assets/ folder supplies reusable files, static examples, and prompt scaffolds.
---
name: python-review
description: This skill should be used when the user asks to
  "review Python code", "check Python style", "lint Python",
  or mentions code quality.
triggers:
  - python review
  - code review
  - lint python
---
# Python Code Review
Review Python code using company standards...

Dedicated directory packaging keeps operational procedures separate from raw agent runtime logic. Teams share versioned capabilities across different agent frameworks without rewriting instructions.

4.2 Packaging manuals via progressive disclosure

Progressive disclosure (a tiered loading strategy that exposes only lightweight metadata upfront and retrieves detailed instructions and code on demand) shields working context from excessive token saturation.

  1. Level 1 (Metadata): inject only frontmatter fields into the persistent system prompt.
  2. Level 2 (Instructions): load markdown instructions via dedicated tool calls upon matching triggers.
  3. Level 3 (Resources): execute bundled scripts or read reference files only when needed.
  • Embedding retrieval: vector queries identify relevant skill descriptors using incoming task text.
  • Domain routing: environment signals load specialized bundles, like loading shopping skills when adding Sony headphones.

Unrestricted reference injection overflows prompt context limits and degrades model reasoning. Progressive disclosure preserves context space by delaying access until task conditions require it.

4.3 Modular multi-file asset workflows

HermesAgent coordinates multi-file packages across sequential execution turns without flooding context windows with script source code.

  1. Turn 1 (Index Ingestion): prompt loads index summaries consuming approximately 3,000 tokens.
  2. Turn 2 (Skill Ingestion): agent calls skill_view('python-review') to load core markdown instructions.
  3. Turn 3 (Script Execution): agent runs TERMINAL python scripts/run_checks.py src/ for output.
  4. Turn 4 (Reference Retrieval): agent invokes skill_view('python-review', 'references/docstring-style.md') for specific documentation.
  • 3,000 tokens: catalog summaries occupy minimal system prompt space during initial ingestion.
  • Terminal isolation: tool scripts run externally and return output without dumping source code.
  • Targeted lookup: supplementary reference manuals enter context only when exact style rules apply.
  • Minimal distraction: compact skill packages protect the model from displacement of base reasoning.

Multi-Turn Progressive Skill Execution

Fig 6. Staged tool calls load instructions, execute linters, and fetch references without context bloat.

Irrelevant or over-provisioned skills inflate context and distract agents from core task objectives. Tight packaging ensures models access only procedural knowledge critical to immediate execution.

4.4 Implementations in Hermes and OpenHands

Open-source agent frameworks provide built-in tooling to index, inspect, and update modular skill packages.

## Skills
Before replying, scan the skills below. If a skill matches or is even
partially relevant to your task, you MUST load it with skill_view(name)
and follow its instructions. ...
<available_skills>
  code-quality:
    - python-review: This skill should be used when the user asks to
      "review Python code", "check Python style", "lint Python", or
      mentions code quality.
  workflow:
    - submit-task: When the task is complete, take the required steps to
      submit the solution. DO NOT submit without invoking this skill.
    - release-notes: ...
</available_skills>
Only proceed without loading a skill if genuinely none are relevant.
Feature HermesAgent OpenHands
Catalog Format XML tagged hierarchy System prompt listings
Inspection Tool skill_view Custom retrieval actions
Lifecycle Manager skill_manage tool /skill-creator command
Authoring Timing Pre-task and dynamic Immediate post-task workflow
  • Catalog presentation: XML structures categorize available packages directly inside runtime instructions.
  • Model triggering: agents parse metadata descriptions to deduce when tool views are required.
  • Precision metadata: explicit trigger text prevents false positive skill invocations during execution.
  • Post-task creation: authoring skills immediately after successful task runs captures real edge cases.

Accurate metadata ensures that models infer skill relevance reliably without human intervention. Post-run authoring extracts authentic operational knowledge before task details leave agent memory.


5. Progressive Disclosure: Indexing Metadata in System Prompts

In short
– Progressive disclosure indexes skill metadata upfront to prevent context window overflow.
– Agents fetch detailed procedural instructions on demand using tools like skill_view.

5.1 Low-Footprint Frontmatter Indexing

System prompts use progressive disclosure (loading metadata upfront and details on demand) to save context.
– YAML frontmatter (structured header specifying metadata): supplies only skill name and description from SKILL.md.
– ~3,000 tokens: consumed by HermesAgent to index its full metadata catalog.
– Tool discovery: informs the agent of available tools like skill_view.

Pre-loading compact headers prevents context exhaustion during multi-step runs.

5.2 Routing Queries via Catalogs

Agents route tasks by matching triggers against metadata before loading procedural guidance.
1. Match triggers: compare incoming requests against frontmatter descriptions.
2. Retrieve instructions: invoke skill_view to load procedural details on demand.
3. Execute tools: run auxiliary actions without early context exhaustion.

A progressive tool loop routes specialized execution to keep detailed instructions out of the context window until needed.

Fig 7. On-demand tool retrieval keeps detailed procedural instructions out of context until needed.

Deferred loading ensures specialized instructions enter context only when actively needed.


6. Progressive Disclosure: Tool-Driven Skill Loading

In short
– Progressive disclosure avoids context bloat by loading instructions only when tool calls trigger them.
– Tiered directories keep reference manuals and executable scripts outside active prompt tokens.

6.1 Tiered skill directory structure

Progressive disclosure [a tiered loading strategy that exposes only lightweight metadata upfront and retrieves detailed instructions and code on demand] organizes skill directories.
– SKILL.md: required markdown file defining Level 2 instructions and Level 1 metadata.
– Optional subfolders: directory components including scripts/, references/, and assets/.
– Level 1 metadata: permanent system prompt YAML headers with skill names and descriptions.
– Level 2 instructions: detailed Markdown instruction bodies loaded strictly via tool calls.
– Level 3 resources: bundled external scripts and reference documents loaded on demand.

Full instructions rapidly saturate limited context windows. Tiered directories preserve token capacity for active reasoning.

6.2 Just-in-time context injection protocol

HermesAgent executes a turn-by-turn context injection protocol using sequential tool invocations.
1. 3,000 tokens: Turn 1 injects the system prompt index containing skill names and descriptions.
2. Turn 2 instructions: skill_view('python-review') loads review steps from SKILL.md.
3. Turn 3 execution: python scripts/run_checks.py src/ returns only Black and Ruff findings.
4. Turn 4 documentation: skill_view('python-review', 'references/docstring-style.md') retrieves supplementary reference guides when needed.

Turn-by-turn context expansion using tool calls to inspect SKILL.md, run scripts, and load reference documentation.

Fig 8. Tool calls dynamically expand context with instructions, script outputs, and reference docs.

Running scripts externally prevents raw code from filling memory. The agent consumes only actionable terminal outputs.


7. Benchmarking Skill Efficacy on SkillsBench

In short
– Curated skills boost average agent pass rates across diverse tasks.
– Adding too many skills or verbose instructions degrades agent problem-solving.
– High-performing skills come from successful traces rather than a priori synthesis.

7.1 SkillsBench pass rates and gains

SkillsBench (a benchmark evaluating how curated procedural skills improve agent success rates) tests 87 tasks across 8 domains.

  • 87 tasks, 8 domains: each paired with skills that human annotators picked from a pool of two million web-sourced skills.
  • Pre-filter: a small model subset first checked that the curated skills actually help.
  • 33.9% -> 50.5%: pass rate increase across 18 model-harness configurations using human verification.
  • 1–3 skills: delivered substantially larger gains than equipping agents with four or more skills.
  • Shorter documentation: concise SKILL.md instruction bodies correlated with higher performance gains.
  • 13 of 87 tasks: suffered degraded performance when ill-suited skills displaced superior default reasoning.

Supplying curated skills increases average pass rates, though rigid guidelines can displace default reasoning on select tasks.

Fig 9. Curated skills lift average pass rates but sometimes displace effective default reasoning.

Pass rate gains and failure cases across tasks with varying skill counts and documentation lengths.

Fig 10. Compact instructions and three or fewer skills produce the largest performance improvements.

Excessive instructions clutter context windows and divert agents from straightforward execution paths.

7.2 Skill sourcing and lifecycle maintenance

Production agents source capabilities through three pathways before refining them against execution failures.

Pathway Origin Storage or Tool
Bundled Harness framework Default system tools
Installed Human authors .agents/skills/ or shared repositories
Agent-created Model synthesis HermesAgent skill_manage or OpenHands /skill-creator
  1. Execute task: run the agent to complete a task successfully.
  2. Extract subroutines: capture procedural steps directly from the successful execution trace.
  3. Verify and patch: test against verification runs and patch recurring failure modes.
  • Adopted suggestions: a model judge evaluated human developer acceptance on merged PRs (pull requests).
  • 15% of failures: stemmed from agents ignoring repository conventions during code review.
  • 10% of failures: stemmed from agents approving pull requests containing critical flaws.
  • Automated patches: updated the SKILL.md file directly to fix recurring review errors.

The three primary pathways for sourcing and managing agent skill packages.

Fig 11. Skill packages originate from harness defaults, human repositories, or model synthesis tools.

Drafting skills a priori fails because models hallucinate procedural steps without grounded execution data.


8. Auditing and Maintaining Production Skills

In short
– Track human acceptance rates of agent suggestions to pinpoint recurring skill failures.
– Reasoning models inspect logs and update SKILL.md to prevent future execution errors.

8.1 Failure Attribution in Code Reviews

OpenHands audits its python-review skill across pull request trajectories (chronological sequences of actions and observations).

  1. Execute review: Run the review skill on pull requests and log run notes.
  2. Count acceptance: Model judges score how many suggestions humans retained in merged code.
  3. Hundreds of runs: Aggregate outcomes across historical executions to identify recurring failures.

Tracking human acceptance rates grounds evaluation in real developer workflows. This isolates genuine execution flaws.

8.2 Iterative Skill Patching Workflow

Diagnostic reasoning models analyze empirical failure logs to fix operational guidelines systematically.

  • Log diagnosis: Diagnostic models evaluate run traces to isolate systematic execution errors.
  • 2 failure categories: Targeted rule revisions address the two dominant failure types directly.
  • Reinforce SKILL.md: Automated patches update skill guidelines to prevent future oversights.

Model-in-the-Loop Skill Patching Pipeline

Fig 12. Diagnostic models analyze failure logs to patch operational rules in SKILL.md.

Automated patching eliminates repeated manual intervention. Closing the feedback loop keeps production skills reliable.


9. Tiered Memory Architectures and Tool-Driven Storage

In short
– External storage tiers prevent long task trajectories from overflowing finite context windows.
– MemGPT uses OS-like paging to swap records between working context and databases.
– Explicit tool calls allow agents to read and write memory on demand.

9.1 Managing Context via External Stores

Agents use a two-tier storage hierarchy to run long workflows without overflowing the context window.

  • Two-tier hierarchy: fast working context pairs with scalable secondary storage for persistent data.
  • Trajectory scaling: external stores preserve state when a trajectory (full chronological action sequence) exceeds token limits.

Operating Systems Memory Hierarchy Analogy

Fig 13. OS memory hierarchies map directly to fast context and scalable external agent storage.

Finite context windows cannot store entire task histories without degrading reasoning quality.

9.2 MemGPT OS-Inspired Memory Tiers

MemGPT partitions memory into structured tiers to prevent chat logs from displacing durable facts.

  • MemGPT: an OS-inspired agent architecture paging records between working context and storage via tools.
  • Three tiers: memory splits across archival storage, recall storage, and FIFO queues.
  • Dynamic paging: explicit function calls page conversational records and facts into working context.

MemGPT Tiered Memory Architecture

Fig 14. Structured tiers prevent volatile dialogue from displacing durable long-term factual knowledge.

Separating chat histories from permanent facts protects core knowledge during extended runs.

9.3 Tool-Driven Memory Operations

Models govern their own memory lifecycle by executing explicit read and write tool calls.

  • Function execution: model generates explicit tool calls to query archival or recall records.
  • Observation injection: search outputs return as tool observations directly into the working context.
  • Example query: mentioning Six Flags triggers a tool call searching records for prior visits.

Explicit tools allow the agent to inspect, retrieve, and update storage only when needed.


10. Resolving Memory Conflicts in Mem0

In short
– Mem0 retrieves top-K candidate records to detect contradictions against incoming dialogue.
– Four discrete operations (ADD, UPDATE, DELETE, NOOP) mutate stored text facts cleanly.
– Direct text editing replaces complex neural unlearning with interpretable, automated updates.

10.1 Detecting Contradictions via Candidate Retrieval

Mem0 (a memory framework resolving contradictions via ADD, UPDATE, DELETE, or NOOP database operations) retrieves prior facts alongside dialogue.

  1. Candidate extraction: an LLM extracts discrete candidate facts warranting persistent storage from incoming dialogue.
  2. Top-K retrieval: an embedding retriever fetches top-K semantically similar records from external storage.
  3. Contextual comparison: the system compares candidate facts against retrieved records to identify contradictions.

Appending records indefinitely causes stale data to linger when user attributes change. Side-by-side evaluation reveals direct contradictions.

10.2 Four Fact Mutation Operations

A language model reconciles candidate statements with historical data using four discrete database operations.

  • ADD: inserts completely new information when incoming facts lack prior database records.
  • UPDATE: overwrites outdated records with fresh details when historical attributes change.
  • DELETE: removes invalidated records entirely when negated by new dialogue statements.
  • NOOP: ignores redundant input when incoming facts match existing stored records.

Mem0 Fact Mutation Operations

Fig 15. Four discrete mutation operations reconcile incoming candidate facts against stored database records.

Classifying memory mutations prevents contradictory entries from accumulating over multi-session interactions.

10.3 Handling Negations and Redundant Input

Explicit mutation rules keep external memory accurate and concise across extended user dialogues.

  • Negation pruning: deletes the employment fact entirely when a user is laid off from company X.
  • Redundancy filtering: executes a no-op when incoming dialogue merely reiterates known facts.
  • Automated maintenance: reflects the true world state continuously without requiring manual intervention.

Replacing fields during negations introduces false premises. Explicit deletion preserves truthful state representations.

10.4 Textual Versus Neural State Editing

Mem0 provides an interpretable text-based counterpart to neural state editing models like DeltaNet.

Memory System Storage Format Editing Mechanism Direct Interpretability
Mem0 External text facts Database mutation operations Fully readable
DeltaNet Key-value vectors Numerical state updates Latent vectors

Textual vs Neural Memory Editing

Fig 16. Direct text edits revise outdated knowledge without retraining or modifying neural weights.

Editing external text eliminates obsolete knowledge cleanly without requiring complex neural unlearning procedures.


11. Trajectory Reflection and Self-Correction with Reflexion

In short
– Natural language self-critiques iteratively correct task errors across repeated execution attempts.
– Stored execution trajectories provide few-shot demonstrations for structurally similar future tasks.

11.1 Converting feedback into verbal reflection

Reflexion (a framework converting task feedback into natural language self-critiques to guide retries; Shinn et al., NeurIPS 2023) corrects errors.

  1. Attempt: the agent executes an action sequence to complete the task.
  2. Evaluator: a model judge or environment predicts a reward from the outcome.
  3. Reflection: a language model generates natural language feedback diagnosing errors.
  4. Retry the same task: the agent reattempts the task conditioned on the reflection.
    – Scalar reward limitation: natural language critiques provide far more actionable guidance than scalar scores.
    – 1776 battle example: reflection corrected “Battle of White Plains” to “The New York and New Jersey campaign”.

Semantic critiques explain specific execution failures. Scalar rewards cannot explain how to fix errors.

11.2 Iterative self-correction across task attempts

Fried emphasizes that trial-and-error reflection loops extend beyond immediate retries of the exact same task.

  • Immediate retries: localized verbal feedback corrects immediate execution mistakes on the current prompt.
  • General heuristics: agents abstract task-specific reflections into broader procedural rules for future runs.
  • Pitfall prevention: stored critiques help agents avoid recurring traps on structurally similar future tasks.
  • Zero weight updates: agents improve failure handling over time without modifying underlying model weights.

Abstracting critiques prevents repeated failures across related workflows. Agents learn from past errors without retraining.

11.3 Conditioning on stored agent experiences

Systems store each trajectory (chronological sequence of observations, thoughts, and actions) to support cross-trajectory conditioning.

  • What is stored: complete success and failure trajectories, often annotated with reflective critiques.
  • Source pool: episodes gathered offline from demonstrations, logged during rollouts, or hand-written.
  • Retrieval mechanism: embedding models match incoming task prompts against past descriptions for few-shot context.
  • Execution RAG: frameworks perform retrieval-augmented generation directly over past execution histories.
  • Cross-trajectory conditioning: retrieving historical execution episodes as few-shot in-context demonstrations improves task success.
  • Demonstrated frameworks: ExpeL (AAAI 2024), Synapse (ICLR 2024), ICAL (NeurIPS 2024), and Agent S (ICLR 2025).

Similar-trajectory conditioning workflow retrieving past experiences to guide new tasks

Fig 17. Retrieved past execution trajectories provide few-shot demonstrations that guide agents through new tasks.

Retrieving past execution traces provides concrete demonstrations. This prevents repeating previously solved exploration steps.


12. Cross-Trajectory Conditioning in ExpeL

In short
– ExpeL stores complete interaction traces and natural feedback in an experience pool.
– Agents retrieve past runs as in-context demonstrations without updating weights.

12.1 Retrieving Trajectories from Memory

Agents store full interaction sequences rather than isolated facts to preserve procedural context.

  • Full interactions: ExpeL (Zhao et al., AAAI 2024) logs observations, actions, tool calls, and feedback.
  • Offline collection: agents gather trajectories (complete chronological sequences of actions and observations) during training.
  • Online accumulation: the experience pool stores new traces as the agent completes tasks.
  • Prepared demonstrations: designers seed the system with hand-written expert runs.

Fried emphasizes that retaining complete traces preserves operational context. This helps the agent avoid previous failures.

12.2 Few-Shot Conditioning for New Tasks

Agents retrieve prior execution traces dynamically to solve new task instances.

  • Retrieval workflow: Synapse and ICAL fetch relevant traces as few-shot demonstrations.
  • Cross-trajectory conditioning: retrieving past execution episodes guides the agent through new tasks.
  • No fine-tuning: conditioning transfers execution strategies without updating model weights.

Agents condition directly on retrieved past episodes in context to transfer execution strategies without weight updates.

Fig 18. Retrieved past episodes guide new tasks directly in context without updating weights.

In-context demonstrations transfer working tactics immediately. This avoids the high computational cost of fine-tuning.


13. Inducing Procedural Skills

In short
– Modular procedural skills convert recurring action chunks into parameterized, reusable subroutines.
– Progressive disclosure and controlled skill counts prevent prompt clutter and behavioral degradation.

13.1 Modular Task Procedures

Agents convert recurring low-level action sequences into reusable subroutines across varied user requests.

  • Skill definition: Fried frames skills as modular chunks reused across different user requests.
  • Procedural skills (reusable action sequences): parameterized procedures preventing fragile action synthesis from scratch.
  • Product search example: typing queries and clicking submit before adding Sony headphones to lists.
# To find {query}, I will type it into the store's search box and submit.
fill('element145', {query})
click('element147')

Skills as reusable chunks of a task

Fig 19. Skills package recurring low-level actions into modular, reusable task subroutines.

Packaging parameterized actions prevents models from repeatedly synthesizing fragile execution steps.

13.2 Managing Skill Retrieval and Quality

Systems regulate skill volume and structure to avoid saturating context windows or displacing baseline behaviors.

  • Progressive disclosure (tiered loading strategy): SKILL.md files provide metadata and triggers without saturating prompts.
  • 1 to 3 skills: optimal allocation on SkillsBench (benchmark evaluating curated skills).
  • >= 4 skills: excessive allocation that degrades performance by displacing default behaviors.
  • 15% of failures: OpenHands pull request review errors from ignoring repository conventions.
  • 10% of failures: OpenHands review errors caused by approving critical flaws.

Targeted patches mandate convention checks and explicit change requests to eliminate systematic errors.


14. Summary

In short
– External storage architectures maintain state when tasks exceed context windows.
– Dynamic memory operations and reflection loops enable continual task improvement.

14.1 Persistent memory and trajectory feedback

Autonomous agents use systems like MemGPT (paging context via tools) across 3 primary memory tiers:
– 1. Working context: active context window holding fixed instructions and scratchpad state.
– 2. Archival Storage: long-term database of facts read and written via function calls.
– 3. Recall Storage: searchable conversation history and message queue updated via queue manager.
– 4 Mem0 (conflict framework) operations: extracts incoming facts, executing ADD, UPDATE, DELETE, or NOOP database actions.
– 4 Reflexion (self-critique framework) stages: attempt initial task, evaluate reward, reflect on failures, and retry.
– ExpeL episodic demonstrations: retrieves offline successful and failed trajectories (chronological execution records) via text embeddings.

Evaluating execution traces and failure modes updates modular skill definitions across evolving environments. Tiered hierarchies and trajectory feedback translate past execution into structured, reusable skills.


Source

Lecture: Memory and Skills for Agents by Daniel Fried, Carnegie Mellon University.
Course: CMU 11-768 AI Agents (Fall 2026), Lecture 4, first half.
Video: YouTube · Slides: PDF · Course page: cmu-agents.com

Further reading referenced in the lecture:


dataHacker.rs — LLM_log #032: Beyond the Context Window — Authored Skills and External Memory for AI Agents. By Vladimir Matic.