agentleFS
topprismdatatopprismdata/cultivating-ml-agent/skills/examples/runtime-reflexion/SKILL.md

runtime-reflexion

Skill5 starsChanged 34 days agoMITView on GitHub

Use when running Python code via sandbox, when an experiment fails with a runtime error, when building self-correcting ML agents, or when debugging auto-generated code. Triggers on subprocess failures, ImportError, CUDA OOM, shape mismatch, or any "agent gets stuck on syntax error" pattern.

  • Installs packages

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When LLM fix is unavailable (record-only mode)

    line 88
  2. Distinctive:

    Combine with sandbox isolation: never run untrusted code outside subprocess

    line 91

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Runtime Reflexion (Error → Diagnose → Retry)

Context

Static skills freeze knowledge. Reflexion (Shinn et al. NeurIPS 2023) + Code Sandbox makes ML agents self-correct: 80%+ of runtime errors auto-fixable when errors are precisely classified. agy verified this as a P0 must-have for ML agents (MLE-bench Kaggle medal correlation).

The core insight: errors aren't random — they fall into ~12 categories, each with known fixes.

Guidance

Single Execution with Diagnosis

from framework.src.reflexion import CodeSandbox, ErrorAnalyzer, execute_with_analysis

sandbox = CodeSandbox(timeout_sec=30)
result, diagnosis = execute_with_analysis(generated_code, sandbox)

if not result.success:
    print(f"Error: {diagnosis.category.value}")
    print(f"Suggested fix: {diagnosis.suggested_fix}")
    print(f"Related skills: {diagnosis.related_skills}")
    # → "category=memory, fix=reduce batch_size, skills=[gpu-readiness-assessment]"

Self-Correction Loop

from framework.src.reflexion import ReflexionLoop, CodeSandbox

def my_llm_fix(prompt: str) -> str:
    """Call Claude/your LLM to fix code given the reflexion prompt"""
    return llm_client.messages.create(
        model="claude-sonnet-4-6",
        messages=[{"role": "user", "content": prompt}],
    ).content[0].text

loop = ReflexionLoop(
    sandbox=CodeSandbox(timeout_sec=60),
    llm_fix=my_llm_fix,
)
result = loop.run(initial_code, max_attempts=5)

if result.success:
    deploy(result.final_code)
else:
    log_to_vault(result.final_diagnosis)  # remember for next time

Error Categories (12)

CategoryTriggerFix
syntaxSyntaxErrorCheck indentation
importModuleNotFoundErrorpip install
shapeshape mismatchreshape/transpose
memoryCUDA OOMreduce batch_size
overfittingval_loss divergingdropout/early stop
data_leakage"leakage" mentionedcheck temporal features
timeouttimed outreduce data/optimize
.........

Why This Matters

Without Reflexion: agent gets stuck on syntax error → user manually fixes → no learning. Repeat next competition.

With Reflexion: agent auto-fixes 80%+ errors → escalates to LLM with precise diagnosis → logs to vault for future prevention.

agy: "Reflexion + Sandbox is the only reliable deployment pattern for code-generation agents in 2025-2026."

When to Apply

When to Use

  • Auto-generated Python code from LLM
  • ML pipeline runs that may fail
  • Kaggle competition automation
  • Agent benchmarks (MLE-bench, AIDE)
  • Any "agent gets stuck and gives up" pattern

When NOT to Use

  • Single-shot queries (overkill)
  • Production stable code (just monitor)
  • When LLM fix is unavailable (record-only mode)

Notes

  • Combine with sandbox isolation: never run untrusted code outside subprocess
  • Set timeouts aggressively: 30-60s default; ML training needs more
  • Log failures to vault: future prevention (memory-hierarchy-management)
  • Track fix success rate: <50% means your prompts need improvement
  • See also: multi-agent-roles (Critic uses Reflexion), self-evolving-skills

References

  • Implementation: framework/src/reflexion/
  • Research: Shinn et al. "Reflexion" (NeurIPS 2023), MLE-bench (OpenAI 2024)
  • Pairing skill: multi-agent-roles (Continuity-Critic uses ErrorAnalyzer)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.