mirror of
https://github.com/openai/codex.git
synced 2026-11-26 23:40:43 +00:00
Simplify tool executor lifetimes (#64159)
## Why Extension tools borrow host capabilities for each call. Expressing that borrow in the executor's type argument requires higher-ranked lifetime bounds wherever extension executors are stored or returned. ## What changed Define the per-call input as `ToolInput::Call<'a>` so `ToolExecutor` can use the same lifetime for the input, the executor borrow, and the returned future while remaining usable as a trait object. Default to borrowed `ToolCall<'a>` inputs so extension contributors can return `Arc<dyn ToolExecutor>`. Core handlers continue to take owned `ToolInvocation` inputs. GitOrigin-RevId: efbf56c1e758c59a18b192d210c2ab1b368793e2
This commit is contained in:
@@ -98,10 +98,12 @@ pub use tool_discovery::TOOL_SEARCH_TOOL_NAME;
|
||||
pub use tool_discovery::ToolSearchSourceInfo;
|
||||
pub use tool_discovery::collect_request_plugin_install_entries;
|
||||
pub use tool_discovery::filter_request_plugin_install_discoverable_tools_for_client;
|
||||
pub use tool_executor::BorrowedToolCall;
|
||||
pub use tool_executor::ToolExecutor;
|
||||
pub use tool_executor::ToolExecutorFuture;
|
||||
pub use tool_executor::ToolExposure;
|
||||
pub use tool_executor::ToolExposures;
|
||||
pub use tool_executor::ToolInput;
|
||||
pub use tool_output::JsonToolOutput;
|
||||
pub use tool_output::ToolOutput;
|
||||
pub use tool_payload::ToolPayload;
|
||||
|
||||
@@ -98,12 +98,25 @@ impl ToolExposure {
|
||||
}
|
||||
}
|
||||
|
||||
/// Selects the input a tool receives for the lifetime of one call.
|
||||
/// Keeping the associated type here lets `ToolExecutor` remain dyn-compatible.
|
||||
pub trait ToolInput {
|
||||
type Call<'a>: 'a;
|
||||
}
|
||||
|
||||
/// Extension tools borrow host capabilities for the duration of the call.
|
||||
pub enum BorrowedToolCall {}
|
||||
|
||||
impl ToolInput for BorrowedToolCall {
|
||||
type Call<'a> = crate::ToolCall<'a>;
|
||||
}
|
||||
|
||||
/// 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.
|
||||
pub trait ToolExecutor<Invocation>: Send + Sync {
|
||||
pub trait ToolExecutor<Input: ToolInput = BorrowedToolCall>: Send + Sync {
|
||||
/// The concrete tool name handled by this runtime instance.
|
||||
fn tool_name(&self) -> ToolName;
|
||||
|
||||
@@ -133,7 +146,5 @@ pub trait ToolExecutor<Invocation>: Send + Sync {
|
||||
}
|
||||
|
||||
/// Handles one invocation without retaining capabilities borrowed by the host.
|
||||
fn handle<'a>(&'a self, invocation: Invocation) -> ToolExecutorFuture<'a>
|
||||
where
|
||||
Invocation: 'a;
|
||||
fn handle<'a>(&'a self, invocation: Input::Call<'a>) -> ToolExecutorFuture<'a>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user