帮助开发者设计自主代码循环,从顺序流程扩展到多智能体协作架构。
复制安装指令,让 AI 自动完成配置 · 推荐新手
请帮我安装 askskill 上的 "autonomous-loops" 技能: 1. 下载 https://raw.githubusercontent.com/affaan-m/ECC/main/docs/zh-CN/skills/autonomous-loops/SKILL.md 2. 保存为 ~/.claude/skills/autonomous-loops/SKILL.md 3. 装好后重载技能,告诉我可以用了
请为一个 Claude 代码代理设计最简单的自主循环架构,目标是读取任务、编写代码、运行测试、根据结果迭代修复。请输出流程步骤、关键状态、停止条件,以及适合实现的伪代码。
一份基础自主循环方案,包含流程图思路、状态定义、终止规则和伪代码。
把现有的单代理代码自动化流程升级为基于 RFC 的多智能体有向无环图系统,包含需求分析、代码生成、测试、评审和发布节点。请说明各节点职责、输入输出、依赖关系、失败重试策略和治理机制。
一套多智能体 DAG 架构设计,清晰说明节点分工、依赖拓扑和控制策略。
请比较顺序管道、自反思循环、计划-执行循环以及基于 RFC 的多智能体 DAG 四种自主代码循环模式,分别从复杂度、可维护性、扩展性、失败恢复和适用场景进行分析,并给出选型建议。
一份结构化对比分析,帮助用户根据团队规模和任务复杂度选择合适模式。
兼容性说明 (v1.8.0):
autonomous-loops保留一个发布周期。 规范的技能名称现在是continuous-agent-loop。新的循环指南应在此处编写,而此技能继续可用以避免破坏现有工作流。
在循环中自主运行 Claude Code 的模式、架构和参考实现。涵盖从简单的 claude -p 管道到完整的 RFC 驱动的多智能体 DAG 编排的一切。
从最简单到最复杂:
| 模式 | 复杂度 | 最适合 |
|---|---|---|
| 顺序管道 | 低 | 日常开发步骤,脚本化工作流 |
| NanoClaw REPL | 低 | 交互式持久会话 |
| 无限智能体循环 | 中 | 并行内容生成,规范驱动的工作 |
| 持续 Claude PR 循环 | 中 | 具有 CI 门的跨天迭代项目 |
| 去草率化模式 | 附加 | 任何实现者步骤后的质量清理 |
| Ralphinho / RFC 驱动的 DAG | 高 | 大型功能,具有合并队列的多单元并行工作 |
claude -p)最简单的循环。 将日常开发分解为一系列非交互式 claude -p 调用。每次调用都是一个具有清晰提示的专注步骤。
如果你无法想出这样的循环,那意味着你甚至无法在交互模式下驱动 LLM 来修复你的代码。
claude -p 标志以非交互方式运行 Claude Code 并附带提示,完成后退出。链式调用来构建管道:
#!/bin/bash
# daily-dev.sh — Sequential pipeline for a feature branch
set -e
# Step 1: Implement the feature
claude -p "Read the spec in docs/auth-spec.md. Implement OAuth2 login in src/auth/. Write tests first (TDD). Do NOT create any new documentation files."
# Step 2: De-sloppify (cleanup pass)
claude -p "Review all files changed by the previous commit. Remove any unnecessary type tests, overly defensive checks, or testing of language features (e.g., testing that TypeScript generics work). Keep real business logic tests. Run the test suite after cleanup."
# Step 3: Verify
claude -p "Run the full build, lint, type check, and test suite. Fix any failures. Do not add new features."
# Step 4: Commit
claude -p "Create a conventional commit for all staged changes. Use 'feat: add OAuth2 login flow' as the message."
claude -p 调用都是一个新的上下文窗口,意味着步骤之间没有上下文泄露。set -e 在失败时停止管道。使用模型路由:
# Research with Opus (deep reasoning)
claude -p --model opus "Analyze the codebase architecture and write a plan for adding caching..."
# Implement with Sonnet (fast, capable)
claude -p "Implement the caching layer according to the plan in docs/caching-plan.md..."
# Review with Opus (thorough)
claude -p --model opus "Review all changes for security issues, race conditions, and edge cases..."
使用环境上下文:
# Pass context via files, not prompt length
echo "Focus areas: auth module, API rate limiting" > .claude-context.md
claude -p "Read .claude-context.md for priorities. Work through them in order."
rm .claude-context.md
使用 --allowedTools 限制:
# Read-only analysis pass
claude -p --allowedTools "Read,Grep,Glob" "Audit this codebase for security vulnerabilities..."
# Write-only implementation pass
claude -p --allowedTools "Read,Write,Edit,Bash" "Implement the fixes from security-audit.md..."
ECC 内置的持久循环。 一个具有会话感知的 REPL,它使用完整的对话历史同步调用 claude -p。
# Start the default session
node scripts/claw.js
# Named session with skill context
CLAW_SESSION=my-project CLAW_SKILLS=tdd-workflow,security-review node scripts/claw.js
~/.claude/claw/{session}.md 加载对话历史claude -p| 用例 | NanoClaw | 顺序管道 |
|---|---|---|
| 交互式探索 | 是 | 否 |
| 脚本化自动化 | 否 | 是 |
| 会话持久性 | 内置 | 手动 |
| 上下文累积 | 每轮增长 | 每个步骤都是新的 |
| CI/CD 集成 | 差 | 优秀 |
有关完整详情,请参阅 /claw 命令文档。
一个双提示系统,用于编排并行子智能体以进行规范驱动的生成。由 disler 开发(致谢:@disler)。
PROMPT 1(协调器) PROMPT 2(子代理)
┌─────────────────────┐ ┌──────────────────────┐
│ 解析规范文件 │ │ 接收完整上下文 │
│ 扫描输出目录 │ 部署 │ 读取分配编号 │
…
通过双评审智能体对结果进行对抗式校验,提升输出发布前的可靠性
通过多智能体并行协作完成编码规划、执行调度与进度监控。