graph TB
subgraph "core/ 核心包"
A[core/session] -->|"会话事件日志"| B[core/agent-loop]
C[core/system-prompt] -->|"Prompt 段落组装"| B
D[core/tools] -->|"工具注册表"| B
E[core/agent] -->|"Agent 接口"| B
F[core/scope] -->|"作用域原语"| B
end
B -->|"驱动"| G[ReactLoopAgent]
G -->|"执行"| H[Turn/Step 循环]
H -->|"调用"| I[LLM 服务]
H -->|"执行"| J[工具管道]
turn/start
claim next-step input plus one queued message
assemble prompt sections + tool schemas
-> agent/pre-step reject | enter(messages, startsRequestSeries?)
reject, or a first enter rewritten empty -> close the turn with no step
step/start
append entered messages as user/message
derive model history from the log
agent/request -> llm/stream -> assistant/chunk* -> assistant/message
tool/call* -> tools/pre-execute -> tools/execute -> tools/post-execute -> tool/result*
step/end
tools owe another request, or next-step input arrived -> claim -> next step
-> agent/turn-stopping
turn/end
4.4.2 事件分类
预览
源码
graph LR
subgraph "持久化会话事件"
A["turn/*"]
B["step/*"]
C["user/message"]
D["assistant/*"]
E["tool/*"]
end
subgraph "活的扩展点"
F["agent/pre-step"]
G["agent/request"]
H["llm/stream"]
I["tools/pre-execute"]
J["tools/execute"]
K["tools/post-execute"]
end
subgraph "Waterfall 事件"
L["agent/pre-step<br/>必须调用 next()"]
M["agent/request<br/>必须调用 next()"]
N["llm/stream<br/>必须调用 next()"]
O["tools/*<br/>必须调用 next()"]
end
sequenceDiagram
participant Loop as Agent Loop
participant Pre as tools/pre-execute
participant Exec as tools/execute
participant Post as tools/post-execute
participant Tool as 实际工具
Loop->>Pre: waterfall('tools/pre-execute', input)
Note over Pre: 预处理、验证、拦截
Pre-->>Loop: modified input
Loop->>Exec: waterfall('tools/execute', input)
Exec->>Tool: 实际执行
Tool-->>Exec: result
Exec-->>Loop: result
Loop->>Post: waterfall('tools/post-execute', result)
Note over Post: 后处理、审计
Post-->>Loop: final result
sequenceDiagram
participant Loop as Agent Loop
participant Pre as tools/pre-execute
participant Exec as tools/execute
participant Post as tools/post-execute
participant Tool as 实际工具
Loop->>Pre: waterfall('tools/pre-execute', input)
Note over Pre: 预处理、验证、拦截
Pre-->>Loop: modified input
Loop->>Exec: waterfall('tools/execute', input)
Exec->>Tool: 实际执行
Tool-->>Exec: result
Exec-->>Loop: result
Loop->>Post: waterfall('tools/post-execute', result)
Note over Post: 后处理、审计
Post-->>Loop: final result
graph TB
A[session 日志] --> B[deriveMessages]
B --> C[模型历史]
D[system-prompt] --> E[prompt sections]
F[tools] --> G[tool schemas]
E --> H[renderPrompt]
G --> H
C --> H
H --> I[完整 Prompt]