mirror of
https://github.com/openai/codex.git
synced 2026-05-24 21:14:51 +00:00
## Why The tool runtime path still had a typed output associated type on `ToolExecutor`, plus a core-only `RegisteredTool` adapter and extension-only executor aliases. That made every new shared tool runtime carry extra adapter plumbing before it could participate in core dispatch, extension tools, hook payloads, telemetry, and model-visible spec generation. This PR moves output erasure to the shared executor boundary so core and extension tools can use the same execution contract directly. ## What Changed - Changed `codex_tools::ToolExecutor` to return `Box<dyn ToolOutput>` instead of an associated `Output` type. - Removed the extension-specific `ExtensionToolExecutor` / `ExtensionToolOutput` aliases and exposed `ToolExecutor<ToolCall>` plus `ToolOutput` through `codex-extension-api`. - Reworked core tool registration around `CoreToolRuntime` and `ToolRegistry::from_tools`, removing the extra `RegisteredTool` / `ToolRegistryBuilder` layer. - Consolidated model-visible spec planning and registry construction in `core/src/tools/spec_plan.rs`, including deferred tool search and code-mode-only filtering. - Added `ToolOutput` helpers for post-tool-use hook ids and inputs so MCP, unified exec, extension, and other boxed outputs preserve the same hook payload behavior. - Updated core handlers, memories tools, and the related registry/spec/router tests to use the simplified contract. ## Test Coverage - Updated coverage for tool spec planning, registry lookup, deferred tool search registration, extension tool routing, post-tool-use hook payloads, dispatch tracing, guardian output extraction, and memories extension tool execution.
59 lines
1.7 KiB
Rust
59 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,
|
|
}
|
|
|
|
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) -> Option<ToolSpec> {
|
|
None
|
|
}
|
|
|
|
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>;
|
|
}
|