mirror of
https://github.com/openai/codex.git
synced 2026-05-23 12:34:25 +00:00
## Why `ToolExecutor` is the runtime contract that keeps a callable tool and its model-visible spec together. Leaving `spec()` optional lets a registered runtime silently omit that half of the contract, and it also overloads a missing spec as an exposure decision for tools that should stay dispatchable without being shown to the model. ## What - Make `ToolExecutor::spec()` required and update core, extension, and test tool executors to return a concrete `ToolSpec`. - Add `ToolExposure::Hidden` for dispatch-only tools. The legacy `shell_command` runtime in unified-exec sessions now uses that explicit exposure instead of hiding itself by omitting a spec. - Build MCP tool specs when `McpHandler` is constructed so invalid MCP specs are skipped before the handler is registered. - Keep tool planning aligned with the new contract for direct, deferred, hidden, code-mode, dynamic, and namespaced tool paths. ## Testing - Added tool-plan coverage that invalid MCP tool specs are not registered. - Updated shell-family coverage for the hidden legacy `shell_command` runtime and the affected tool executor test fixtures.
60 lines
1.7 KiB
Rust
60 lines
1.7 KiB
Rust
use crate::FunctionCallError;
|
|
use crate::ToolName;
|
|
use crate::ToolOutput;
|
|
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,
|
|
|
|
/// 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 supports_parallel_tool_calls(&self) -> bool {
|
|
false
|
|
}
|
|
|
|
async fn handle(
|
|
&self,
|
|
invocation: Invocation,
|
|
) -> Result<Box<dyn ToolOutput>, FunctionCallError>;
|
|
}
|