Skip to content
预计 1 分钟右侧目录可快速定位

Turn Observation ​

createTurnObservation() 内部不是一个事件函数,而是一组事实采集器 ​

Symbol观察对象Runtime fact
turnStarted()Turnstart timestamp/event
toolStarted()Toolpending + current tool
toolCompleted()Tooldone / failed
recordToolActivity()Tool historyrecent activity + observed count
beginMcpExecObservation()MCP executionstall / error / duration diagnostic
observeAwaitToolCall()awaitcompleted / timeout / cancelled
flushPendingAwaitsOnUnwind()cancellation/unwind给尚未结束的 await 补终态
listAsyncTasks()subagent / shell / cloud-agent当前后台工作快照
emitAsyncTasksChanged()background stateowner + task list event
armDispatchObservation()model dispatchdispatch latency / TTFT / resolved model

Tool 生命周期 ​

text
toolStarted(name)
  ├─ lastTool = name
  ├─ activity = pending
  └─ emit tool-started

executor...

toolCompleted(name, failed)
  ├─ clear lastTool
  ├─ activity = done | failed
  └─ emit tool-completed

Await / Cancellation ​

observeAwaitToolCall() 会给 await 建立 pending record;完成时根据 cancel / timeout / result 生成 outcome。flushPendingAwaitsOnUnwind() 则处理控制流提前退出时仍悬空的 await。这就是为什么 Observation 不是简单的“工具返回值”。

Background work ​

listAsyncTasks() 将 subagent、后台 shell、host restart 后重新 attach 的 shell、cloud-agent 统一投影成可观察 task list。它体现的是 execution fact normalization。

本地定位 ​

bash
rg -n "turnStarted|toolStarted|toolCompleted|recordToolActivity|beginMcpExecObservation|observeAwaitToolCall|flushPendingAwaitsOnUnwind|listAsyncTasks|armDispatchObservation" source/host/runner/turn-observation.ts

固定源码 ​

关联知识文章 ​

AI Engineering · Agent · Harness · Backend Systems