knowledge-agent-execution-and-orchestration-decision-loop-and-completion

knowledge-agent-execution-and-orchestration-decision-loop-and-completion is a skill for Claude Code, Codex from echoVic/blade-code. It costs 145 tokens per session (2,679 once invoked), scanned A, original, MIT.

The main execution loop that moves a coding agent through model responses, tool calls, saved conversation state, error recovery, and completion checks.

In plain words
What is it for?
Use it to change streaming agent behavior, tool-call rounds, persistence order, recovery, completion rules, system prompts, plans, or structured output.
Why use it?
It prevents unfinished or unverified work from being treated as complete, including after a crash or interrupted run.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one. Also seen: mentions subagents; names the NotebookEdit tool.

Good fit Use it to change streaming agent behavior, tool-call rounds, persistence order, recovery, completion rules, system prompts, plans, or structured output.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/echovic/blade-code/decision-loop-and-completion
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add echoVic/blade-code --skill decision-loop-and-completion
Clone the repo
git clone --depth 1 https://github.com/echoVic/blade-code

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for knowledge-agent-execution-and-orchestration-decision-loop-and-completion

README.md
[![agentmods](https://agentmods.dev/badge/skills/echovic/blade-code/decision-loop-and-completion.svg)](https://agentmods.dev/skills/echovic/blade-code/decision-loop-and-completion)
Your own site
<a href="https://agentmods.dev/skills/echovic/blade-code/decision-loop-and-completion"><img src="https://agentmods.dev/badge/skills/echovic/blade-code/decision-loop-and-completion.svg" alt="Measured on agentmods" height="20"></a>
Per session 145 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,679 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00145 $0.02679
Opus 5 $0.00072 $0.01340
Sonnet 5 $0.00029 $0.00536
Haiku 4.5 $0.00015 $0.00268

Measured 4d ago against content hash 2322d39b92d3, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

knowledge-agent-execution-and-orchestration-decision-loop-and-completion scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.trae/knowledges/agent-execution-and-orchestration/decision-loop-and-completion/SKILL.md · 75 lines

How it starts

The opening of the file, as written. The whole thing — 75 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Module Structure

该节点描述一次 Agent run 如何在 Provider 回合、工具副作用、持久化和多重完成条件之间推进,并保证崩溃恢复后不会把未提交状态当成成功。

Directory Layout

  • packages/cli/src/agent/Agent.ts — 无状态入口、运行模式切换和 SessionRuntime 适配
  • packages/cli/src/agent/ExecutionEngine.ts — ContextManager 容器与简单单轮执行兼容入口
  • packages/cli/src/agent/ExecutionSummary.ts — 运行统计摘要
  • packages/cli/src/agent/loop/ — 主循环、会话状态、工具流、完成策略和恢复检测
    • executeLoopGenerator.ts — 核心状态机
    • StreamingToolExecutor.ts — 流式预启动、排队、顺序收集和 epoch 丢弃
    • completionPolicy.ts — 显式委派、worktree、验证和停止策略
    • conversationPersistence.ts — 消息、工具调用、工具结果和压缩的 durable commit
    • independentVerification.ts — 非平凡实现的独立验证门禁
    • goalCompletionVerification.ts — Goal 完成候选门禁
    • actionStationarity.ts — 重复工具动作的进展感知检测
  • packages/cli/src/prompts/ — 默认提示、Plan 提示、项目指令和 Provider 边界附加内容
  • packages/cli/src/services/StructuredOutputService.ts — JSON Schema 终态契约与恢复

Key Entry Points

  • Agent.chatStream() in packages/cli/src/agent/Agent.ts — 统一事件流入口并处理 durable input、follow-up 与 Goal continuation
  • executeLoopGenerator() in packages/cli/src/agent/loop/executeLoopGenerator.ts — 完整 agentic loop
  • StreamingToolExecutor.addTool() in packages/cli/src/agent/loop/StreamingToolExecutor.ts — 决定流内预启动、排队或拒绝
  • checkIndependentVerificationGate() in packages/cli/src/agent/loop/independentVerification.ts — 主 Agent 独立验证准出
  • createStructuredOutputContract() in packages/cli/src/services/StructuredOutputService.ts — 结构化终态校验入口

Gotchas

  • stream_end 是每个 Provider turn 的终止信号,一个完整 run 内可能出现多次;消费者不能把第一次 stream_end 当成 Agent 已完成 (packages/cli/src/agent/loop/types.ts)
  • 流式预启动同时要求工具在固定只读 allowlist、声明 isConcurrencySafe 且前面没有 exclusive barrier;仅把工具标成并发安全不会让它在 Provider 流提交前启动 (packages/cli/src/agent/loop/StreamingToolExecutor.ts)
  • 工具副作用前必须先按模型调用顺序提交 durable tool_call;required commit 失败时工具根本不启动,不能把返回的失败结果解释为“可能已执行” (packages/cli/src/agent/loop/StreamingToolExecutor.ts, packages/cli/src/agent/loop/conversationPersistence.ts)
  • 工具执行完成后仍要先提交 durable tool_result 才能发布给界面或下一次 Provider 请求;该提交失败时副作用可能已发生,loop 以 tool_persistence_failed 停止并要求恢复阶段处理不确定性 (packages/cli/src/agent/loop/executeLoopGenerator.ts, packages/cli/src/agent/loop/conversationPersistence.ts, git:b98a073e)
  • 成功的显式验证证据会在后续 Edit、Write、ApplyPatch 或 NotebookEdit 成功时清空;独立验证的 mutation revision 也同步失效,PASS 不能跨源码修改复用 (packages/cli/src/agent/loop/completionPolicy.ts, packages/cli/src/agent/loop/independentVerification.ts)
  • 非平凡实现门禁只在主 Agent 修改至少 3 个实现文件、触及高风险路径或执行潜在写 Bash 时触发;子代理、禁止委派、exactly-once Task 契约或不可用 Task 工具会跳过这一门禁 (packages/cli/src/agent/loop/independentVerification.ts)
  • 用户明确要求的 test、lint、type-check、build 是另一道完成门禁;它按请求中的具体类别匹配成功 Bash 命令,运行了任意一种检查并不自动满足全部要求 (packages/cli/src/agent/loop/completionPolicy.ts)
  • 合法结构化终态只能通过保留的 StructuredOutput 工具提交,JSON prose 不算完成;新 steering 或后续 workspace mutation 会清除已接受对象并重置纠正预算 (packages/cli/src/agent/loop/executeLoopGenerator.ts, packages/cli/src/services/StructuredOutputService.ts)
  • StructuredOutput 恢复同时校验 schema digest 和对象内容;恢复扫描遇到更新的 user message 会停止,旧 schema 或旧输入下的结果不会被误复用 (packages/cli/src/services/StructuredOutputService.ts)
  • Stop hook 超时或抛错采用保守的“允许停止”结果,而不是无限阻塞完成;只有明确返回 shouldStop: false 才注入继续提示并使 Goal 验证失效 (packages/cli/src/agent/loop/completionPolicy.ts, packages/cli/src/agent/loop/executeLoopGenerator.ts)
  • Plan 批准后会先持久化 Session permission mode,再把批准内容包进用户消息并重新进入普通 loop;Plan run 的成功结果本身不是任务执行完成 (packages/cli/src/agent/Agent.ts)
  • 默认 Agent 已取消固定 100 回合上限,-1 表示无限;防止无界循环依靠输出重复、动作停滞、预算与完成门禁,而不是隐含 turn ceiling (packages/cli/src/agent/loop/executeLoopGenerator.ts, git:85643629)

Read the full file on GitHub · 75 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 75 lines · 145 tokens per session scan A 2322d39b92d3

Subscribe to this mod's changes

knowledge-agent-execution-and-orchestration-decision-loop-and-completion is a skill published in the GitHub repository echoVic/blade-code (178 stars, last pushed 2d ago), licensed MIT. It adds 145 tokens to every session and 2,679 once invoked, about $0.0007 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.