Catalog PyPI
PACKAGE EXPLORERView in registry

agent-self-edit

PyPI

An agent that rewrites its own system prompt from execution feedback

Versions collected1
Direct dependencies8From release 0.3.0
Last observed20 Oct, 23:19 UTC

README

Version 0.3.0 documentation

AgentSelfEdit

PyPI version Python Tests License OpenSSF Best Practices

A self-improving agent prompt optimizer. Proposes edits to its own system prompt from execution feedback, A/B tests them against a held-out task set, and promotes only statistically-proven winners under deterministic guardrails.

Changelog · v0.2.0 Release Notes · v0.1.0 Field Test Report · v0.2.0 Field Test Report

Why

Most production agents are prompt-tuned once by hand, then frozen at ship time. Every recurring failure is silently absorbed. Two common approaches fall short:

  • Reflection appends prose to context but never changes the prompt itself. The same failure repeats.
  • Unconstrained LLM-judged edits poison the baseline within a few iterations.

AgentSelfEdit is a sidecar that observes execution traces and proposes prompt edits through a deterministic, evidence-driven loop.

Quick Start

pip install agent-self-edit
agent-self-edit init
agent-self-edit run --once

How It Works

Agent executes task → Execution trace stored (SQLite)
                           ↓
                 Feedback Analyzer (LLM)
                 reviews traces, proposes concrete edits,
                 each with a written hypothesis
                           ↓
            ──── A/B Test Engine ────
             candidate vs current prompt
             held-out task set, bootstrap CI,
             effect size, permutation p-value
            ───────────────────────────
                           ↓
               Promotion Gate (deterministic)
               1. Sample floor     4. Frozen sections
               2. Effect size      5. Edit-distance limit
               3. Confidence p-val 6. Drift detection
                           ↓
                 ┌──────────┼──────────┐
                 ▼          ▼          ▼
             Promoted   Near-miss   Rejected
  1. Analyze — An LLM reviews execution traces and identifies failures.
  2. Propose — Concrete, minimal prompt edits with stated hypotheses.
  3. Test — Each candidate is A/B tested with confidence intervals and effect-size thresholds.
  4. Promote or Archive — Winners become the new baseline; losers are archived with reasoning.
  5. Guard — Frozen sections, edit-distance limits, and drift detection prevent degradation.

Core Components

ComponentWhat it does
Feedback AnalyzerLLM that reviews traces and produces edit proposals. v0.2.0: staged 4-pipeline (summarize → select → synthesize → score) with rejection-context feedback.
A/B Test EngineCompares candidate vs current prompt on held-out tasks. v0.2.0: 40-task promotion corpus.
Promotion GateSix deterministic checks: sample floor, effect size, confidence, frozen sections, edit-distance, drift. Code, not LLM-judged.
Prompt RegistryFile-based versioned store with full lineage, diff, rollback, SHA-256 integrity.
ScorersRuntime-selectable: ExactMatch, StructuredExtraction, LLMJudge. Label-set-aware, multi-domain.
CLIinit, run, status, diff, rollback, guardrails, lineage, propose, ingest, validate.

The Promotion Gate

Six fail-fast checks before any edit is promoted:

  1. Sample floor — minimum A/B trials completed
  2. Effect size — minimum improvement threshold
  3. Confidence — p < 0.05 (default)
  4. Frozen core sections — user-annotated protected regions
  5. Edit-distance limit — max lines changed per cycle
  6. Drift detection — semantic similarity to original prompt

Field Test Results

v0.1.0

15-iteration loop against Qwen3.5-4B-4bit (local). Gate correctly rejected every edit.

MetricResult
FP rate (bad edits promoted)0%
FN rate (good edits rejected)0%
LLM calls4,150
Wall time37 min
Cost$0.00

v0.2.0

Validation across 4 domains, adversarial edits, real-trace ingestion, Docker. Strongest analyzer: Mistral Small 24B (OpenRouter). Directional gains but no promotable edit — framework is sound, analyzer quality is the bottleneck.

MetricResult
FP rate0%
FN ratenot observed
Multi-domain suites4/4
Adversarial edits caught5/5 (0 FN)
Strongest analyzermistralai/mistral-small-3.2-24b-instruct
Coverage81% (target 92%)

Full v0.2.0 field test report

Trigger Modes

  • Batch — analyze after N tasks (default: 50)
  • Time-based — analyze every N hours
  • Manual — analyze on demand

Where It Helps

Agents that repeat a task type and see execution feedback: classification, code review, data extraction, content moderation, sales outreach, documentation generation.

Status

AreaStatus
Core loop✅
Model role separation✅
Staged analyzer✅
Multi-domain support✅
Runtime scorer selection✅
Adversarial rejection (5/5)✅
Real-trace ingestion✅
Tests (489/489 pass)✅
Ruff + mypy strict✅
Security (bandit, gitleaks, trufflehog)✅ clean
Coverage⬜ 81%

Roadmap

VersionFocus
v0.1.0✅ Released — core loop, gate, CLI, Docker
v0.2.0✅ Released — staged analyzer, model roles, multi-domain, field test
v0.3.0Framework adapters, multi-failure clustering, adaptive sample floors
v0.4.0Fleet-wide learning, cost-aware improvement
v1.0.0Stable API, production deployment guide

License

MIT — see LICENSE

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
0.3.04 Sept 20268

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
deghosal-2026/agent-self-edit

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 23:19 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:0e818122b8f512d30006cecefbe30bc0a8ef34eb291950b4ac6ff8ef9c480e5a