正在加载陈远的个人网站

Agent Loop Library:可复用工作流与验证闭环

收录带检查项与停止条件的 AI Agent 工作流,覆盖研发、评测、运营与内容场景。

原始内容

This is the best site on the internet to find agent loops you can use right now. Free. Completely. Most AI engineers are still writing these from scratch. https://t.co/FHDHGXam6Z Bookmark this site. Then read this ↓ https://t.co/H5vkrn3UJ2

20 Loop Design Patterns Every AI Engineer Should Know Most AI engineers know how to build an agent. Very few know how to build a system that gets better after the first attempt. That gap is worth six figures. Here's the difference: An agent is a worker. A loop is what makes the worker improve. The most capable AI systems in production today are not single model calls. They are loops. Generate → Evaluate → Learn → Improve. Over and over. Until the output is actually good. Here are 20 loop design patterns that show up repeatedly in production AI systems. Save this. You will build with these. --- ## Agents vs Loops Old way: Prompt → Response → Done. New way: Generate → Critique → Rewrite → Score → Retry → Remember → Improve. One is a factory worker who does the job once. The other is a factory worker who studies every mistake, rewrites the playbook, and gets 3% better every single shift. The teams shipping production AI right now are not writing better prompts. They are building better loops. --- ## CATEGORY 1 — QUALITY IMPROVEMENT LOOPS (Make the output better before it leaves the system) --- ## 1. Generate → Critique → Rewrite The most important loop in AI engineering. Generate output. Critic reviews it. Generator rewrites based on feedback. Repeat until quality threshold is met. Not one model. Two roles. One pipeline. ```plaintext [Generator] → draft [Critic] → "paragraph 3 is vague. missing evidence. tone is off." [Generator] → rewrite based on critique [Critic] → "better. but conclusion still weak." [Generator] → final rewrite ``` Used for: writing, code review, reports, strategy docs, sales emails. The insight: the model that generates is not the best judge of its own output. A separate critic finds what the generator missed every time. --- ## 2. Score-and-Retry Loop Generate. Score. Retry if below threshold. Simple. Powerful. Underused. score = evaluate(output) ```plaintext score = evaluate(output) while score < threshold: output = generate(prompt) score = evaluate(output) attempts += 1 if attempts > max_retries: return best_so_far ``` Best when quality is measurable — extraction accuracy, format compliance, factual correctness, lead scoring. The generator doesn't know it's being graded. The evaluator does. That separation is the pattern. --- ## 3. Multi-Critic Loop One critic has blind spots. Use four. → Correctness critic: is it factually accurate? → Style critic: is it clear and well-written? → Safety critic: is it appropriate and safe? → Domain critic: does it meet specialist standards? Each evaluates independently. Final output must satisfy all four before it exits. Used in: medical AI, legal document review, financial analysis, regulated content. --- ## 4. Adversarial Critique Loop The critic's only job is to break the answer. Not improve it. Break it. Questions the adversarial critic asks: → What assumptions fail here? → What evidence is missing? → What would a skeptic say? → Where is this confidently wrong? The generator then defends or rewrites. The best answer survives the attack. Used for: research synthesis, investment thesis review, strategic planning, risk analysis. --- ## 5. Judge Ensemble Loop One judge gives noisy scores. Five judges average out the noise. Run the same output through multiple evaluators. Aggregate scores. Only outputs with high consensus advance. Used when: single-model evaluation is unreliable, stakes are high, edge cases matter. --- ## CATEGORY 2 — MEMORY LOOPS (Learn from what happened so next time is smarter) --- ## 6. Reflexion Loop The most important self-improvement pattern that exists. Agent fails. Agent analyzes why it failed. Agent stores the lesson. Agent retries with that lesson in context. Each iteration: smarter than the last. ```plaintext attempt 1: fails reflection: "I assumed X but X was wrong. Next time verify X first." attempt 2: incorporates lesson → partial success reflection: "Better. But I skipped Y. Add Y check." attempt 3: succeeds ``` The difference between a system that fails once and a system that only fails once. ## 7. Memory Update Loop After every task, store three things: → What decision was made → What the outcome was → What would be done differently Future runs inherit this knowledge. The system in month 6 is not the same as the system in month 1. It has read 6 months of its own history. --- ## 8. Error Library Loop Store every failure. Wrong answer. Bad output. Failed execution. Edge case. Before acting on a new task: Search the error library first. If a similar failure exists → apply the known fix before even starting. The system stops making the same mistake twice. The most underused pattern in production AI. --- ## 9. Success Pattern Loop Most engineers only store failures. Store successes too. When a task goes well: → Save the approach → Save the context → Save what made it work Retrieve successful patterns when facing similar tasks. Learn from wins. Not just mistakes. --- ## 10. Memory Compression Loop Memory grows forever. Unlimited memory is unusable memory. After N items accumulate: Compress them. Many specific memories → fewer higher-level abstractions. ```plaintext Before compression: "Failed on task A because of X" "Failed on task B because of X" "Failed on task C because of X" After compression: "Pattern: X causes failures. Always check X first." ``` Context stays manageable. Patterns stay accessible. System stays fast. --- ## CATEGORY 3 — PLANNING LOOPS (Adapt the plan when reality changes) --- ## 11. Plan → Execute → Replan The most common mistake in AI agent design: Treating the plan as fixed. Plans break on contact with reality. The pattern: Create plan → execute step → observe outcome → update plan → continue Not a waterfall. A spiral. Each lap around tightens the approach. Used when: environment changes, tasks have dependencies, long-horizon goals. --- ## 12. Dynamic Workflow Loop Most pipelines are fixed. Step 1 → Step 2 → Step 3. Always. Dynamic workflows change based on results. If output A → run branch X If output B → run branch Y If output C → skip to step 5 The pipeline decides its own shape at runtime. Used in: multi-document research, customer support routing, adaptive content pipelines. --- ## 13. Goal Decomposition Loop Large goal enters. System breaks it into subgoals. Each subgoal breaks into tasks. Each task breaks into steps. Decompose until each unit is small enough to execute in one call. ```plaintext Goal: "Write a comprehensive competitive analysis" ↓ Subgoal 1: "Identify top 5 competitors" Subgoal 2: "Analyze each competitor's product" Subgoal 3: "Compare pricing models" Subgoal 4: "Identify gaps" ↓ Each subgoal → tasks → individual model calls ``` The loop keeps decomposing until the system can act. --- ## 14. Progress Evaluation Loop Every N steps: stop and ask. "Are we actually getting closer to the goal?" If yes: continue current strategy. If no: change strategy, tools, or plan. The system monitors its own progress. Not just executes blindly. Used in: long-running research agents, multi-day autonomous tasks, debugging agents. --- ## 15. Constraint Satisfaction Loop Keep running until all constraints are met. ```plaintext while not all_constraints_satisfied(output): output = improve(output, unsatisfied_constraints) constraints = [ budget_under_limit, quality_above_threshold, latency_under_200ms, tone_matches_brand, no_hallucinations ] ``` Very common in production systems. The output is not done until every business rule passes. --- ## CATEGORY 4 — EXPLORATION LOOPS (Find the best answer by trying multiple paths) --- ## 16. Branch-and-Explore Loop Don't commit to one path. Explore several simultaneously. ```plaintext paths = [ generate(approach="conservative"), generate(approach="aggressive"), generate(approach="creative") ] scores = [evaluate(p) for p in paths] best = paths[scores.index(max(scores))] ``` Compare outcomes. Choose the best branch. Discard the rest. Used for: content variations, architecture decisions, debugging multiple hypotheses, A/B generation. --- ## 17. Tree Search Loop Branch-and-Explore goes one level deep. Tree Search goes as deep as needed. Expand the most promising nodes. Prune the weakest ones. Keep exploring until the solution is found. ```plaintext root → [A, B, C] A → [A1, A2] # A looks promising, expand it B → prune # B is weak, stop here A1 → [A1a, A1b] A1a → solution ✓ ``` Used for: complex reasoning chains, multi-step planning, code debugging, research synthesis. Computationally expensive but finds solutions single-pass calls cannot. --- ## 18. Debate Loop Two agents. One topic. Opposite positions. Agent A argues for the answer. Agent B argues against it. Each round challenges assumptions, demands evidence, exposes weak logic. Final answer emerges through disagreement. Not through agreement. The adversarial pressure finds what confident single-agent answers miss. Used for: investment decisions, strategic planning, risk assessment, research critique. --- ## CATEGORY 5 — SYSTEM OPTIMIZATION LOOPS (The loop improves the loop) --- ## 19. Prompt Optimization Loop Most engineers write a prompt once and never touch it again. Prompt optimization loops change that. The system: → Runs the prompt on a test set → Scores every output → Identifies where the prompt fails → Rewrites the prompt to fix those failures → Reruns and rescores The prompt gets better automatically. Without a human touching it. ```plaintext current_prompt = "Summarize this document." for iteration in range(max_iterations): outputs = [run(current_prompt, doc) for doc in test_set] scores = [evaluate(o) for o in outputs] avg_score = mean(scores) if avg_score >= target: break failures = [o for o, s in zip(outputs, scores) if s < threshold] current_prompt = improve_prompt(current_prompt, failures) # Prompt rewrites itself based on where it fails ``` Used in: production pipelines, automated content systems, classification tasks. The best prompts in production AI were not written by a human. They were evolved. --- ## 20. Workflow Optimization Loop This is where it gets interesting. The loop improves the loop. The system measures its own performance: → latency: how long does each step take? → cost: how many tokens does each call use? → quality: what is the output score at each stage? Then it modifies its own workflow. Too slow? Parallelize two steps. Too expensive? Replace a GPT-4 call with a smaller model where quality holds. Quality dropping? Add a critic before the final output. ```plaintext metrics = measure_workflow(outputs, latency, cost) if metrics.latency > target_latency: workflow = parallelize(slow_steps) if metrics.cost > budget: workflow = replace_with_cheaper_model(high_cost_steps) if metrics.quality < threshold: workflow = add_critic_before(final_output_step) ``` This is where truly self-improving systems begin. Not just outputs that improve. Systems that redesign themselves. --- ## The pattern behind all 20 patterns Every single loop above shares one structure: Act → Observe → Evaluate → Adjust That is the entire recipe. The output is never final on the first attempt. The output is a starting point. The loop is what turns a starting point into something production-worthy. --- ## The full map Category 1 — Quality Loops (Make output better before it leaves) → 1. Generate → Critique → Rewrite → 2. Score-and-Retry → 3. Multi-Critic → 4. Adversarial Critique → 5. Judge Ensemble Category 2 — Memory Loops (Learn from what happened) → 6. Reflexion → 7. Memory Update → 8. Error Library → 9. Success Pattern → 10. Memory Compression Category 3 — Planning Loops (Adapt when reality changes) → 11. Plan → Execute → Replan → 12. Dynamic Workflow → 13. Goal Decomposition → 14. Progress Evaluation → 15. Constraint Satisfaction Category 4 — Exploration Loops (Find best answer by trying many paths) → 16. Branch-and-Explore → 17. Tree Search → 18. Debate Category 5 — System Optimization Loops (The loop improves the loop) → 19. Prompt Optimization → 20. Workflow Optimization --- ## Most engineers think agents are the future. Agents are just workers. Loops are what make workers improve. The biggest shift happening in AI right now is not better models. It's moving from: Prompt → Response to Generate → Evaluate → Learn → Improve The teams that master loop design will not build better prompts. They will build systems that get better every single day after deployment. Without anyone touching them. --- ## If this was useful: → Repost to share it with every AI engineer you know → Follow @sairahul1 for more patterns like this → Bookmark this — pick one loop and implement it this week I write about AI, building products, and systems that work without you.

— @sairahul1(Rahul)的引用原文
Agent Loop Library:可复用工作流与验证闭环,来源媒体第 1 张,共 1 张

深度解析

是什么 这条推文推荐 Forward Future 的 Loop Library,一个集中收录 Agent 工作流提示词的目录。它的核心承诺不是教人从零搭建 Agent,而是提供可以直接复制、运行和改进的循环模板,并为任务配套检查项与停止条件。配套的 Loopy skill 还能引导 Agent 完成查找、编写、运行、改进和发布。

核心设计 库中的 loop 通常遵循“目标设定—执行—验证—修复或迭代—再次验证—停止”的闭环。示例覆盖文档同步、架构重构、性能基准、生产错误、测试覆盖、发布运维、客户 AI 部署以及 SEO/GEO 审计等场景。分类、搜索、排序、复制与投票机制降低了发现和复用成本。

关键洞察 推文强调,Agent 的差异不只在一次任务能否完成,更在系统能否通过测试、证据、回归和复盘持续变好。优秀 loop 把模糊的“继续优化”转成可观测的验收标准,适合作为团队运行手册、编码 Agent 的任务协议或研发自动化起点。

边界与风险 “100% 覆盖”“低于 50 毫秒”等绝对目标可能诱发指标游戏或无限循环;涉及生产数据、发布、仓库清理和外部沟通时仍需权限、审批、范围和回滚机制。截图显示 70 条 loop、更新于 2026 年 6 月,而正文显示 85 条、更新于 7 月,说明页面数据可能随版本变化,不宜把数量当作稳定事实。