跳过正文

Tool Calling

Why Codex Does Not Give the Model Every Tool: tool_search, BM25, and Model Replacement

Think of the model as an engineer with a small desk. If hundreds of tool manuals cover it, every request becomes expensive and the right manual is harder to find. Codex instead provides a short catalog and retrieves only the most relevant manuals. This article explains that design, BM25 ranking, reuse in Python or Go, and model replacement. This article is pinned to stable rust-v0.147.0, released on August 7, 2026, at commit be6e8eac. I also rechecked main at commit 646f7c0a on August 9. Two conclusions matter up front:

Codex 为什么不把所有工具都交给模型?讲透 tool_search、BM25 与模型替换

··2016 字· 10 分钟
把模型想成只有一张小桌子的工程师。工具说明书有几百本时,全部摊在桌上既贵又难找;更好的办法是先给它一本目录,需要什么再取出最相关的几本。本文就讲清 Codex 怎样做这件事、为什么使用 BM25 排序,以及怎样把同一办法搬到 Python、Go 和其他模型上。 本文固定在 2026-08-07 发布的稳定版 rust-v0.147.0,源码 commit 为 be6e8eac;另复查了 2026-08-09 的 main commit 646f7c0a。先给两个不会误导人的结论: 模型第一次能看到哪些工具,不是一张永远不变的名单。 它会随模型、接入方式、运行环境和功能开关变化。 tool_search 和背后的 BM25 排序代码都已经写好,普通直连方式可以使用;但这个稳定版给 GPT-5.6 采用的 exec 集中调用方式漏掉了搜索入口。 这不是功能没开发,而是一条接线没有接通。 这篇文章写给谁 # 默认读者只需要知道“大模型可以调用外部工具”。不要求会 Rust,也不要求读过 Codex 源码。 如果你主要写 Python 或 TypeScript,后面的 Rust 连写可以直接理解成“筛选列表 → 改造每一项 → 收集结果”。 有两条阅读路线: 只想理解做法:读小桌子问题、机场图、工具搜索过程、跨语言复用和模型替换; 想跟进源码:继续读伪代码、Rust 对照、完整查询实例和源码索引。 先只记住四句大白话 # 先把 Rust 函数名和 OpenAI 的专有叫法全部擦掉,一个会使用工具的模型仍逃不开四件事:

读完 Codex 源码后,我认为最值得企业 Agent 借鉴的是这 5 个设计

可以把 Codex 想成一支小型施工队:模型像会判断下一步的现场负责人,Agent Harness 则是围绕他的派工台、门禁、档案柜和进度看板。源码真正展示的,不只是“负责人会下命令”,而是整套系统如何让工作安全开工、暂停后接着做,并让用户始终知道事情进行到了哪里。 很多 Agent 教程只有这样一个循环: 1 2 3 4 5 6 while True: response = model(messages, tools) if response.tool_calls: messages += execute(response.tool_calls) else: return response.text 它没有错,只是省略了真正困难的部分:几张工单能否同时开工?测试十分钟不退出时由谁保管现场?每次查看进度是否都要打扰用户?一句“还在检查”会不会被误认为已经交付?用户不知道操作手册叫什么时,系统能否主动找到?用户明确说“不要停”后,任务怎样跨越多轮处理仍不丢失? 这次我没有再从界面现象反推实现,而是阅读了官方 openai/codex 仓库在 commit bb5054f 的 Rust 源码。下文的组件名、状态分支和数值都能在对应源码中找到;产品未来仍可能演进,但这些设计已经足够回答一个问题:企业 Agent Harness 应该替模型承担什么? 先看懂:Agent 的一轮 Turn 到底做了什么 # 把一次完整用餐看成一个 Thread:它是整件事情的总账。前菜、主菜和甜点可以是不同 Turn;每个 Turn 都是从“用户提出这一轮要求”到“这一轮结果真正交付”的完整周期。 一轮 Turn 像一次点单到上菜:中间可以反复派出多张工具工单,也可以完全不调用工具。 顺着图走,一轮通常包含六件事:

Five Codex Harness Designs Worth Copying After Reading the Source

Think of Codex as a small construction crew. The model is the site lead deciding what should happen next. The agent harness is everything around that lead: dispatch desk, access control, job records, and the progress board. The source is valuable not merely because the lead can issue commands, but because the surrounding system keeps work safe, recoverable, and understandable to the customer. Many agent tutorials reduce the loop to this:

Claude's Tool Calling Paradigm Shift: A Deep Dive into Programmatic Tool Calling and Dynamic Filtering

The important change is not “two more tool features.” It is the movement of multi-step orchestration into a code-execution environment, with only a compact result returning to model context. Background: The Cost Problem in Agent Tool Calling # In traditional agent tool-calling, every tool invocation requires a full cycle of “model inference → tool execution → result return → model re-inference.” This seemingly natural loop breaks down at scale in three ways: