mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
8d720feb69
Deferred tools need to be searchable even when they are not implemented inside `codex-core`. Extension-provided tools can be registered for later discovery, but the search metadata path was still owned by core-specific runtime hooks, which meant the shared `ToolExecutor` abstraction could not describe how a deferred extension tool should appear in `tool_search`. ## Changes - Move `ToolSearchEntry` and `ToolSearchInfo` into `codex-tools` and re-export them from the shared tools crate. - Add a default `ToolExecutor::search_info` implementation that derives loadable tool-search metadata from function and namespace specs. - Forward search metadata through extension adapters and exposure overrides while keeping custom search text/source metadata for dynamic, MCP, and multi-agent tools. - Remove the old core-local `tool_search_entry` module now that search metadata lives with the shared executor APIs. ## Testing - Added `deferred_extension_tools_are_discoverable_with_tool_search` coverage in `core/src/tools/spec_plan_tests.rs`.
68 lines
2.1 KiB
Rust
68 lines
2.1 KiB
Rust
use crate::FunctionCallError;
|
|
use crate::ToolName;
|
|
use crate::ToolOutput;
|
|
use crate::ToolSearchInfo;
|
|
use crate::ToolSpec;
|
|
|
|
/// Controls where a tool is exposed to the model.
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
pub enum ToolExposure {
|
|
/// Include this tool in the initial model-visible tool list.
|
|
///
|
|
/// When code mode is enabled, this tool is also available as a nested
|
|
/// code-mode tool.
|
|
Direct,
|
|
|
|
/// Register this tool for later discovery, but omit it from the initial
|
|
/// model-visible tool list. Deferred tools must provide search metadata via
|
|
/// [`ToolExecutor::search_info`]. The default implementation derives
|
|
/// metadata from function and namespace specs.
|
|
Deferred,
|
|
|
|
/// Include this tool in the initial model-visible tool list only.
|
|
///
|
|
/// In code-mode-only sessions, this keeps the tool callable as a normal
|
|
/// model tool while excluding it from the nested code-mode tool surface.
|
|
DirectModelOnly,
|
|
|
|
/// Keep this tool registered for dispatch without exposing it to the model.
|
|
Hidden,
|
|
}
|
|
|
|
impl ToolExposure {
|
|
pub fn is_direct(self) -> bool {
|
|
matches!(self, Self::Direct | Self::DirectModelOnly)
|
|
}
|
|
}
|
|
|
|
/// Shared runtime contract for model-visible tools.
|
|
///
|
|
/// Implementations keep the model-visible spec tied to the executable runtime.
|
|
/// Host crates can layer routing, hooks, telemetry, or other orchestration on
|
|
/// top without reopening the spec/runtime split.
|
|
#[async_trait::async_trait]
|
|
pub trait ToolExecutor<Invocation>: Send + Sync {
|
|
/// The concrete tool name handled by this runtime instance.
|
|
fn tool_name(&self) -> ToolName;
|
|
|
|
fn spec(&self) -> ToolSpec;
|
|
|
|
fn exposure(&self) -> ToolExposure {
|
|
ToolExposure::Direct
|
|
}
|
|
|
|
fn search_info(&self) -> Option<ToolSearchInfo> {
|
|
let spec = self.spec();
|
|
ToolSearchInfo::from_tool_spec(&self.tool_name(), spec, /*source_info*/ None)
|
|
}
|
|
|
|
fn supports_parallel_tool_calls(&self) -> bool {
|
|
false
|
|
}
|
|
|
|
async fn handle(
|
|
&self,
|
|
invocation: Invocation,
|
|
) -> Result<Box<dyn ToolOutput>, FunctionCallError>;
|
|
}
|