一键导入
agentic-reflection
Reflection pattern for quality-critical outputs using generate-critique-refine cycles. Requires clear evaluation criteria and acceptable latency.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Reflection pattern for quality-critical outputs using generate-critique-refine cycles. Requires clear evaluation criteria and acceptable latency.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Formal reasoning via FOL theorem proving, model finding, and categorical logic
Use modern, token-efficient command-line tools (fd, ripgrep, ast-grep, bat, sd, jq, yq, tokei, eza, dust, procs, delta, hyperfine, just) instead of legacy coreutils (find, grep, cat, sed, ls, du, ps) for any shell, file, or codebase task — on any platform (Linux/macOS/Windows) and through any executor (a terminal, Claude Code's bash tool, Desktop Commander, or an MCP shell bridge). Trigger whenever you are about to search files, grep for text, read or inspect files, find-and-replace, refactor code, traverse a repository, process JSON/YAML, or inspect disk usage or processes — even if the user did not name a specific tool. These tools are faster, .gitignore-aware, and emit clean structured output that protects the context window. For installation across operating systems and platform-specific quirks, see references/. If you run commands specifically through the LocalREPL MCP bridge, also consult the local-repl-cli skill for environment-specific gotchas.
Operating guide for the AGEM reasoning engine: native tools, honest metric interpretation, formal-logic verification via mcp-logic, and the meta-tool MCP interface.
Use when the user wants to design, redesign, shape, critique, audit, polish, clarify, distill, harden, optimize, adapt, animate, colorize, extract, or otherwise improve a frontend interface. Covers websites, landing pages, dashboards, product UI, app shells, components, forms, settings, onboarding, and empty states. Handles UX review, visual hierarchy, information architecture, cognitive load, accessibility, performance, responsive behavior, theming, anti-patterns, typography, fonts, spacing, layout, alignment, color, motion, micro-interactions, UX copy, error states, edge cases, i18n, and reusable design systems or tokens. Also use for bland designs that need to become bolder or more delightful, loud designs that should become quieter, live browser iteration on UI elements, or ambitious visual effects that should feel technically extraordinary. Not for backend-only or non-UI tasks.
Master orchestrator for the five-question decision tree that selects the right agentic pattern from Sequential, ReAct, Planning, Reflection, or Multi-Agent.
Multi-agent pattern for tasks requiring specialization or scale beyond single-agent capacity. Covers topology, routing, and coordination design.
| name | agentic-reflection |
| description | Reflection pattern for quality-critical outputs using generate-critique-refine cycles. Requires clear evaluation criteria and acceptable latency. |
[!TIP] TL;DR: Use this pattern when output quality matters more than response speed, AND evaluation criteria are clear. The agent generates, critiques, and refines until quality thresholds are met. Key Principle: "Critic independence is critical. If the critic mirrors the generator too closely, it tends to agree rather than evaluate."
The reflection pattern is grounded in the expectation that first-pass outputs are often incomplete or flawed, and that iterative self-critique and refinement improves final quality enough to justify the added cost.
┌─────────────────────────────────────────────────────┐
│ REFLECTION CYCLE │
│ │
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
│ │ Generate│───▶│ Critique│───▶│ Refine │ │
│ │ "First │ │ "What's │ │ "Fixed │ │
│ │ draft" │ │ wrong?" │ │ version"│ │
│ └─────────┘ └─────────┘ └─────────┘ │
│ │ │ │ │
│ ◀──────────────┴──────────────┘ │
│ (iterate until quality met) │
└─────────────────────────────────────────────────────┘
When to use: Apply this pattern when:
BOTH conditions must be met.
| Good Criteria | Bad Criteria |
|---|---|
| "Valid SQL query that returns expected columns" | "Good code" |
| "Contract with all required fields filled" | "Professional document" |
| "Passes linting + unit tests + integration tests" | "Clean output" |
| "Mathematically equivalent to specification" | "Correct answer" |
Without clear criteria, the critic produces vague or misleading feedback.
| High Error Cost (use reflection) | Low Error Cost (skip reflection) |
|---|---|
| Deployed production code | Development exploration |
| Client-facing documents | Internal scratchpads |
| Regulatory submissions | Drafts for internal review |
| Financial transactions | High-throughput batch processing |
This is the most important design choice in reflection patterns:
Generator: GPT-4
Critic: Same GPT-4, slightly different prompt
→ Tendency: Agree rather than evaluate
→ Result: Minimal improvement, wasted cycles
Generator: GPT-4
Critic: Different model (e.g., Claude), OR
Same model but different framing/context, OR
Rule-based validator for specific criteria
→ Result: Genuine evaluation, meaningful improvement
MAX_ITERATIONS = 3 # Prevent infinite loops
For iteration in 1..MAX_ITERATIONS:
1. Generate output
2. Evaluate against criteria
3. If PASSED → return output
4. If FAILED → generate critique
5. Refine based on critique
6. Loop
If MAX_ITERATIONS reached without PASS:
→ return best effort OR escalate to human
| Signal | Cause | Fix |
|---|---|---|
| Critique cycles don't improve output | Evaluation criteria unclear | Define sharper, verifiable criteria |
| Critique cycles don't improve output | Critic too aligned with generator | Use different model/framing for critic |
| Same errors persist | Critique not actionable | Make critique specific to criteria |
| Signal | Cause | Fix |
|---|---|---|
| Cycles continue without end | No stopping condition | Define max iterations |
| Quality doesn't improve | Criteria not achievable | Revise criteria or accept current state |
def reflection_loop(generator, critic, criteria, max_iterations=3):
best_output = None
best_score = -1
for i in range(max_iterations):
output = generator.generate()
score = critic.evaluate(output, criteria)
if score > best_score:
best_output = output
best_score = score
if score >= threshold:
return output # Quality met
critique = critic.critique(output, criteria)
generator.refine(critique)
return best_output # Best effort after max iterations
Reflection adds well to other patterns:
| Base Pattern | + Reflection | Use When |
|---|---|---|
| ReAct | + Quality at each step | Quality critical at each stage |
| Planning | + Checkpoint validation | Quality gates between stages |
| Multi-Agent | + Specialist critique | Domain-specific quality checks |
run_agem_cycle — Generation phaseget_cohomology — Check generator/critic alignment (should be LOW for independence)spawn_agem_agent — Spawn independent critic agentadvanced-reasoning — Deep critique reasoningmcp-logic — Formal verification of generated outputshipai-montague — Track belief evolution through refinementconscience-servitor — Ethical evaluation for sensitive outputs1. Define quality criteria (must be verifiable)
2. Set max reflection iterations (typically 2-3)
3. Initialize generator and critic (ensure independence)
4. LOOP:
a. Generate output
b. Evaluate against criteria
c. If PASSED → return
d. If FAILED → critique
e. Refine generator based on critique
f. If max iterations → return best effort
## Reflection Task Definition
**Task**: [What needs to be generated]
**Quality Matters**: [YES/NO]
**Speed Matters**: [YES/NO - if YES, don't use reflection]
**Latency Acceptable**: [YES/NO]
### Quality Criteria (verifiable):
1. [Criterion 1] - [how to verify]
2. [Criterion 2] - [how to verify]
3. [Criterion N] - [how to verify]
### Generator: [model/prompt]
### Critic: [different model/framing for independence]
### Max Iterations: [N]
### Pass Threshold: [score/value]
### Escalation Triggers:
- [Max iterations reached] → human review OR accept best effort
- [Criteria impossible to meet] → revise criteria
| Question | Answer | Use Reflection? |
|---|---|---|
| Quality matters more than speed? | YES | ✓ |
| Clear evaluation criteria exist? | YES | ✓ |
| Both conditions met? | YES | → Use Reflection |
| Either condition NO? | NO | → Skip Reflection |