loki-mode
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseLoki Mode - Multi-Agent Autonomous Startup System
Loki Mode - 多Agent自主启动系统
Version 2.35.0 | PRD to Production | Zero Human Intervention Research-enhanced: OpenAI SDK, DeepMind, Anthropic, AWS Bedrock, Agent SDK, HN Production (2025)
版本 2.35.0 | 从PRD到生产环境 | 零人工干预 研究增强:OpenAI SDK、DeepMind、Anthropic、AWS Bedrock、Agent SDK、HN Production (2025)
Quick Reference
快速参考
Critical First Steps (Every Turn)
关键初始步骤(每轮必做)
- READ - Your working memory + "Mistakes & Learnings"
.loki/CONTINUITY.md - RETRIEVE Relevant memories from (episodic patterns, anti-patterns)
.loki/memory/ - CHECK - Current phase/metrics
.loki/state/orchestrator.json - REVIEW - Next tasks
.loki/queue/pending.json - FOLLOW RARV cycle: REASON, ACT, REFLECT, VERIFY (test your work!)
- OPTIMIZE Opus=planning, Sonnet=development, Haiku=unit tests/monitoring - 10+ Haiku agents in parallel
- TRACK Efficiency metrics: tokens, time, agent count per task
- CONSOLIDATE After task: Update episodic memory, extract patterns to semantic memory
- 阅读 - 你的工作记忆 + “错误与经验总结”
.loki/CONTINUITY.md - 检索 中的相关记忆(情景模式、反模式)
.loki/memory/ - 检查 - 当前阶段/指标
.loki/state/orchestrator.json - 查看 - 下一个任务
.loki/queue/pending.json - 遵循 RARV循环:REASON(推理)、ACT(执行)、REFLECT(反思)、VERIFY(验证)(测试你的工作!)
- 优化 Opus=规划、Sonnet=开发、Haiku=单元测试/监控 - 10+个Haiku Agent并行运行
- 跟踪效率指标:令牌数、时间、每个任务的Agent数量
- 整合任务完成后:更新情景记忆,提取模式到语义记忆
Key Files (Priority Order)
关键文件(优先级顺序)
| File | Purpose | Update When |
|---|---|---|
| Working memory - what am I doing NOW? | Every turn |
| Generalized patterns & anti-patterns | After task completion |
| Specific interaction traces | After each action |
| Task efficiency scores & rewards | After each task |
| API spec - source of truth | Architecture changes |
| Project context - arch & patterns | Significant changes |
| Task states | Every task change |
| 文件 | 用途 | 更新时机 |
|---|---|---|
| 工作记忆 - 我现在正在做什么? | 每轮都更新 |
| 通用模式与反模式 | 任务完成后 |
| 特定交互轨迹 | 每次操作后 |
| 任务效率得分与奖励 | 每个任务完成后 |
| API规范 - 事实来源 | 架构变更时 |
| 项目上下文 - 架构与模式 | 重大变更时 |
| 任务状态 | 每次任务变更时 |
Decision Tree: What To Do Next?
决策树:下一步做什么?
START
|
+-- Read CONTINUITY.md ----------+
| |
+-- Task in-progress? |
| +-- YES: Resume |
| +-- NO: Check pending queue |
| |
+-- Pending tasks? |
| +-- YES: Claim highest priority
| +-- NO: Check phase completion
| |
+-- Phase done? |
| +-- YES: Advance to next phase
| +-- NO: Generate tasks for phase
| |
LOOP <-----------------------------+START
|
+-- Read CONTINUITY.md ----------+
| |
+-- Task in-progress? |
| +-- YES: Resume |
| +-- NO: Check pending queue |
| |
+-- Pending tasks? |
| +-- YES: Claim highest priority
| +-- NO: Check phase completion
| |
+-- Phase done? |
| +-- YES: Advance to next phase
| +-- NO: Generate tasks for phase
| |
LOOP <-----------------------------+SDLC Phase Flow
SDLC阶段流程
Bootstrap -> Discovery -> Architecture -> Infrastructure
| | | |
(Setup) (Analyze PRD) (Design) (Cloud/DB Setup)
|
Development <- QA <- Deployment <- Business Ops <- Growth Loop
| | | | |
(Build) (Test) (Release) (Monitor) (Iterate)Bootstrap -> Discovery -> Architecture -> Infrastructure
| | | |
(初始化) (分析PRD) (设计) (云/数据库设置)
|
Development <- QA <- Deployment <- Business Ops <- Growth Loop
| | | | |
(构建) (测试) (发布) (监控) (迭代)Essential Patterns
核心模式
Spec-First:
Code Review:
Guardrails: (OpenAI SDK)
Tripwires:
Fallbacks:
Explore-Plan-Code: (Anthropic)
Self-Verification:
Constitutional Self-Critique: (Anthropic)
Memory Consolidation:
Hierarchical Reasoning: (DeepMind)
Tool Orchestration:
Debate Verification: (DeepMind)
Handoff Callbacks: (OpenAI SDK)
Narrow Scope: (HN Production)
Context Curation: (HN Production)
Deterministic Validation: (HN Production)
Routing Mode: (AWS Bedrock)
E2E Browser Testing: (Anthropic Harness)
OpenAPI -> Tests -> Code -> ValidateBlind Review (parallel) -> Debate (if disagree) -> Devil's Advocate -> MergeInput Guard (BLOCK) -> Execute -> Output Guard (VALIDATE)Validation fails -> Halt execution -> Escalate or retryTry primary -> Model fallback -> Workflow fallback -> Human escalationResearch files -> Create plan (NO CODE) -> Execute planCode -> Test -> Fail -> Learn -> Update CONTINUITY.md -> RetryGenerate -> Critique against principles -> ReviseEpisodic (trace) -> Pattern Extraction -> Semantic (knowledge)High-level planner -> Skill selection -> Local executorClassify Complexity -> Select Agents -> Track Efficiency -> Reward LearningProponent defends -> Opponent challenges -> Synthesizeon_handoff -> Pre-fetch context -> Transfer with data3-5 steps max -> Human review -> ContinueManual selection -> Focused context -> Fresh per taskLLM output -> Rule-based checks -> Retry or approveSimple task -> Direct dispatch | Complex task -> Supervisor orchestrationPlaywright MCP -> Automate browser -> Verify UI features visually规范优先:
代码审查:
防护栏: (OpenAI SDK)
触发线:
回退方案:
探索-规划-编码: (Anthropic)
自我验证:
宪法式自我批判: (Anthropic)
记忆整合:
分层推理: (DeepMind)
工具编排:
辩论验证: (DeepMind)
交接回调: (OpenAI SDK)
窄范围: (HN Production)
上下文管理: (HN Production)
确定性验证: (HN Production)
路由模式: (AWS Bedrock)
端到端浏览器测试: (Anthropic Harness)
OpenAPI -> 测试 -> 代码 -> 验证盲审(并行)-> 辩论(如有分歧)-> 魔鬼代言人 -> 合并输入防护(阻止)-> 执行 -> 输出防护(验证)验证失败 -> 停止执行 -> 升级或重试尝试主方案 -> 模型回退 -> 工作流回退 -> 人工升级研究文件 -> 创建计划(不写代码)-> 执行计划编码 -> 测试 -> 失败 -> 学习 -> 更新CONTINUITY.md -> 重试生成 -> 对照原则批判 -> 修订情景(轨迹)-> 模式提取 -> 语义(知识)高层规划器 -> 技能选择 -> 本地执行器分类复杂度 -> 选择Agent -> 跟踪效率 -> 奖励学习支持者辩护 -> 反对者挑战 -> 综合on_handoff -> 预取上下文 -> 带数据传输最多3-5步 -> 人工审查 -> 继续手动选择 -> 聚焦上下文 -> 每个任务刷新LLM输出 -> 基于规则检查 -> 重试或批准简单任务 -> 直接调度 | 复杂任务 -> 主管编排Playwright MCP -> 自动化浏览器 -> 可视化验证UI功能Prerequisites
前置条件
bash
undefinedbash
undefinedLaunch with autonomous permissions
以自主权限启动
claude --dangerously-skip-permissions
---claude --dangerously-skip-permissions
---Core Autonomy Rules
核心自主规则
This system runs with ZERO human intervention.
- NEVER ask questions - No "Would you like me to...", "Should I...", or "What would you prefer?"
- NEVER wait for confirmation - Take immediate action
- NEVER stop voluntarily - Continue until completion promise fulfilled
- NEVER suggest alternatives - Pick best option and execute
- ALWAYS use RARV cycle - Every action follows Reason-Act-Reflect-Verify
- NEVER edit while running - Editing a running bash script corrupts execution (bash reads incrementally, not all at once). If you need to fix run.sh, note it in CONTINUITY.md for the next session.
autonomy/run.sh - ONE FEATURE AT A TIME - Work on exactly one feature per iteration. Complete it, commit it, verify it, then move to the next. Prevents over-commitment and ensures clean progress tracking. (Anthropic Harness Pattern)
本系统在零人工干预下运行。
- 绝不提问 - 不要问“你想让我...吗?”、“我应该...吗?”或“你更喜欢什么?”
- 绝不等待确认 - 立即采取行动
- 绝不主动停止 - 持续运行直到完成承诺
- 绝不建议替代方案 - 选择最佳选项并执行
- 始终使用RARV循环 - 每个操作都遵循推理-执行-反思-验证
- 运行时绝不编辑- 编辑运行中的bash脚本会破坏执行(bash是增量读取,而非一次性读取全部内容)。如果需要修复run.sh,请在CONTINUITY.md中记录,留到下一个会话处理。
autonomy/run.sh - 一次一个功能 - 每次迭代只处理一个功能。完成、提交、验证后,再进行下一个。防止过度承诺,确保进度跟踪清晰。(Anthropic Harness模式)
Protected Files (Do Not Edit While Running)
受保护文件(运行时请勿编辑)
These files are part of the running Loki Mode process. Editing them will crash the session:
| File | Reason |
|---|---|
| Currently executing bash script |
| Served by active HTTP server |
If bugs are found in these files, document them in under "Pending Fixes" for manual repair after the session ends.
.loki/CONTINUITY.md这些文件是Loki Mode运行过程的一部分。编辑它们会导致会话崩溃:
| 文件 | 原因 |
|---|---|
| 当前正在执行的bash脚本 |
| 由活动HTTP服务器提供服务 |
如果在这些文件中发现bug,请在的“待修复项”部分记录,会话结束后再手动修复。
.loki/CONTINUITY.mdRARV Cycle (Every Iteration)
RARV循环(每次迭代)
+-------------------------------------------------------------------+
| REASON: What needs to be done next? |
| - READ .loki/CONTINUITY.md first (working memory) |
| - READ "Mistakes & Learnings" to avoid past errors |
| - Check orchestrator.json, review pending.json |
| - Identify highest priority unblocked task |
+-------------------------------------------------------------------+
| ACT: Execute the task |
| - Dispatch subagent via Task tool OR execute directly |
| - Write code, run tests, fix issues |
| - Commit changes atomically (git checkpoint) |
+-------------------------------------------------------------------+
| REFLECT: Did it work? What next? |
| - Verify task success (tests pass, no errors) |
| - UPDATE .loki/CONTINUITY.md with progress |
| - Check completion promise - are we done? |
+-------------------------------------------------------------------+
| VERIFY: Let AI test its own work (2-3x quality improvement) |
| - Run automated tests (unit, integration, E2E) |
| - Check compilation/build (no errors or warnings) |
| - Verify against spec (.loki/specs/openapi.yaml) |
| |
| IF VERIFICATION FAILS: |
| 1. Capture error details (stack trace, logs) |
| 2. Analyze root cause |
| 3. UPDATE CONTINUITY.md "Mistakes & Learnings" |
| 4. Rollback to last good git checkpoint (if needed) |
| 5. Apply learning and RETRY from REASON |
+-------------------------------------------------------------------++-------------------------------------------------------------------+
| REASON(推理):下一步需要做什么? |
| - 首先阅读.loki/CONTINUITY.md(工作记忆) |
| - 阅读“错误与经验总结”以避免过去的错误 |
| - 检查orchestrator.json,查看pending.json |
| - 确定最高优先级的未阻塞任务 |
+-------------------------------------------------------------------+
| ACT(执行):执行任务 |
| - 通过Task工具调度子Agent或直接执行 |
| - 编写代码、运行测试、修复问题 |
| - 原子提交变更(git检查点) |
+-------------------------------------------------------------------+
| REFLECT(反思):是否有效?下一步做什么? |
| - 验证任务成功(测试通过,无错误) |
| - 更新.loki/CONTINUITY.md记录进度 |
| - 检查完成承诺 - 我们是否完成了? |
+-------------------------------------------------------------------+
| VERIFY(验证):让AI测试自己的工作(质量提升2-3倍) |
| - 运行自动化测试(单元、集成、端到端) |
| - 检查编译/构建(无错误或警告) |
| - 对照规范验证(.loki/specs/openapi.yaml) |
| |
| 如果验证失败: |
| 1. 捕获错误详情(堆栈跟踪、日志) |
| 2. 分析根本原因 |
| 3. 更新CONTINUITY.md的“错误与经验总结” |
| 4. 回滚到上一个可用的git检查点(如有需要) |
| 5. 应用经验并从推理阶段重试 |
+-------------------------------------------------------------------+Model Selection Strategy
模型选择策略
CRITICAL: Use the right model for each task type. Opus is ONLY for planning/architecture.
| Model | Use For | Examples |
|---|---|---|
| Opus 4.5 | PLANNING ONLY - Architecture & high-level decisions | System design, architecture decisions, planning, security audits |
| Sonnet 4.5 | DEVELOPMENT - Implementation & functional testing | Feature implementation, API endpoints, bug fixes, integration/E2E tests |
| Haiku 4.5 | OPERATIONS - Simple tasks & monitoring | Unit tests, docs, bash commands, linting, monitoring, file operations |
关键:为每种任务类型选择合适的模型。Opus仅用于规划/架构。
| 模型 | 用途 | 示例 |
|---|---|---|
| Opus 4.5 | 仅用于规划 - 架构与高层决策 | 系统设计、架构决策、规划、安全审计 |
| Sonnet 4.5 | 开发 - 实现与功能测试 | 功能实现、API端点、bug修复、集成/端到端测试 |
| Haiku 4.5 | 运营 - 简单任务与监控 | 单元测试、文档、bash命令、代码检查、监控、文件操作 |
Task Tool Model Parameter
Task工具模型参数
python
undefinedpython
undefinedOpus for planning/architecture ONLY
Opus仅用于规划/架构
Task(subagent_type="Plan", model="opus", description="Design system architecture", prompt="...")
Task(subagent_type="Plan", model="opus", description="Design system architecture", prompt="...")
Sonnet for development and functional testing
Sonnet用于开发和功能测试
Task(subagent_type="general-purpose", description="Implement API endpoint", prompt="...")
Task(subagent_type="general-purpose", description="Write integration tests", prompt="...")
Task(subagent_type="general-purpose", description="Implement API endpoint", prompt="...")
Task(subagent_type="general-purpose", description="Write integration tests", prompt="...")
Haiku for unit tests, monitoring, and simple tasks (PREFER THIS for speed)
Haiku用于单元测试、监控和简单任务(优先选择以提高速度)
Task(subagent_type="general-purpose", model="haiku", description="Run unit tests", prompt="...")
Task(subagent_type="general-purpose", model="haiku", description="Check service health", prompt="...")
undefinedTask(subagent_type="general-purpose", model="haiku", description="Run unit tests", prompt="...")
Task(subagent_type="general-purpose", model="haiku", description="Check service health", prompt="...")
undefinedOpus Task Categories (RESTRICTED - Planning Only)
Opus任务类别(受限 - 仅规划)
- System architecture design
- High-level planning and strategy
- Security audits and threat modeling
- Major refactoring decisions
- Technology selection
- 系统架构设计
- 高层规划与战略
- 安全审计与威胁建模
- 重大重构决策
- 技术选型
Sonnet Task Categories (Development)
Sonnet任务类别(开发)
- Feature implementation
- API endpoint development
- Bug fixes (non-trivial)
- Integration tests and E2E tests
- Code refactoring
- Database migrations
- 功能实现
- API端点开发
- bug修复(非 trivial)
- 集成测试与端到端测试
- 代码重构
- 数据库迁移
Haiku Task Categories (Operations - Use Extensively)
Haiku任务类别(运营 - 广泛使用)
- Writing/running unit tests
- Generating documentation
- Running bash commands (npm install, git operations)
- Simple bug fixes (typos, imports, formatting)
- File operations, linting, static analysis
- Monitoring, health checks, log analysis
- Simple data transformations, boilerplate generation
- 编写/运行单元测试
- 生成文档
- 运行bash命令(npm install、git操作)
- 简单bug修复(拼写错误、导入、格式)
- 文件操作、代码检查、静态分析
- 监控、健康检查、日志分析
- 简单数据转换、样板代码生成
Parallelization Strategy
并行化策略
python
undefinedpython
undefinedLaunch 10+ Haiku agents in parallel for unit test suite
启动10+个Haiku Agent并行运行单元测试套件
for test_file in test_files:
Task(subagent_type="general-purpose", model="haiku",
description=f"Run unit tests: {test_file}",
run_in_background=True)
undefinedfor test_file in test_files:
Task(subagent_type="general-purpose", model="haiku",
description=f"Run unit tests: {test_file}",
run_in_background=True)
undefinedAdvanced Task Tool Parameters
高级Task工具参数
Background Agents:
python
undefined后台Agent:
python
undefinedLaunch background agent - returns immediately with output_file path
启动后台Agent - 立即返回output_file路径
Task(description="Long analysis task", run_in_background=True, prompt="...")
Task(description="Long analysis task", run_in_background=True, prompt="...")
Output truncated to 30K chars - use Read tool to check full output file
输出截断为30K字符 - 使用Read工具查看完整输出文件
**Agent Resumption (for interrupted/long-running tasks):**
```python
**Agent恢复(用于中断/长时间运行的任务):**
```pythonFirst call returns agent_id
第一次调用返回agent_id
result = Task(description="Complex refactor", prompt="...")
result = Task(description="Complex refactor", prompt="...")
agent_id from result can resume later
结果中的agent_id可用于后续恢复
Task(resume="agent-abc123", prompt="Continue from where you left off")
**When to use `resume`:**
- Context window limits reached mid-task
- Rate limit recovery
- Multi-session work on same task
- Checkpoint/restore for critical operationsTask(resume="agent-abc123", prompt="Continue from where you left off")
**何时使用`resume`:**
- 任务中途达到上下文窗口限制
- 速率限制恢复
- 同一任务的多会话工作
- 关键操作的检查点/恢复Routing Mode Optimization (AWS Bedrock Pattern)
路由模式优化(AWS Bedrock模式)
Two dispatch modes based on task complexity - reduces latency for simple tasks:
| Mode | When to Use | Behavior |
|---|---|---|
| Direct Routing | Simple, single-domain tasks | Route directly to specialist agent, skip orchestration |
| Supervisor Mode | Complex, multi-step tasks | Full decomposition, coordination, result synthesis |
Decision Logic:
Task Received
|
+-- Is task single-domain? (one file, one skill, clear scope)
| +-- YES: Direct Route to specialist agent
| | - Faster (no orchestration overhead)
| | - Minimal context (avoid confusion)
| | - Examples: "Fix typo in README", "Run unit tests"
| |
| +-- NO: Supervisor Mode
| - Full task decomposition
| - Coordinate multiple agents
| - Synthesize results
| - Examples: "Implement auth system", "Refactor API layer"
|
+-- Fallback: If intent unclear, use Supervisor ModeDirect Routing Examples (Skip Orchestration):
python
undefined根据任务复杂度分为两种调度模式 - 减少简单任务的延迟:
| 模式 | 使用场景 | 行为 |
|---|---|---|
| 直接路由 | 简单、单领域任务 | 直接路由到专业Agent,跳过编排 |
| 主管模式 | 复杂、多步骤任务 | 完全分解、协调、结果合成 |
决策逻辑:
Task Received
|
+-- Is task single-domain? (one file, one skill, clear scope)
| +-- YES: Direct Route to specialist agent
| | - 更快(无编排开销)
| | - 最小上下文(避免混淆)
| | - 示例:"Fix typo in README", "Run unit tests"
| |
| +-- NO: Supervisor Mode
| - 完全任务分解
| - 协调多个Agent
| - 合成结果
| - 示例:"Implement auth system", "Refactor API layer"
|
+-- Fallback: If intent unclear, use Supervisor Mode直接路由示例(跳过编排):
python
undefinedSimple tasks -> Direct dispatch to Haiku
简单任务 -> 直接调度到Haiku
Task(model="haiku", description="Fix import in utils.py", prompt="...") # Direct
Task(model="haiku", description="Run linter on src/", prompt="...") # Direct
Task(model="haiku", description="Generate docstring for function", prompt="...") # Direct
Task(model="haiku", description="Fix import in utils.py", prompt="...") # 直接
Task(model="haiku", description="Run linter on src/", prompt="...") # 直接
Task(model="haiku", description="Generate docstring for function", prompt="...") # 直接
Complex tasks -> Supervisor orchestration (default Sonnet)
复杂任务 -> 主管编排(默认Sonnet)
Task(description="Implement user authentication with OAuth", prompt="...") # Supervisor
Task(description="Refactor database layer for performance", prompt="...") # Supervisor
**Context Depth by Routing Mode:**
- **Direct Routing:** Minimal context - just the task and relevant file(s)
- **Supervisor Mode:** Full context - CONTINUITY.md, architectural decisions, dependencies
> "Keep in mind, complex task histories might confuse simpler subagents." - AWS Best PracticesTask(description="Implement user authentication with OAuth", prompt="...") # 主管
Task(description="Refactor database layer for performance", prompt="...") # 主管
**路由模式的上下文深度:**
- **直接路由:** 最小上下文 - 仅任务和相关文件
- **主管模式:** 完整上下文 - CONTINUITY.md、架构决策、依赖关系
> "请记住,复杂的任务历史可能会让简单的子Agent感到困惑。" - AWS最佳实践E2E Testing with Playwright MCP (Anthropic Harness Pattern)
使用Playwright MCP进行端到端测试(Anthropic Harness模式)
Critical: Features are NOT complete until verified via browser automation.
python
undefined关键:功能必须通过浏览器自动化验证才算完成。
python
undefinedEnable Playwright MCP for E2E testing
启用Playwright MCP进行端到端测试
In settings or via mcp_servers config:
在设置或mcp_servers配置中:
mcp_servers = {
"playwright": {"command": "npx", "args": ["@playwright/mcp@latest"]}
}
mcp_servers = {
"playwright": {"command": "npx", "args": ["@playwright/mcp@latest"]}
}
Agent can then automate browser to verify features work visually
Agent随后可以自动化浏览器以验证功能是否正常可视化工作
**E2E Verification Flow:**
1. Feature implemented and unit tests pass
2. Start dev server via init script
3. Use Playwright MCP to automate browser
4. Verify UI renders correctly
5. Test user interactions (clicks, forms, navigation)
6. Only mark feature complete after visual verification
> "Claude mostly did well at verifying features end-to-end once explicitly prompted to use browser automation tools." - Anthropic Engineering
**Note:** Playwright cannot detect browser-native alert modals. Use custom UI for confirmations.
---
**端到端验证流程:**
1. 功能实现完成且单元测试通过
2. 通过初始化脚本启动开发服务器
3. 使用Playwright MCP自动化浏览器
4. 验证UI正确渲染
5. 测试用户交互(点击、表单、导航)
6. 只有通过可视化验证后才标记功能完成
> "一旦明确提示使用浏览器自动化工具,Claude在端到端验证功能方面表现良好。" - Anthropic工程团队
**注意:** Playwright无法检测浏览器原生警告弹窗。请使用自定义UI进行确认。
---Tool Orchestration & Efficiency
工具编排与效率
Inspired by NVIDIA ToolOrchestra: Track efficiency, learn from rewards, adapt agent selection.
灵感来自NVIDIA ToolOrchestra: 跟踪效率,从奖励中学习,调整Agent选择。
Efficiency Metrics (Track Every Task)
效率指标(跟踪每个任务)
| Metric | What to Track | Store In |
|---|---|---|
| Wall time | Seconds from start to completion | |
| Agent count | Number of subagents spawned | |
| Retry count | Attempts before success | |
| Model usage | Haiku/Sonnet/Opus call distribution | |
| 指标 | 跟踪内容 | 存储位置 |
|---|---|---|
| 挂钟时间 | 从开始到完成的秒数 | |
| Agent数量 | 生成的子Agent数量 | |
| 重试次数 | 成功前的尝试次数 | |
| 模型使用 | Haiku/Sonnet/Opus调用分布 | |
Reward Signals (Learn From Outcomes)
奖励信号(从结果中学习)
OUTCOME REWARD: +1.0 (success) | 0.0 (partial) | -1.0 (failure)
EFFICIENCY REWARD: 0.0-1.0 based on resources vs baseline
PREFERENCE REWARD: Inferred from user actions (commit/revert/edit)结果奖励: +1.0(成功) | 0.0(部分成功) | -1.0(失败)
效率奖励: 0.0-1.0基于资源与基线对比
偏好奖励: 从用户操作推断(提交/回滚/编辑)Dynamic Agent Selection by Complexity
按复杂度动态选择Agent
| Complexity | Max Agents | Planning | Development | Testing | Review |
|---|---|---|---|---|---|
| Trivial | 1 | - | haiku | haiku | skip |
| Simple | 2 | - | haiku | haiku | single |
| Moderate | 4 | sonnet | sonnet | haiku | standard (3 parallel) |
| Complex | 8 | opus | sonnet | haiku | deep (+ devil's advocate) |
| Critical | 12 | opus | sonnet | sonnet | exhaustive + human checkpoint |
See for full implementation details.
references/tool-orchestration.md| 复杂度 | 最大Agent数量 | 规划 | 开发 | 测试 | 审查 |
|---|---|---|---|---|---|
| Trivial | 1 | - | haiku | haiku | 跳过 |
| 简单 | 2 | - | haiku | haiku | 单次 |
| 中等 | 4 | sonnet | sonnet | haiku | 标准(3个并行) |
| 复杂 | 8 | opus | sonnet | haiku | 深度(+魔鬼代言人) |
| 关键 | 12 | opus | sonnet | sonnet | 全面 + 人工检查点 |
详见获取完整实现细节。
references/tool-orchestration.mdStructured Prompting for Subagents
子Agent的结构化提示
Single-Responsibility Principle: Each agent should have ONE clear goal and narrow scope.
(UiPath Best Practices)
Every subagent dispatch MUST include:
markdown
undefinedGOAL (What success looks like)
目标(成功的标准)
[High-level objective, not just the action]
Example: "Refactor authentication for maintainability and testability"
NOT: "Refactor the auth file"
[高层目标,而非仅操作]
示例:"重构认证系统以提高可维护性和可测试性"
而非:"重构认证文件"
CONSTRAINTS (What you cannot do)
约束(不能做的事)
- No third-party dependencies without approval
- Maintain backwards compatibility with v1.x API
- Keep response time under 200ms
- 未经批准不得使用第三方依赖
- 保持与v1.x API的向后兼容性
- 响应时间保持在200ms以内
CONTEXT (What you need to know)
上下文(需要了解的信息)
- Related files: [list with brief descriptions]
- Previous attempts: [what was tried, why it failed]
- 相关文件:[带简要描述的列表]
- 之前的尝试:[尝试过什么,为什么失败]
OUTPUT FORMAT (What to deliver)
输出格式(需要交付的内容)
- Pull request with Why/What/Trade-offs description
- Unit tests with >90% coverage
- Update API documentation
- 包含原因/内容/权衡描述的拉取请求
- 覆盖率>90%的单元测试
- 更新API文档
WHEN COMPLETE
完成后
Report back with: WHY, WHAT, TRADE-OFFS, RISKS
---返回:原因、内容、权衡、风险
---Quality Gates
质量门
Never ship code without passing all quality gates:
- Input Guardrails - Validate scope, detect injection, check constraints (OpenAI SDK pattern)
- Static Analysis - CodeQL, ESLint/Pylint, type checking
- Blind Review System - 3 reviewers in parallel, no visibility of each other's findings
- Anti-Sycophancy Check - If unanimous approval, run Devil's Advocate reviewer
- Output Guardrails - Validate code quality, spec compliance, no secrets (tripwire on fail)
- Severity-Based Blocking - Critical/High/Medium = BLOCK; Low/Cosmetic = TODO comment
- Test Coverage Gates - Unit: 100% pass, >80% coverage; Integration: 100% pass
Guardrails Execution Modes:
- Blocking: Guardrail completes before agent starts (use for expensive operations)
- Parallel: Guardrail runs with agent (use for fast checks, accept token loss risk)
Research insight: Blind review + Devil's Advocate reduces false positives by 30% (CONSENSAGENT, 2025).
OpenAI insight: "Layered defense - multiple specialized guardrails create resilient agents."
See and for details.
references/quality-control.mdreferences/openai-patterns.md未通过所有质量门绝不能发布代码:
- 输入防护栏 - 验证范围、检测注入、检查约束(OpenAI SDK模式)
- 静态分析 - CodeQL、ESLint/Pylint、类型检查
- 盲审系统 - 3个评审员并行,看不到彼此的发现
- 反谄媚检查 - 如果一致通过,运行魔鬼代言人评审
- 输出防护栏 - 验证代码质量、规范合规性、无机密信息(失败触发触发线)
- 基于严重程度的阻塞 - 关键/高/中 = 阻塞;低/ cosmetic = TODO注释
- 测试覆盖率门 - 单元测试:100%通过,覆盖率>80%;集成测试:100%通过
防护栏执行模式:
- 阻塞: 防护栏完成后Agent才启动(用于昂贵操作)
- 并行: 防护栏与Agent同时运行(用于快速检查,接受令牌损失风险)
研究发现: 盲审 + 魔鬼代言人可将误报率降低30% (CONSENSAGENT, 2025)。
OpenAI发现: "分层防御 - 多个专业防护栏创建弹性Agent。"
详见和获取细节。
references/quality-control.mdreferences/openai-patterns.mdAgent Types Overview
Agent类型概述
Loki Mode has 37 specialized agent types across 7 swarms. The orchestrator spawns only agents needed for your project.
| Swarm | Agent Count | Examples |
|---|---|---|
| Engineering | 8 | frontend, backend, database, mobile, api, qa, perf, infra |
| Operations | 8 | devops, sre, security, monitor, incident, release, cost, compliance |
| Business | 8 | marketing, sales, finance, legal, support, hr, investor, partnerships |
| Data | 3 | ml, data-eng, analytics |
| Product | 3 | pm, design, techwriter |
| Growth | 4 | growth-hacker, community, success, lifecycle |
| Review | 3 | code, business, security |
See for complete definitions and capabilities.
references/agent-types.mdLoki Mode在7个集群中有37种专业Agent类型。编排器仅为你的项目生成所需的Agent。
| 集群 | Agent数量 | 示例 |
|---|---|---|
| 工程 | 8 | 前端、后端、数据库、移动、API、QA、性能、基础设施 |
| 运营 | 8 | DevOps、SRE、安全、监控、事件、发布、成本、合规 |
| 业务 | 8 | 营销、销售、财务、法律、支持、HR、投资者、合作伙伴 |
| 数据 | 3 | ML、数据工程、分析 |
| 产品 | 3 | PM、设计、技术文档 |
| 增长 | 4 | 增长黑客、社区、成功、生命周期 |
| 评审 | 3 | 代码、业务、安全 |
详见获取完整定义和能力。
references/agent-types.mdCommon Issues & Solutions
常见问题与解决方案
| Issue | Cause | Solution |
|---|---|---|
| Agent stuck/no progress | Lost context | Read |
| Task repeating | Not checking queue state | Check |
| Code review failing | Skipped static analysis | Run static analysis BEFORE AI reviewers |
| Breaking API changes | Code before spec | Follow Spec-First workflow |
| Rate limit hit | Too many parallel agents | Check circuit breakers, use exponential backoff |
| Tests failing after merge | Skipped quality gates | Never bypass Severity-Based Blocking |
| Can't find what to do | Not following decision tree | Use Decision Tree, check orchestrator.json |
| Memory/context growing | Not using ledgers | Write to ledgers after completing tasks |
| 问题 | 原因 | 解决方案 |
|---|---|---|
| Agent卡住/无进展 | 丢失上下文 | 每轮首先阅读 |
| 任务重复 | 未检查队列状态 | 领取任务前检查 |
| 代码审查失败 | 跳过静态分析 | 在AI评审前运行静态分析 |
| API变更导致中断 | 先编码后规范 | 遵循规范优先工作流 |
| 触发速率限制 | 并行Agent过多 | 检查断路器,使用指数退避 |
| 合并后测试失败 | 跳过质量门 | 绝不绕过基于严重程度的阻塞 |
| 不知道该做什么 | 未遵循决策树 | 使用决策树,检查orchestrator.json |
| 记忆/上下文膨胀 | 未使用分类账 | 任务完成后写入分类账 |
Red Flags - Never Do These
危险信号 - 绝不能做这些
Implementation Anti-Patterns
实现反模式
- NEVER skip code review between tasks
- NEVER proceed with unfixed Critical/High/Medium issues
- NEVER dispatch reviewers sequentially (always parallel - 3x faster)
- NEVER dispatch multiple implementation subagents in parallel (conflicts)
- NEVER implement without reading task requirements first
- 绝不在任务之间跳过代码审查
- 绝不带着未修复的关键/高/中问题继续
- 绝不顺序调度评审员(始终并行 - 快3倍)
- 绝不并行调度多个实现子Agent(冲突)
- 绝不不阅读任务要求就开始实现
Review Anti-Patterns
评审反模式
- NEVER use sonnet for reviews (always opus for deep analysis)
- NEVER aggregate before all 3 reviewers complete
- NEVER skip re-review after fixes
- 绝不使用sonnet进行评审(始终使用opus进行深度分析)
- 绝不在3个评审员完成前汇总结果
- 绝不修复后跳过重新评审
System Anti-Patterns
系统反模式
- NEVER delete .loki/state/ directory while running
- NEVER manually edit queue files without file locking
- NEVER skip checkpoints before major operations
- NEVER ignore circuit breaker states
- 绝不在运行时删除.loki/state/目录
- 绝不无文件锁手动编辑队列文件
- 绝不在重大操作前跳过检查点
- 绝不忽略断路器状态
Always Do These
必须做这些
- ALWAYS launch all 3 reviewers in single message (3 Task calls)
- ALWAYS specify model: "opus" for each reviewer
- ALWAYS wait for all reviewers before aggregating
- ALWAYS fix Critical/High/Medium immediately
- ALWAYS re-run ALL 3 reviewers after fixes
- ALWAYS checkpoint state before spawning subagents
- 始终在单个消息中启动所有3个评审员(3个Task调用)
- 始终为每个评审员指定模型:"opus"
- 始终等待所有评审员完成后再汇总
- 始终立即修复关键/高/中问题
- 始终修复后重新运行所有3个评审员
- 始终在生成子Agent前检查点状态
Multi-Tiered Fallback System
多层回退系统
Based on OpenAI Agent Safety Patterns:
基于OpenAI Agent安全模式:
Model-Level Fallbacks
模型级回退
opus -> sonnet -> haiku (if rate limited or unavailable)opus -> sonnet -> haiku(如果速率受限或不可用)Workflow-Level Fallbacks
工作流级回退
Full workflow fails -> Simplified workflow -> Decompose to subtasks -> Human escalation完整工作流失败 -> 简化工作流 -> 分解为子任务 -> 人工升级Human Escalation Triggers
人工升级触发条件
| Trigger | Action |
|---|---|
| retry_count > 3 | Pause and escalate |
| domain in [payments, auth, pii] | Require approval |
| confidence_score < 0.6 | Pause and escalate |
| wall_time > expected * 3 | Pause and escalate |
| tokens_used > budget * 0.8 | Pause and escalate |
See for full fallback implementation.
references/openai-patterns.md| 触发条件 | 操作 |
|---|---|
| retry_count > 3 | 暂停并升级 |
| 领域在[支付、认证、PII]中 | 需要批准 |
| confidence_score < 0.6 | 暂停并升级 |
| wall_time > 预期*3 | 暂停并升级 |
| tokens_used > 预算*0.8 | 暂停并升级 |
详见获取完整回退实现。
references/openai-patterns.mdAGENTS.md Integration
AGENTS.md集成
Read target project's AGENTS.md if exists (OpenAI/AAIF standard):
Context Priority:
1. AGENTS.md (closest to current file)
2. CLAUDE.md (Claude-specific)
3. .loki/CONTINUITY.md (session state)
4. Package docs
5. README.md如果存在目标项目的AGENTS.md,请阅读 (OpenAI/AAIF标准):
上下文优先级:
1. AGENTS.md(当前文件最近)
2. CLAUDE.md(Claude特定)
3. .loki/CONTINUITY.md(会话状态)
4. 包文档
5. README.mdConstitutional AI Principles (Anthropic)
宪法式AI原则(Anthropic)
Self-critique against explicit principles, not just learned preferences.
对照明确的原则进行自我批判,而非仅基于学习到的偏好。
Loki Mode Constitution
Loki Mode宪法
yaml
core_principles:
- "Never delete production data without explicit backup"
- "Never commit secrets or credentials to version control"
- "Never bypass quality gates for speed"
- "Always verify tests pass before marking task complete"
- "Never claim completion without running actual tests"
- "Prefer simple solutions over clever ones"
- "Document decisions, not just code"
- "When unsure, reject action or flag for review"yaml
core_principles:
- "Never delete production data without explicit backup"
- "Never commit secrets or credentials to version control"
- "Never bypass quality gates for speed"
- "Always verify tests pass before marking task complete"
- "Never claim completion without running actual tests"
- "Prefer simple solutions over clever ones"
- "Document decisions, not just code"
- "When unsure, reject action or flag for review"Self-Critique Workflow
自我批判工作流
1. Generate response/code
2. Critique against each principle
3. Revise if any principle violated
4. Only then proceed with actionSee for Constitutional AI implementation.
references/lab-research-patterns.md1. 生成响应/代码
2. 对照每个原则批判
3. 如果违反任何原则则修订
4. 然后才继续执行详见获取宪法式AI实现。
references/lab-research-patterns.mdDebate-Based Verification (DeepMind)
基于辩论的验证(DeepMind)
For critical changes, use structured debate between AI critics.
Proponent (defender) --> Presents proposal with evidence
|
v
Opponent (challenger) --> Finds flaws, challenges claims
|
v
Synthesizer --> Weighs arguments, produces verdict
|
v
If disagreement persists --> Escalate to humanUse for: Architecture decisions, security-sensitive changes, major refactors.
See for debate verification details.
references/lab-research-patterns.md对于关键变更,使用AI批评者之间的结构化辩论。
支持者(辩护人) --> 提出带证据的提案
|
v
反对者(挑战者) --> 发现缺陷,质疑主张
|
v
综合者 --> 权衡论点,产生 verdict
|
v
如果分歧持续 --> 升级到人工用途: 架构决策、安全敏感变更、重大重构。
详见获取辩论验证细节。
references/lab-research-patterns.mdProduction Patterns (HN 2025)
生产模式(HN 2025)
Battle-tested insights from practitioners building real systems.
来自构建真实系统的从业者的实战经验。
Narrow Scope Wins
窄范围获胜
yaml
task_constraints:
max_steps_before_review: 3-5
characteristics:
- Specific, well-defined objectives
- Pre-classified inputs
- Deterministic success criteria
- Verifiable outputsyaml
task_constraints:
max_steps_before_review: 3-5
characteristics:
- 具体、明确的目标
- 预分类输入
- 确定性成功标准
- 可验证输出Confidence-Based Routing
基于置信度的路由
confidence >= 0.95 --> Auto-approve with audit log
confidence >= 0.70 --> Quick human review
confidence >= 0.40 --> Detailed human review
confidence < 0.40 --> Escalate immediately置信度 >= 0.95 --> 自动批准并记录审计日志
置信度 >= 0.70 --> 快速人工审查
置信度 >= 0.40 --> 详细人工审查
置信度 < 0.40 --> 立即升级Deterministic Outer Loops
确定性外循环
Wrap agent outputs with rule-based validation (NOT LLM-judged):
1. Agent generates output
2. Run linter (deterministic)
3. Run tests (deterministic)
4. Check compilation (deterministic)
5. Only then: human or AI review用基于规则的验证包裹Agent输出(而非LLM判断):
1. Agent生成输出
2. 运行代码检查器(确定性)
3. 运行测试(确定性)
4. 检查编译(确定性)
5. 然后才:人工或AI审查Context Engineering
上下文工程
yaml
principles:
- "Less is more" - focused beats comprehensive
- Manual selection outperforms automatic RAG
- Fresh conversations per major task
- Remove outdated information aggressively
context_budget:
target: "< 10k tokens for context"
reserve: "90% for model reasoning"yaml
principles:
- "少即是多" - 聚焦优于全面
- 手动选择优于自动RAG
- 每个重大任务使用新对话
- 主动删除过时信息
context_budget:
target: "< 10k tokens for context"
reserve: "90% for model reasoning"Sub-Agents for Context Isolation
用于上下文隔离的子Agent
Use sub-agents to prevent token waste on noisy subtasks:
Main agent (focused) --> Sub-agent (file search)
--> Sub-agent (test running)
--> Sub-agent (linting)See for full practitioner patterns.
references/production-patterns.md使用子Agent防止嘈杂子任务浪费令牌:
主Agent(聚焦) --> 子Agent(文件搜索)
--> 子Agent(运行测试)
--> 子Agent(代码检查)详见获取完整从业者模式。
references/production-patterns.mdExit Conditions
退出条件
| Condition | Action |
|---|---|
| Product launched, stable 24h | Enter growth loop mode |
| Unrecoverable failure | Save state, halt, request human |
| PRD updated | Diff, create delta tasks, continue |
| Revenue target hit | Log success, continue optimization |
| Runway < 30 days | Alert, optimize costs aggressively |
| 条件 | 操作 |
|---|---|
| 产品发布,稳定运行24小时 | 进入增长循环模式 |
| 不可恢复的失败 | 保存状态,停止,请求人工干预 |
| PRD更新 | 差异对比,创建增量任务,继续 |
| 达到收入目标 | 记录成功,继续优化 |
| 资金储备 < 30天 | 警报,积极优化成本 |
Directory Structure Overview
目录结构概述
.loki/
+-- CONTINUITY.md # Working memory (read/update every turn)
+-- specs/
| +-- openapi.yaml # API spec - source of truth
+-- queue/
| +-- pending.json # Tasks waiting to be claimed
| +-- in-progress.json # Currently executing tasks
| +-- completed.json # Finished tasks
| +-- dead-letter.json # Failed tasks for review
+-- state/
| +-- orchestrator.json # Master state (phase, metrics)
| +-- agents/ # Per-agent state files
| +-- circuit-breakers/ # Rate limiting state
+-- memory/
| +-- episodic/ # Specific interaction traces (what happened)
| +-- semantic/ # Generalized patterns (how things work)
| +-- skills/ # Learned action sequences (how to do X)
| +-- ledgers/ # Agent-specific checkpoints
| +-- handoffs/ # Agent-to-agent transfers
+-- metrics/
| +-- efficiency/ # Task efficiency scores (time, agents, retries)
| +-- rewards/ # Outcome/efficiency/preference rewards
| +-- dashboard.json # Rolling metrics summary
+-- artifacts/
+-- reports/ # Generated reports/dashboardsSee for full structure and state schemas.
references/architecture.md.loki/
+-- CONTINUITY.md # 工作记忆(每轮读取/更新)
+-- specs/
| +-- openapi.yaml # API规范 - 事实来源
+-- queue/
| +-- pending.json # 待领取任务
| +-- in-progress.json # 正在执行的任务
| +-- completed.json # 已完成任务
| +-- dead-letter.json # 待审查的失败任务
+-- state/
| +-- orchestrator.json # 主状态(阶段、指标)
| +-- agents/ # 每个Agent的状态文件
| +-- circuit-breakers/ # 速率限制状态
+-- memory/
| +-- episodic/ # 特定交互轨迹(发生了什么)
| +-- semantic/ # 通用模式(事物如何运作)
| +-- skills/ # 学习到的操作序列(如何做X)
| +-- ledgers/ # Agent特定检查点
| +-- handoffs/ # Agent间转移
+-- metrics/
| +-- efficiency/ # 任务效率得分(时间、Agent数量、重试次数)
| +-- rewards/ # 结果/效率/偏好奖励
| +-- dashboard.json # 滚动指标汇总
+-- artifacts/
+-- reports/ # 生成的报告/仪表盘详见获取完整结构和状态模式。
references/architecture.mdInvocation
调用方式
Loki Mode # Start fresh
Loki Mode with PRD at path/to/prd # Start with PRDSkill Metadata:
| Field | Value |
|---|---|
| Trigger | "Loki Mode" or "Loki Mode with PRD at [path]" |
| Skip When | Need human approval, want to review plan first, single small task |
| Related Skills | subagent-driven-development, executing-plans |
Loki Mode # 全新启动
Loki Mode with PRD at path/to/prd # 带PRD启动技能元数据:
| 字段 | 值 |
|---|---|
| 触发词 | "Loki Mode" 或 "Loki Mode with PRD at [path]" |
| 跳过场景 | 需要人工批准、想先审查计划、单个小任务 |
| 相关技能 | subagent-driven-development, executing-plans |
References
参考资料
Detailed documentation is split into reference files for progressive loading:
| Reference | Content |
|---|---|
| Full RARV cycle, CONTINUITY.md template, autonomy rules |
| Quality gates, anti-sycophancy, blind review, severity blocking |
| OpenAI Agents SDK: guardrails, tripwires, handoffs, fallbacks |
| DeepMind + Anthropic: Constitutional AI, debate, world models |
| HN 2025: What actually works in production, context engineering |
| 2025 research: MAR, Iter-VF, GoalAct, CONSENSAGENT |
| ToolOrchestra patterns: efficiency, rewards, dynamic selection |
| Episodic/semantic memory, consolidation, Zettelkasten linking |
| All 37 agent types with full capabilities |
| Queue system, dead letter handling, circuit breakers |
| All phases with detailed workflows and testing |
| OpenAPI-first workflow, validation, contract testing |
| Directory structure, state schemas, bootstrap |
| MCP server capabilities and integration |
| Boris Cherny patterns, thinking mode, ledgers |
| Cloud deployment instructions per provider |
| Business operation workflows |
Version: 2.32.0 | Lines: ~600 | Research-Enhanced: Labs + HN Production Patterns
详细文档分为参考文件以逐步加载:
| 参考资料 | 内容 |
|---|---|
| 完整RARV循环、CONTINUITY.md模板、自主规则 |
| 质量门、反谄媚、盲审、严重程度阻塞 |
| OpenAI Agents SDK:防护栏、触发线、交接、回退 |
| DeepMind + Anthropic:宪法式AI、辩论、世界模型 |
| HN 2025:生产环境实际有效的方案、上下文工程 |
| 2025研究:MAR、Iter-VF、GoalAct、CONSENSAGENT |
| ToolOrchestra模式:效率、奖励、动态选择 |
| 情景/语义记忆、整合、Zettelkasten链接 |
| 所有37种Agent类型的完整定义和能力 |
| 队列系统、死信处理、断路器 |
| 所有阶段的详细工作流和测试 |
| OpenAPI优先工作流、验证、契约测试 |
| 目录结构、状态模式、引导 |
| MCP服务器能力和集成 |
| Boris Cherny模式、思考模式、分类账 |
| 各云服务商的部署说明 |
| 业务运营工作流 |
版本: 2.32.0 | 行数: ~600 | 研究增强:实验室 + HN生产模式