AI Agent Optimization: Using Claude to Systematically Improve Memory Extraction Quality

lerim · Tech · 2026 · source Agentic: yes · promotional bias: low · source-backed · extracted with prompt 0.5.2 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: Coding-agent memory extraction

Lerim needed to improve memory extraction quality without guessing which prompts, tools, schemas, or DSPy signatures mattered.

Constraints:

Architecture

Lerim used Claude Code as an optimizer agent around another memory-agent system. The AutoResearch-style setup gives Claude Code program.md directives, modifiable prompts/tool descriptions/DSPy signatures/Pydantic schemas/harness code, and an immutable evaluator over golden cases. Each experiment modifies one surface, runs Lerim’s full or component pipeline, scores extraction/search/dedup/maintain quality, and keeps or reverts the change. Later rounds recalibrated the judge toward precision and quality alignment and separated the reusable optimization method from the specific objective.

Diagram confidence: explicit (topology described by the source).

flowchart LR
  program-directives[Program directives] --> claude-code-optimizer[Claude Code optimizer]
  autoresearch-skill[AutoResearch skill] --> claude-code-optimizer
  claude-code-optimizer --> modifiable-optimization-surface[Modifiable optimization surface]
  modifiable-optimization-surface --> lerim-memory-pipeline[Lerim memory pipeline]
  lerim-memory-pipeline --> immutable-evaluator[Immutable evaluator]
  immutable-evaluator --> claude-code-optimizer
  immutable-evaluator --> lifecycle-validation[Lifecycle validation]
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Claude Code optimizer Opus 4.6 agent that reads Lerim code/prompts/tools, proposes edits, and keeps or reverts changes. Program directives, Modifiable optimization surface, Immutable evaluator, Lerim memory pipeline
Program directives program.md specifying objective, allowed files, metric, and constraints. Claude Code optimizer
Modifiable optimization surface Prompts, tool descriptions, DSPy signatures, Pydantic schema descriptions, harness code, and filters Claude may edit. Claude Code optimizer, Lerim memory pipeline
Immutable evaluator Composite golden-case scorer for extraction quality, search relevance, dedup accuracy, and maintain precision. Claude Code optimizer, Lerim memory pipeline
Lerim memory pipeline Memory extraction/dedup/maintain system running on MiniMax M2.5 that receives the optimized changes. Modifiable optimization surface, Immutable evaluator
Lifecycle validation Slower sequential sync/maintain evaluation that checks component improvements end-to-end. Immutable evaluator, Lerim memory pipeline
AutoResearch skill Reusable method wrapper that separates optimization procedure from objective. Claude Code optimizer, Program directives

Data flow

The author writes program.md constraints and objective, then lets Claude Code edit allowed Lerim surfaces. For each experiment, Claude changes a prompt, signature, schema, tool description, harness, or filter; the evaluator runs golden cases through the memory pipeline; composite metrics decide whether the change helped; Claude keeps successful changes and reverts failed ones. Component-level tests guide fast iteration, while lifecycle tests verify that improvements survive sequential sync and maintain cycles.

5 supporting quotes
“I adapted Karpathy’s AutoResearch pattern — but instead of an AI agent optimizing a training script, I had Claude Code optimizing Lerim’s agents (harness and the prompts and tools).”article, stated
“1. program.md— I wrote the directives: which files Claude Code can modify, what the eval metric is, what constraints to follow (“don’t overfit to the golden cases”)”article, stated
“3. Immutable evaluator— A composite score (extraction quality, search relevance, dedup accuracy, maintain precision) measured against 15 golden test cases. Claude Code cannot touch the evaluator.”article, stated
“The loop runs ~30 minutes per experiment: Claude Code modifies a prompt or signature, the evaluator runs Lerim’s full pipeline against golden cases, scores the output, and Claude Code decides whether the change improved things.”article, stated
“End-to-end (lifecycle) — Sequential syncs of 3 sessions with a maintain cycle afterward. Tests how memories accumulate, how dedup works across sessions, and whether maintenance decisions improve.”article, stated

Why this architecture

The setup deliberately separates optimizer, editable surfaces, and immutable evaluator so another agent can make aggressive changes without moving the goalposts. Component-level evals keep the loop fast, lifecycle evals prevent local wins from failing in realistic memory accumulation, and keep/revert discipline turns failed experiments into knowledge instead of silent regressions.

3 supporting quotes
“The evaluator combines LLM-based quality assessment (is each extracted memory atomic and actionable?) with deterministic metrics (does the extracted title match golden data? does dedup correctly identify duplicates?).”article, stated
“I measured improvements at two levels to make sure component-level gains hold up in practice:”article, stated
“The keep/revert discipline caught regressions that intuition would have missed (7 of 14 experiments were correctly discarded).”article, stated

Models used: Claude Code Opus 4.6 · MiniMax M2.5 · LLM judge

Scale

Alternatives considered (roads not taken)

Prompt-only optimization

Rejected because: Schema/DSPy changes, especially ChainOfThought and field descriptions, beat prompt engineering alone.

“Field descriptions in the Pydantic model (20 words controlling output format) had more impact than 50 lines of prompt engineering.”article, stated

Let the optimizer change the evaluator

Rejected because: The evaluator is immutable so Claude cannot improve scores by changing the target.

“3. Immutable evaluator— A composite score (extraction quality, search relevance, dedup accuracy, maintain precision) measured against 15 golden test cases. Claude Code cannot touch the evaluator.”article, stated

Use restrictive negative rules to raise precision

Rejected because: Restrictive rules repeatedly reduced recall without improving precision.

“Negative examples, skip lists, “don’t do X” directives — they all reduce recall without improving precision. The LLM becomes cautious and starts missing real decisions.”article, stated

Patterns

eval-driven-development (quality)

Every agent change was measured against a golden dataset before being kept or reverted.

“An AI agent improving another AI agent’s code, measuring its own impact, keeping what works, reverting what doesn’t.**”article, stated

prompt-versioning (model-operations)

The optimization surface included prompts, tool descriptions, DSPy signatures, and schema field descriptions as explicit tunable artifacts.

“The optimization surface includes: system prompts that guide the agent, DSPy signature docstrings that instruct the extraction LLM, tool descriptions that influence tool selection, Pydantic schema field descriptions that shap”article, stated

Tradeoffs

How to use an agent to modify another agent.

Chose bounded experimental edits with evals and revert rules over unconstrained autonomous refactoring.

Rationale: The program file constrained what Claude could change and how success was measured.

“program.md— I wrote the directives: which files Claude Code can modify, what the eval metric is, what constraints to follow (“don’t overfit to the golden cases”)”article, stated

Optimization safety boundary.

Chose modifiable surfaces plus immutable evaluator over unconstrained agent refactoring of system and metric.

Rationale: The optimizer can search broadly while the score remains stable and comparable.

"2. Modifiable code — Lerim’s prompts, tool descriptions, DSPy signatures, schema definitions, and the whole harness. Claude Code edits these.

3. Immutable evaluator— A composite score (extraction quality, search relevance, dedup accuracy, maintain precision)"

— article, stated

Guidance style for extraction quality.

Chose positive quality criteria and schema descriptions over restrictive skip lists and negative examples.

Rationale: Positive guidance improved quality while restrictive rules made the extractor cautious and reduced recall.

“Tell the LLM what good looks like. Never tell it what to avoid.”article, stated

Gotchas (what bit them)

Prompt engineering was not the only or largest optimization lever.

Root cause: Schema and component-level changes could cascade through the end-to-end memory pipeline.

Resolution: Let the optimizer test prompts, signatures, schemas, tools, and harness changes under one metric.

“The experiments revealed that schema-level changes outperformed prompt engineering, that positive guidance beats restrictive rules, and that component-level optimizations cascade into end-to-end improvements across the entire system.”summary, stated

Evaluation

Two rounds and 24 experiments measured composite quality score changes.

Metrics: 41% composite quality improvement · 24 experiments · 14 experiments in one evening

“The result: 41% improvement in composite quality score from 14 experiments over one evening.”article, stated

Outcomes

Author warns the exact code snapshot is old and not meant to be reproduced literally.

“The numbers and lessons below are real, but don’t try to reproduce the specific code changes — they live in an older commit.”article, implied