mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Unify tool runtime assembly before router construction (#36119)
## What changed - Split core tool planning from the assembly of MCP, extension, and dynamic tool runtimes. - Build `ToolRouter` from a single ordered runtime list plus hosted tool specs. - Centralize whether each `ToolExposure` variant is available in code mode. - Preserve core, MCP, extension, and dynamic source ordering and existing name-collision priority. ## Testing - Add coverage for unified source ordering and collisions, code-mode exposure, and standalone web search alongside MCP and dynamic `web.run` tools. GitOrigin-RevId: b010c2e9728b92b75a35325ca9b2ec465c3bac12
This commit is contained in:
1 parent
6219b7c40f
commit
b293412c24
8 files changed
+415
-332
No files matched your search
@@ -1,4 +1,3 @@
|
||||
use crate::environment_selection::TurnEnvironmentSnapshot;
|
||||
use crate::function_tool::FunctionCallError;
|
||||
use crate::session::session::Session;
|
||||
use crate::session::step_context::StepContext;
|
||||
@@ -12,12 +11,9 @@ use crate::tools::registry::CoreToolRuntime;
|
||||
use crate::tools::registry::ToolArgumentDiffConsumer;
|
||||
use crate::tools::registry::ToolRegistry;
|
||||
use crate::tools::spec_plan::build_tool_router;
|
||||
use codex_protocol::dynamic_tools::DynamicToolSpec;
|
||||
use codex_protocol::models::ResponseItem;
|
||||
use codex_protocol::models::SearchToolCallParams;
|
||||
use codex_tools::DiscoverableTool;
|
||||
use codex_tools::ToolCall as ExtensionToolCall;
|
||||
use codex_tools::ToolExecutor;
|
||||
use codex_tools::ToolName;
|
||||
use codex_tools::ToolSpec;
|
||||
use std::borrow::Cow;
|
||||
@@ -71,14 +67,6 @@ pub struct ToolRouter {
|
||||
model_visible_specs: Vec<ToolSpec>,
|
||||
}
|
||||
|
||||
pub(crate) struct ToolRouterParams<'a> {
|
||||
pub(crate) tool_runtimes: Vec<Arc<dyn CoreToolRuntime>>,
|
||||
pub(crate) tool_suggest_candidates: Option<ToolSuggestCandidates>,
|
||||
pub(crate) extension_tool_executors: Vec<Arc<dyn ToolExecutor<ExtensionToolCall>>>,
|
||||
pub(crate) wait_for_environment_tool_config: Option<Arc<crate::WaitForEnvironmentToolConfig>>,
|
||||
pub(crate) dynamic_tools: &'a [DynamicToolSpec],
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum ToolSuggestPresentation {
|
||||
ListTool,
|
||||
@@ -92,18 +80,16 @@ pub(crate) struct ToolSuggestCandidates {
|
||||
}
|
||||
|
||||
impl ToolRouter {
|
||||
pub(crate) fn from_context(
|
||||
pub(crate) fn from_tools(
|
||||
turn_context: &TurnContext,
|
||||
environments: &TurnEnvironmentSnapshot,
|
||||
mcp: &codex_mcp::McpBinding,
|
||||
params: ToolRouterParams<'_>,
|
||||
tool_runtimes: Vec<Arc<dyn CoreToolRuntime>>,
|
||||
hosted_specs: Vec<ToolSpec>,
|
||||
tool_search_handler_cache: &ToolSearchHandlerCache,
|
||||
) -> Self {
|
||||
build_tool_router(
|
||||
turn_context,
|
||||
environments,
|
||||
mcp,
|
||||
params,
|
||||
tool_runtimes,
|
||||
hosted_specs,
|
||||
tool_search_handler_cache,
|
||||
)
|
||||
}
|
||||
@@ -299,26 +285,6 @@ impl ToolRouter {
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(level = "trace", skip_all)]
|
||||
pub(crate) fn extension_tool_executors(
|
||||
session: &Session,
|
||||
step_store: &codex_extension_api::ExtensionData,
|
||||
) -> Vec<Arc<dyn ToolExecutor<ExtensionToolCall>>> {
|
||||
session
|
||||
.services
|
||||
.extensions
|
||||
.tool_contributors()
|
||||
.iter()
|
||||
.flat_map(|contributor| {
|
||||
contributor.tools_for_step(
|
||||
&session.services.session_extension_data,
|
||||
&session.services.thread_extension_data,
|
||||
step_store,
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "router_tests.rs"]
|
||||
mod tests;
|
||||
Reference in new issue
Block a user