控制流与编排引擎

UI RendererEditToolGrepToolReadToolTool BatcherLLM APIMain Loop (tt)UserUI RendererEditToolGrepToolReadToolTool BatcherLLM APIMain Loop (tt)Userpar[Parallel Execution]Sequential Execution"Search for TODO comments and update them"Stream request with contexttext_delta: "I'll search for TODOs..."Update displaytool_use: GrepTooltool_use: ReadTool (multiple files)message_stopExecute tool batchReadTool.call() [Read-only]GrepTool.call() [Read-only]Progress: "Reading file1.js"Progress: "Searching *.js"Result: File contentsResult: 5 matchesTool resultsContinue with resultstool_use: EditToolExecute write toolEditTool.call() [Write]Progress: "Editing file1.js"Result: SuccessEdit completeContinue with resulttext_delta: "Updated 5 TODOs..."Final response

UI 渲染器编辑工具 grep 工具读取工具工具批处理 LLM API 主循环 (tt) 用户 UI 渲染器编辑工具 grep 工具读取工具工具批处理 LLM API 主循环 (tt) 用户并行执行顺序执行"搜索 TODO 注释并更新它们"带上下文的流请求 text_delta: "我会搜索 TODO..."更新显示工具使用:GrepTool工具使用:ReadTool(多个文件)消息停止执行工具批处理 ReadTool.call() [只读]GrepTool.call() [只读]进度:"正在读取 file1.js"进度:"正在搜索 *.js"结果:文件内容结果:5 个匹配工具结果继续处理结果工具使用:EditTool执行写入工具 EditTool.call() [写入]进度:"正在编辑 file1.js"结果:成功编辑完成继续处理结果 text_delta: "更新了 5 个 TODO..."最终响应

The heart of Claude Code is the tt async generator function—a sophisticated state machine that orchestrates the entire conversation flow. Let's examine its actual structure:

Claude Code 的核心是 tt 异步生成器函数——一个复杂的状态机,协调整个对话流程。让我们检查它的实际结构:

async function* tt( currentMessages: CliMessage[], baseSystemPromptString: string, currentGitContext: GitContext, currentClaudeMdContents: ClaudeMdContent[], permissionGranterFn: PermissionGranter, toolUseContext: ToolUseContext, activeStreamingToolUse?: ToolUseBlock, loopState: { turnId: string, turnCounter: number, compacted?: boolean, isResuming?: boolean } ): AsyncGenerator<CliMessage, void, void> { }

异步生成函数* tt( currentMessages: CliMessage[], baseSystemPromptString: string, currentGitContext: GitContext, currentClaudeMdContents: ClaudeMdContent[], permissionGranterFn: PermissionGranter, toolUseContext: ToolUseContext, activeStreamingToolU...

开通本站会员,查看完整译文。

- 위키
Copyright © 2011-2025 iteam. Current version is 2.144.0. UTC+08:00, 2025-06-06 12:01
浙ICP备14020137号-1 $방문자$