AI 原生工程笔记AI Native Engineering

最新LatestOpenHarness 源码阅读 · 八Reading OpenHarness · 8

谁定义,谁派活,谁来跑Who defines, who dispatches, who runs

OpenHarness
源码阅读source reading

  1. 第一篇:Part 1: 按下回车之后After you press EnterAgent 不只是一次模型请求。这篇笔记从一条用户消息出发,跟踪它如何被装配、流式发送,并在工具调用与文本回复之间循环。An agent is more than one model request. Starting from a single user message, this note follows how it is assembled, streamed out, and looped between tool calls and text replies.7 分钟7 min
  2. 第二篇:Part 2: 模型答完了,任务还没完The model is done. The task isn't.第一篇沿着一条消息画出了 Query Loop 的地图;这一篇继续走进 Engine,观察每一轮怎样开始、被拦截、压缩、执行,并最终结束。The first piece mapped the Query Loop by following one message. This one walks into the Engine to watch how each turn starts, gets intercepted, compacted and executed, and finally ends.13 分钟13 min
  3. 第三篇:Part 3: 从零写一个工具,到模型能调用它From an empty file to a tool the model can call工具不只是给 LLM 的函数列表。它还定义输入、权限、生命周期事件,以及结果如何回到下一轮对话。A tool is more than a function list handed to the LLM. It also defines inputs, permissions and lifecycle events, and how its result returns to the next turn of the conversation.10 分钟10 min
  4. 第四篇:Part 4: 九道检查,顺序就是安全策略Nine checks, and the order is the policy工具执行前的统一闸门:先硬拦敏感路径与 deny 列表,再按模式决定放行、弹确认还是直接拒绝。One gate before any tool runs: sensitive paths and the deny list are blocked outright first, then the mode decides whether to allow, ask for confirmation, or refuse.9 分钟9 min
  5. 第五篇:Part 5: Hook 返回 blocked,不等于真的拦住了A hook returning blocked doesn't stop anything by itselfHook 是生命周期节点上的异步扩展机制:适合门禁、审计、通知与校验;但它不是能任意改写 prompt、工具入参或工具结果的通用中间件。Hooks are asynchronous extensions at lifecycle points: good for gates, audits, notifications and checks, but not a general-purpose middleware that can rewrite prompts, tool inputs or tool results at will.11 分钟11 min
  6. 第六篇:Part 6: 先给目录,用到再翻正文Catalog first, body on demandSkill 是 Markdown + YAML frontmatter。系统 prompt 只放清单;正文按需加载——模型走 skill 工具,用户走 /skill-name。A skill is Markdown plus YAML frontmatter. The system prompt holds only the catalog; the body loads on demand: the model goes through the skill tool, the user through /skill-name.11 分钟11 min
  7. 第七篇:Part 7: 外部工具接进来,走的还是同一条管线External tools, same pipelineMCP 把外部工具与资源接到 agent。OpenHarness 做 client:连上 server,用适配器把每个 MCP tool 注册成普通 BaseTool,再走同一套管线。MCP connects external tools and resources to the agent. OpenHarness is the client: it connects to servers, registers each MCP tool as an ordinary BaseTool through an adapter, and sends it down the same pipeline.14 分钟14 min
  8. 第八篇:Part 8: 谁定义,谁派活,谁来跑Who defines, who dispatches, who runs多 Agent 不是一个模块,是三层各管一段:定义层回答「有哪些 agent」,调度层回答「这次派谁」,执行层回答「怎么跑起来」。Multi-agent is not one module but three layers, each owning one part: the definition layer answers “which agents exist”, the dispatch layer “who goes this time”, and the execution layer “how it runs”.12 分钟12 min

实验室Lab大营销抽奖Big Market lottery

大营销抽奖实验室Big Market lottery lab

在浏览器里模拟一次抽奖,显示请求经过的责任链和规则树节点。Simulates a draw in the browser and shows which responsibility-chain and rule-tree nodes the request passed through.

Open the lab去实验室
图Figure权重责任链演示,抽过 3 次之后的一次请求The weight-rule chain demo: one request after three draws
  1. 额度校验Quota checkquota_check
  2. 创建抽奖单Create orderorder
  3. 权重规则Weight rulerule_weight
  4. 默认规则Default rulerule_default(跳过) (skipped)
  5. 解锁规则Unlock rulerule_lock(跳过) (skipped)
  6. 库存规则Stock rulerule_stock(跳过) (skipped)
  7. 兜底奖规则Fallback awardrule_luck_award(跳过) (skipped)
  8. 发奖与履约Awardaward

rule_weight 接管,后面四步都跳过rule_weight takes over; the next four steps are skipped