askill
reflexion

reflexionSafety 100Repository

Post-action analysis to generate heuristics, update project memory, and prevent regression loops.

1 stars
1.2k downloads
Updated 1/30/2026

Package Files

Loading files...
SKILL.md

Reflexion Skill

Purpose

To transform Failures into Heuristics. Reflexion is the cognitive step that occurs after a failed attempt and before the next attempt. It breaks the "Insanity Loop" (doing the same thing twice expecting different results).

ROI Metric: Prevents 5-10 wasted attempts in a loop by forcing a strategy shift after the first failure.

When to Use

  • Automatic Trigger: After a tool error (e.g., bash exit code != 0).
  • Automatic Trigger: After a test failure during execution mode.
  • Manual Trigger: When the user rejects an artifact ("This isn't what I asked for").
  • Periodic: At the end of a major feature (Project Retro).

The Reflexion Protocol (The Loop)

1. The Halt (Stop)

Rule: Never retry immediately. If an error occurs, you must pause. Do not simply re-run the command hoping for a different outcome.

2. The Trace (Diagnosis)

Action: Analyze the mismatch between Expected Output and Actual Output.

  • Was it a Syntax Error? (Context failure).
  • Was it a Logic Error? (Reasoning failure).
  • Was it a Hallucination? (Knowledge failure).

3. The Heuristic (Correction)

Action: Create a new rule for yourself.

  • Old Thought: "I will use rm -rf to clean up."
  • New Heuristic: "I must check if the directory exists before attempting delete."

4. The Store (Memory)

Action: Save this lesson.

  • Short-term: Apply to current context window.
  • Long-term: Write to .opencode/memory/patterns.md.

Execution Template

Use this scratchpad when entering a Reflexion State.

## 🧠 Reflexion: [Failure Context]

### 1. Analysis
- **Expectation**: Test passed.
- **Reality**: `ReferenceError: User is not defined`
- **Gap**: I assumed `User` was exported from `types.ts`, but it was a default export.

### 2. Critique
"I failed to check the import style of the existing module before writing the import statement."

### 3. New Strategy (The Pivot)
- ❌ **Stop**: Guessing import paths.
- βœ… **Start**: Using `grep` to see how other files import `User`.
- **Action**: Run `grep -r "import.*User" .` before fixing.

### 4. Memory Update
- [ ] Add to Local Context? (Yes)
- [ ] Add to Project Patterns? (No - simple syntax error)

Memory Schema & Storage

Maintain a dedicated memory structure to allow the researcher and pm-agent to learn over time.

.opencode/
└── memory/
    β”œβ”€β”€ active_context.md       # Scratchpad for current session
    β”œβ”€β”€ patterns.md             # Success patterns (What works here)
    └── anti_patterns.md        # Failure log (What breaks here)

Example: .opencode/memory/anti_patterns.md

## β›” Anti-Patterns

### 1. Database Connections
- **Context**: Next.js Server Components.
- **Failure**: "Too many connections" error.
- **Lesson**: Do not instantiate Prisma Client inside the component. Use the singleton pattern defined in `src/lib/db.ts`.

### 2. Styling
- **Context**: Button Components.
- **Failure**: Tailwinds classes not applying.
- **Lesson**: We are using `tailwind-merge`. Standard string concatenation will fail. Always use `cn()` utility.

Integration with Agents

  • execution agent: Must trigger reflexion after 2 failed build attempts.
    • Logic: "Attempt 1 Failed -> Retry -> Attempt 2 Failed -> STOP & REFLECT -> Attempt 3".
  • pm-agent: Reads .opencode/memory/patterns.md at the start of a new task to load context.
  • writer: Uses successful reflexions to update the project's README.md or CONTRIBUTING.md.

Reflexion vs. Debugging

Featuredebug-protocolreflexion
FocusThe CodeThe Agent's Process
GoalFix the BugImprove the Strategy
OutputWorking SoftwareBetter Internal Rules
Question"Why is variable X null?""Why did I write code that made X null?"

Install

Download ZIP
Requires askill CLI v1.0+β–Ά

AI Quality Score

91/100Analyzed 2/19/2026

Well-structured cognitive skill for post-failure analysis. Provides comprehensive coverage with clear triggers, a 4-step protocol (Halt-Trace-Heuristic-Store), execution templates, and memory schema. Includes valuable comparison with debugging. Tags improve discoverability. Minorζ‰£εˆ† for tight coupling to .opencode-specific paths and agents, but the core methodology is sound and highly actionable. Path depth >4 suggests internal project focus but skill is well-developed."

100
95
75
95
90

Metadata

Licenseunknown
Version-
Updated1/30/2026
Publisherlst97

Tags

ci-cddatabaseobservabilitytesting