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
In this repository63 other files it gives its agents.
- AGENTS.mdAGENTS.md
- adversarial-validation-kaggleSkill
- agent-nurture-frameworkSkill
- agent-session-memory-protocolSkill
- arxiv-paper-searchSkill
- autogluon-firstSkill
- autogluon-preset-strategySkill
- autogluon-timeseries-strategySkill
- catboost-first-tabularSkill
- claudeceptionSkill
- code-competition-artifact-pipelineSkill
- competition-orchestration-multimodelSkill
- context-engineeringSkill
- controlled-submission-experimentSkill
- cross-competition-feature-transferSkill
- cv-lb-gap-acknowledgmentSkill
- domain-knowledge-constraints-trapSkill
- ensemble-model-correlation-trapSkill
- feature-engineering-saturation-detectionSkill
- gpu-readiness-assessmentSkill
- gsd-loop-engineeringSkill
- kaggle-cognitive-cost-optimizationSkill
- kaggle-competition-best-practicesSkill
- kaggle-competition-type-strategySkill
- kaggle-data-format-firstSkill
- kaggle-discussion-searchSkill
- kaggle-experiment-sopSkill
- kaggle-oof-lb-validation-protocolSkill
- kaggle-optimal-blendingSkill
- kaggle-submission-format-by-metricSkill
- kaggle-top-performer-replicationSkill
- knowledge-crystallization-feedback-loopSkill
- ladder-drift-and-meta-aware-regressionSkill
- learned-value-beats-heuristic-augmentationSkill
- llm-competition-pipelineSkill
- mcts-pipeline-searchSkill
- mem0-dynamic-graph-memorySkill
- memory-hierarchy-managementSkill
- ml-sweet-spot-principleSkill
- model-ensemble-negative-weight-effectSkill
- multi-agent-rolesSkill
- multi-level-aggregation-overfittingSkill
- okf-visualize-knowledgeSkill
- onnx-minimal-network-designSkill
- per-category-modeling-backfireSkill
- progressive-verification-debuggingSkill
- ptcg-2ply-bounded-searchSkill
- ptcg-bc-large-model-submissionSkill
- retail-eda-frameworkSkill
- rmsle-zero-threshold-asymmetrySkill
- sc-tir-mathematical-reasoningSkill
- self-evolving-skillsSkill
- skill-governance-and-automationSkill
- spatiotemporal-graph-feature-engineeringSkill
- store-sales-darts-chronos-blendSkill
- tabular-polynomial-features-breakthroughSkill
- three-layer-wisdom-extractionSkill
- time-series-walk-forward-validationSkill
- trueskill-simulation-competition-strategySkill
- ts-day-specific-forecastingSkill
- The first 60 shown.
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
- Distinctive: line 88
When LLM fix is unavailable (record-only mode)
- Distinctive: line 91
Combine with sandbox isolation: never run untrusted code outside subprocess
≈ “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.
Files
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 timeError Categories (12)
| Category | Trigger | Fix |
syntax | SyntaxError | Check indentation |
import | ModuleNotFoundError | pip install |
shape | shape mismatch | reshape/transpose |
memory | CUDA OOM | reduce batch_size |
overfitting | val_loss diverging | dropout/early stop |
data_leakage | "leakage" mentioned | check temporal features |
timeout | timed out | reduce 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)
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
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.

