mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
[codex] Outline ToolExecutor handler bodies (#27299)
## Why We're now [discouraging use of `async_trait`](https://github.com/openai/codex/pull/20242). Removing use of `async_trait` from `ToolExecutor` yields a `codex_core` debug test build speedup of ~78% (from 227.5s to 50.3s) on my machine. For ease of reviewing, this is a prefactor to extract trait method implementations to inherent methods. This will prevent changing indentation from creating a huge diff. ## What Outlined existing `ToolExecutor::handle` bodies into inherent async `handle_call` methods across core and extension tool handlers. The trait methods still use `async_trait` and now delegate to `self.handle_call(...).await`; handler behavior is unchanged.
This commit is contained in:
@@ -97,6 +97,12 @@ impl ToolExecutor<ToolCall> for ImageGenerationTool {
|
||||
|
||||
/// Executes the selected image operation and returns the completed image result.
|
||||
async fn handle(&self, call: ToolCall) -> Result<Box<dyn ToolOutput>, FunctionCallError> {
|
||||
self.handle_call(call).await
|
||||
}
|
||||
}
|
||||
|
||||
impl ImageGenerationTool {
|
||||
async fn handle_call(&self, call: ToolCall) -> Result<Box<dyn ToolOutput>, FunctionCallError> {
|
||||
let args = parse_args(&call)?;
|
||||
let request = request_for_args(&args, call.conversation_history.items())?;
|
||||
call.turn_item_emitter
|
||||
|
||||
@@ -61,6 +61,19 @@ where
|
||||
&self,
|
||||
call: ToolCall,
|
||||
) -> Result<Box<dyn codex_extension_api::ToolOutput>, codex_extension_api::FunctionCallError>
|
||||
{
|
||||
self.handle_call(call).await
|
||||
}
|
||||
}
|
||||
|
||||
impl<B> AddAdHocNoteTool<B>
|
||||
where
|
||||
B: MemoriesBackend,
|
||||
{
|
||||
async fn handle_call(
|
||||
&self,
|
||||
call: ToolCall,
|
||||
) -> Result<Box<dyn codex_extension_api::ToolOutput>, codex_extension_api::FunctionCallError>
|
||||
{
|
||||
let backend = self.backend.clone();
|
||||
let args: AddAdHocNoteArgs = parse_args(&call)?;
|
||||
|
||||
@@ -59,6 +59,19 @@ where
|
||||
&self,
|
||||
call: ToolCall,
|
||||
) -> Result<Box<dyn codex_extension_api::ToolOutput>, codex_extension_api::FunctionCallError>
|
||||
{
|
||||
self.handle_call(call).await
|
||||
}
|
||||
}
|
||||
|
||||
impl<B> ListTool<B>
|
||||
where
|
||||
B: MemoriesBackend,
|
||||
{
|
||||
async fn handle_call(
|
||||
&self,
|
||||
call: ToolCall,
|
||||
) -> Result<Box<dyn codex_extension_api::ToolOutput>, codex_extension_api::FunctionCallError>
|
||||
{
|
||||
let backend = self.backend.clone();
|
||||
let args: ListArgs = parse_args(&call)?;
|
||||
|
||||
@@ -58,6 +58,19 @@ where
|
||||
&self,
|
||||
call: ToolCall,
|
||||
) -> Result<Box<dyn codex_extension_api::ToolOutput>, codex_extension_api::FunctionCallError>
|
||||
{
|
||||
self.handle_call(call).await
|
||||
}
|
||||
}
|
||||
|
||||
impl<B> ReadTool<B>
|
||||
where
|
||||
B: MemoriesBackend,
|
||||
{
|
||||
async fn handle_call(
|
||||
&self,
|
||||
call: ToolCall,
|
||||
) -> Result<Box<dyn codex_extension_api::ToolOutput>, codex_extension_api::FunctionCallError>
|
||||
{
|
||||
let backend = self.backend.clone();
|
||||
let args: ReadArgs = parse_args(&call)?;
|
||||
|
||||
@@ -67,6 +67,19 @@ where
|
||||
&self,
|
||||
call: ToolCall,
|
||||
) -> Result<Box<dyn codex_extension_api::ToolOutput>, codex_extension_api::FunctionCallError>
|
||||
{
|
||||
self.handle_call(call).await
|
||||
}
|
||||
}
|
||||
|
||||
impl<B> SearchTool<B>
|
||||
where
|
||||
B: MemoriesBackend,
|
||||
{
|
||||
async fn handle_call(
|
||||
&self,
|
||||
call: ToolCall,
|
||||
) -> Result<Box<dyn codex_extension_api::ToolOutput>, codex_extension_api::FunctionCallError>
|
||||
{
|
||||
let backend = self.backend.clone();
|
||||
let args: SearchArgs = parse_args(&call)?;
|
||||
|
||||
@@ -75,6 +75,12 @@ impl ToolExecutor<ToolCall> for WebSearchTool {
|
||||
}
|
||||
|
||||
async fn handle(&self, call: ToolCall) -> Result<Box<dyn ToolOutput>, FunctionCallError> {
|
||||
self.handle_call(call).await
|
||||
}
|
||||
}
|
||||
|
||||
impl WebSearchTool {
|
||||
async fn handle_call(&self, call: ToolCall) -> Result<Box<dyn ToolOutput>, FunctionCallError> {
|
||||
let commands = parse_commands(&call)?;
|
||||
let command_action = command_action(&commands);
|
||||
let provider = self
|
||||
|
||||
Reference in New Issue
Block a user