diff --git a/codex-rs/core/src/tools/code_mode/execute_handler.rs b/codex-rs/core/src/tools/code_mode/execute_handler.rs index 3f77216c1674..c46c3e045854 100644 --- a/codex-rs/core/src/tools/code_mode/execute_handler.rs +++ b/codex-rs/core/src/tools/code_mode/execute_handler.rs @@ -1,5 +1,3 @@ -use async_trait::async_trait; - use crate::function_tool::FunctionCallError; use crate::tools::context::FunctionToolOutput; use crate::tools::context::ToolInvocation; @@ -53,7 +51,6 @@ impl CodeModeExecuteHandler { } } -#[async_trait] impl ToolHandler for CodeModeExecuteHandler { type Output = FunctionToolOutput; diff --git a/codex-rs/core/src/tools/code_mode/wait_handler.rs b/codex-rs/core/src/tools/code_mode/wait_handler.rs index f319985a885e..8a9d24c1ffcc 100644 --- a/codex-rs/core/src/tools/code_mode/wait_handler.rs +++ b/codex-rs/core/src/tools/code_mode/wait_handler.rs @@ -1,4 +1,3 @@ -use async_trait::async_trait; use serde::Deserialize; use crate::function_tool::FunctionCallError; @@ -39,7 +38,6 @@ where }) } -#[async_trait] impl ToolHandler for CodeModeWaitHandler { type Output = FunctionToolOutput; diff --git a/codex-rs/core/src/tools/handlers/agent_jobs.rs b/codex-rs/core/src/tools/handlers/agent_jobs.rs index c607730b8fd2..044e2072f9f3 100644 --- a/codex-rs/core/src/tools/handlers/agent_jobs.rs +++ b/codex-rs/core/src/tools/handlers/agent_jobs.rs @@ -13,7 +13,6 @@ use crate::tools::handlers::multi_agents::build_agent_spawn_config; use crate::tools::handlers::parse_arguments; use crate::tools::registry::ToolHandler; use crate::tools::registry::ToolKind; -use async_trait::async_trait; use codex_protocol::ThreadId; use codex_protocol::protocol::AgentStatus; use codex_protocol::protocol::SessionSource; @@ -178,7 +177,6 @@ impl JobProgressEmitter { } } -#[async_trait] impl ToolHandler for BatchJobHandler { type Output = FunctionToolOutput; diff --git a/codex-rs/core/src/tools/handlers/apply_patch.rs b/codex-rs/core/src/tools/handlers/apply_patch.rs index 801cff56f381..00b1173aa4ac 100644 --- a/codex-rs/core/src/tools/handlers/apply_patch.rs +++ b/codex-rs/core/src/tools/handlers/apply_patch.rs @@ -21,7 +21,6 @@ use crate::tools::registry::ToolKind; use crate::tools::runtimes::apply_patch::ApplyPatchRequest; use crate::tools::runtimes::apply_patch::ApplyPatchRuntime; use crate::tools::sandboxing::ToolCtx; -use async_trait::async_trait; use codex_apply_patch::ApplyPatchAction; use codex_apply_patch::ApplyPatchFileChange; use codex_protocol::models::FileSystemPermissions; @@ -122,7 +121,6 @@ async fn effective_patch_permissions( ) } -#[async_trait] impl ToolHandler for ApplyPatchHandler { type Output = ApplyPatchToolOutput; diff --git a/codex-rs/core/src/tools/handlers/dynamic.rs b/codex-rs/core/src/tools/handlers/dynamic.rs index 23285bc9079d..5f73f096e28f 100644 --- a/codex-rs/core/src/tools/handlers/dynamic.rs +++ b/codex-rs/core/src/tools/handlers/dynamic.rs @@ -7,7 +7,6 @@ use crate::tools::context::ToolPayload; use crate::tools::handlers::parse_arguments; use crate::tools::registry::ToolHandler; use crate::tools::registry::ToolKind; -use async_trait::async_trait; use codex_protocol::dynamic_tools::DynamicToolCallRequest; use codex_protocol::dynamic_tools::DynamicToolResponse; use codex_protocol::models::FunctionCallOutputContentItem; @@ -20,7 +19,6 @@ use tracing::warn; pub struct DynamicToolHandler; -#[async_trait] impl ToolHandler for DynamicToolHandler { type Output = FunctionToolOutput; diff --git a/codex-rs/core/src/tools/handlers/js_repl.rs b/codex-rs/core/src/tools/handlers/js_repl.rs index c5906abafcfb..cf8d0e862068 100644 --- a/codex-rs/core/src/tools/handlers/js_repl.rs +++ b/codex-rs/core/src/tools/handlers/js_repl.rs @@ -1,4 +1,3 @@ -use async_trait::async_trait; use serde_json::Value as JsonValue; use std::sync::Arc; use std::time::Duration; @@ -92,7 +91,6 @@ async fn emit_js_repl_exec_end( }; emitter.emit(ctx, stage).await; } -#[async_trait] impl ToolHandler for JsReplHandler { type Output = FunctionToolOutput; @@ -182,7 +180,6 @@ impl ToolHandler for JsReplHandler { } } -#[async_trait] impl ToolHandler for JsReplResetHandler { type Output = FunctionToolOutput; diff --git a/codex-rs/core/src/tools/handlers/list_dir.rs b/codex-rs/core/src/tools/handlers/list_dir.rs index fd461e82e5d4..be4e356c5c91 100644 --- a/codex-rs/core/src/tools/handlers/list_dir.rs +++ b/codex-rs/core/src/tools/handlers/list_dir.rs @@ -4,7 +4,6 @@ use std::fs::FileType; use std::path::Path; use std::path::PathBuf; -use async_trait::async_trait; use codex_utils_string::take_bytes_at_char_boundary; use serde::Deserialize; use tokio::fs; @@ -45,7 +44,6 @@ struct ListDirArgs { depth: usize, } -#[async_trait] impl ToolHandler for ListDirHandler { type Output = FunctionToolOutput; diff --git a/codex-rs/core/src/tools/handlers/mcp.rs b/codex-rs/core/src/tools/handlers/mcp.rs index 18e0df25c4ad..6eaccaf81a0c 100644 --- a/codex-rs/core/src/tools/handlers/mcp.rs +++ b/codex-rs/core/src/tools/handlers/mcp.rs @@ -1,4 +1,3 @@ -use async_trait::async_trait; use std::sync::Arc; use crate::function_tool::FunctionCallError; @@ -10,7 +9,6 @@ use crate::tools::registry::ToolKind; use codex_protocol::mcp::CallToolResult; pub struct McpHandler; -#[async_trait] impl ToolHandler for McpHandler { type Output = CallToolResult; diff --git a/codex-rs/core/src/tools/handlers/mcp_resource.rs b/codex-rs/core/src/tools/handlers/mcp_resource.rs index 158aee612b56..d0b7ddc5a816 100644 --- a/codex-rs/core/src/tools/handlers/mcp_resource.rs +++ b/codex-rs/core/src/tools/handlers/mcp_resource.rs @@ -3,7 +3,6 @@ use std::sync::Arc; use std::time::Duration; use std::time::Instant; -use async_trait::async_trait; use codex_protocol::mcp::CallToolResult; use codex_protocol::models::function_call_output_content_items_to_text; use rmcp::model::ListResourceTemplatesResult; @@ -178,7 +177,6 @@ struct ReadResourcePayload { result: ReadResourceResult, } -#[async_trait] impl ToolHandler for McpResourceHandler { type Output = FunctionToolOutput; diff --git a/codex-rs/core/src/tools/handlers/multi_agents.rs b/codex-rs/core/src/tools/handlers/multi_agents.rs index 166dbd287d73..df66543da64c 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents.rs @@ -17,7 +17,6 @@ pub(crate) use crate::tools::handlers::multi_agents_common::*; use crate::tools::handlers::parse_arguments; use crate::tools::registry::ToolHandler; use crate::tools::registry::ToolKind; -use async_trait::async_trait; use codex_protocol::ThreadId; use codex_protocol::models::ResponseInputItem; use codex_protocol::openai_models::ReasoningEffort; diff --git a/codex-rs/core/src/tools/handlers/multi_agents/close_agent.rs b/codex-rs/core/src/tools/handlers/multi_agents/close_agent.rs index efc8ec378e32..779a85e19892 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents/close_agent.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents/close_agent.rs @@ -2,7 +2,6 @@ use super::*; pub(crate) struct Handler; -#[async_trait] impl ToolHandler for Handler { type Output = CloseAgentResult; diff --git a/codex-rs/core/src/tools/handlers/multi_agents/resume_agent.rs b/codex-rs/core/src/tools/handlers/multi_agents/resume_agent.rs index 09526182f293..9991a90671b6 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents/resume_agent.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents/resume_agent.rs @@ -4,7 +4,6 @@ use std::sync::Arc; pub(crate) struct Handler; -#[async_trait] impl ToolHandler for Handler { type Output = ResumeAgentResult; diff --git a/codex-rs/core/src/tools/handlers/multi_agents/send_input.rs b/codex-rs/core/src/tools/handlers/multi_agents/send_input.rs index 3c8527712b2e..4ae3240cb384 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents/send_input.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents/send_input.rs @@ -3,7 +3,6 @@ use crate::agent::control::render_input_preview; pub(crate) struct Handler; -#[async_trait] impl ToolHandler for Handler { type Output = SendInputResult; diff --git a/codex-rs/core/src/tools/handlers/multi_agents/spawn.rs b/codex-rs/core/src/tools/handlers/multi_agents/spawn.rs index 308ec49d8564..8e4bfb5b594f 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents/spawn.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents/spawn.rs @@ -10,7 +10,6 @@ use crate::agent::next_thread_spawn_depth; pub(crate) struct Handler; -#[async_trait] impl ToolHandler for Handler { type Output = SpawnAgentResult; diff --git a/codex-rs/core/src/tools/handlers/multi_agents/wait.rs b/codex-rs/core/src/tools/handlers/multi_agents/wait.rs index 2fe33f1edd3c..8102b9732968 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents/wait.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents/wait.rs @@ -14,7 +14,6 @@ use tokio::time::timeout_at; pub(crate) struct Handler; -#[async_trait] impl ToolHandler for Handler { type Output = WaitAgentResult; diff --git a/codex-rs/core/src/tools/handlers/multi_agents_v2.rs b/codex-rs/core/src/tools/handlers/multi_agents_v2.rs index 44191ed85e8d..51b80e4a7bf7 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents_v2.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents_v2.rs @@ -11,7 +11,6 @@ use crate::tools::handlers::multi_agents_common::*; use crate::tools::handlers::parse_arguments; use crate::tools::registry::ToolHandler; use crate::tools::registry::ToolKind; -use async_trait::async_trait; use codex_protocol::AgentPath; use codex_protocol::models::ResponseInputItem; use codex_protocol::openai_models::ReasoningEffort; diff --git a/codex-rs/core/src/tools/handlers/multi_agents_v2/close_agent.rs b/codex-rs/core/src/tools/handlers/multi_agents_v2/close_agent.rs index 2296ae5dd3ea..8074f7fe04a7 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents_v2/close_agent.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents_v2/close_agent.rs @@ -2,7 +2,6 @@ use super::*; pub(crate) struct Handler; -#[async_trait] impl ToolHandler for Handler { type Output = CloseAgentResult; diff --git a/codex-rs/core/src/tools/handlers/multi_agents_v2/followup_task.rs b/codex-rs/core/src/tools/handlers/multi_agents_v2/followup_task.rs index d0f87f34268b..312e17a31604 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents_v2/followup_task.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents_v2/followup_task.rs @@ -6,7 +6,6 @@ use super::*; pub(crate) struct Handler; -#[async_trait] impl ToolHandler for Handler { type Output = MessageToolResult; diff --git a/codex-rs/core/src/tools/handlers/multi_agents_v2/list_agents.rs b/codex-rs/core/src/tools/handlers/multi_agents_v2/list_agents.rs index b3b3f7160b7a..579c4419931b 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents_v2/list_agents.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents_v2/list_agents.rs @@ -3,7 +3,6 @@ use crate::agent::control::ListedAgent; pub(crate) struct Handler; -#[async_trait] impl ToolHandler for Handler { type Output = ListAgentsResult; diff --git a/codex-rs/core/src/tools/handlers/multi_agents_v2/send_message.rs b/codex-rs/core/src/tools/handlers/multi_agents_v2/send_message.rs index a16aebd4c299..a490d1100dcd 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents_v2/send_message.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents_v2/send_message.rs @@ -6,7 +6,6 @@ use super::*; pub(crate) struct Handler; -#[async_trait] impl ToolHandler for Handler { type Output = MessageToolResult; diff --git a/codex-rs/core/src/tools/handlers/multi_agents_v2/spawn.rs b/codex-rs/core/src/tools/handlers/multi_agents_v2/spawn.rs index 3dc8d7202464..9b3b818513ee 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents_v2/spawn.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents_v2/spawn.rs @@ -11,7 +11,6 @@ use codex_protocol::protocol::Op; pub(crate) struct Handler; -#[async_trait] impl ToolHandler for Handler { type Output = SpawnAgentResult; diff --git a/codex-rs/core/src/tools/handlers/multi_agents_v2/wait.rs b/codex-rs/core/src/tools/handlers/multi_agents_v2/wait.rs index bf3ad8e93409..777fe1c2e764 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents_v2/wait.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents_v2/wait.rs @@ -6,7 +6,6 @@ use tokio::time::timeout_at; pub(crate) struct Handler; -#[async_trait] impl ToolHandler for Handler { type Output = WaitAgentResult; diff --git a/codex-rs/core/src/tools/handlers/plan.rs b/codex-rs/core/src/tools/handlers/plan.rs index ce0b98b1cb93..fb1c708ada9c 100644 --- a/codex-rs/core/src/tools/handlers/plan.rs +++ b/codex-rs/core/src/tools/handlers/plan.rs @@ -6,7 +6,6 @@ use crate::tools::context::ToolOutput; use crate::tools::context::ToolPayload; use crate::tools::registry::ToolHandler; use crate::tools::registry::ToolKind; -use async_trait::async_trait; use codex_protocol::config_types::ModeKind; use codex_protocol::models::FunctionCallOutputPayload; use codex_protocol::models::ResponseInputItem; @@ -44,7 +43,6 @@ impl ToolOutput for PlanToolOutput { } } -#[async_trait] impl ToolHandler for PlanHandler { type Output = PlanToolOutput; diff --git a/codex-rs/core/src/tools/handlers/request_permissions.rs b/codex-rs/core/src/tools/handlers/request_permissions.rs index e0755deac7a9..2590b9d7dd7e 100644 --- a/codex-rs/core/src/tools/handlers/request_permissions.rs +++ b/codex-rs/core/src/tools/handlers/request_permissions.rs @@ -1,4 +1,3 @@ -use async_trait::async_trait; use codex_protocol::request_permissions::RequestPermissionsArgs; use codex_sandboxing::policy_transforms::normalize_additional_permissions; @@ -12,7 +11,6 @@ use crate::tools::registry::ToolKind; pub struct RequestPermissionsHandler; -#[async_trait] impl ToolHandler for RequestPermissionsHandler { type Output = FunctionToolOutput; diff --git a/codex-rs/core/src/tools/handlers/request_user_input.rs b/codex-rs/core/src/tools/handlers/request_user_input.rs index f12defd0e7e9..dcc9445a948e 100644 --- a/codex-rs/core/src/tools/handlers/request_user_input.rs +++ b/codex-rs/core/src/tools/handlers/request_user_input.rs @@ -5,7 +5,6 @@ use crate::tools::context::ToolPayload; use crate::tools::handlers::parse_arguments; use crate::tools::registry::ToolHandler; use crate::tools::registry::ToolKind; -use async_trait::async_trait; use codex_protocol::request_user_input::RequestUserInputArgs; use codex_tools::REQUEST_USER_INPUT_TOOL_NAME; use codex_tools::normalize_request_user_input_args; @@ -15,7 +14,6 @@ pub struct RequestUserInputHandler { pub default_mode_request_user_input: bool, } -#[async_trait] impl ToolHandler for RequestUserInputHandler { type Output = FunctionToolOutput; diff --git a/codex-rs/core/src/tools/handlers/shell.rs b/codex-rs/core/src/tools/handlers/shell.rs index 34cdd5b976e6..6f662ff493c7 100644 --- a/codex-rs/core/src/tools/handlers/shell.rs +++ b/codex-rs/core/src/tools/handlers/shell.rs @@ -1,4 +1,3 @@ -use async_trait::async_trait; use codex_protocol::ThreadId; use codex_protocol::models::ShellCommandToolCallParams; use codex_protocol::models::ShellToolCallParams; @@ -178,7 +177,6 @@ impl From for ShellCommandHandler { } } -#[async_trait] impl ToolHandler for ShellHandler { type Output = FunctionToolOutput; @@ -279,7 +277,6 @@ impl ToolHandler for ShellHandler { } } -#[async_trait] impl ToolHandler for ShellCommandHandler { type Output = FunctionToolOutput; diff --git a/codex-rs/core/src/tools/handlers/test_sync.rs b/codex-rs/core/src/tools/handlers/test_sync.rs index 2d6e351488c5..ad2647243a2a 100644 --- a/codex-rs/core/src/tools/handlers/test_sync.rs +++ b/codex-rs/core/src/tools/handlers/test_sync.rs @@ -4,7 +4,6 @@ use std::sync::Arc; use std::sync::OnceLock; use std::time::Duration; -use async_trait::async_trait; use serde::Deserialize; use tokio::sync::Barrier; use tokio::time::sleep; @@ -54,7 +53,6 @@ fn barrier_map() -> &'static tokio::sync::Mutex> { BARRIERS.get_or_init(|| tokio::sync::Mutex::new(HashMap::new())) } -#[async_trait] impl ToolHandler for TestSyncHandler { type Output = FunctionToolOutput; diff --git a/codex-rs/core/src/tools/handlers/tool_search.rs b/codex-rs/core/src/tools/handlers/tool_search.rs index aa9d8e92f19e..dd203e93b5ef 100644 --- a/codex-rs/core/src/tools/handlers/tool_search.rs +++ b/codex-rs/core/src/tools/handlers/tool_search.rs @@ -4,7 +4,6 @@ use crate::tools::context::ToolPayload; use crate::tools::context::ToolSearchOutput; use crate::tools::registry::ToolHandler; use crate::tools::registry::ToolKind; -use async_trait::async_trait; use bm25::Document; use bm25::Language; use bm25::SearchEngineBuilder; @@ -25,7 +24,6 @@ impl ToolSearchHandler { } } -#[async_trait] impl ToolHandler for ToolSearchHandler { type Output = ToolSearchOutput; diff --git a/codex-rs/core/src/tools/handlers/tool_suggest.rs b/codex-rs/core/src/tools/handlers/tool_suggest.rs index 45c77a350c3b..380aebd51baf 100644 --- a/codex-rs/core/src/tools/handlers/tool_suggest.rs +++ b/codex-rs/core/src/tools/handlers/tool_suggest.rs @@ -1,6 +1,5 @@ use std::collections::HashSet; -use async_trait::async_trait; use codex_app_server_protocol::AppInfo; use codex_mcp::mcp::CODEX_APPS_MCP_SERVER_NAME; use codex_rmcp_client::ElicitationAction; @@ -28,7 +27,6 @@ use crate::tools::registry::ToolKind; pub struct ToolSuggestHandler; -#[async_trait] impl ToolHandler for ToolSuggestHandler { type Output = FunctionToolOutput; diff --git a/codex-rs/core/src/tools/handlers/unified_exec.rs b/codex-rs/core/src/tools/handlers/unified_exec.rs index 98d7d717fced..dfe8c42752f5 100644 --- a/codex-rs/core/src/tools/handlers/unified_exec.rs +++ b/codex-rs/core/src/tools/handlers/unified_exec.rs @@ -22,7 +22,6 @@ use crate::unified_exec::ExecCommandRequest; use crate::unified_exec::UnifiedExecContext; use crate::unified_exec::UnifiedExecProcessManager; use crate::unified_exec::WriteStdinRequest; -use async_trait::async_trait; use codex_features::Feature; use codex_otel::SessionTelemetry; use codex_otel::metrics::names::TOOL_CALL_UNIFIED_EXEC_METRIC; @@ -86,7 +85,6 @@ fn default_tty() -> bool { false } -#[async_trait] impl ToolHandler for UnifiedExecHandler { type Output = ExecCommandToolOutput; diff --git a/codex-rs/core/src/tools/handlers/view_image.rs b/codex-rs/core/src/tools/handlers/view_image.rs index e87638bba6ac..ec34fafb360d 100644 --- a/codex-rs/core/src/tools/handlers/view_image.rs +++ b/codex-rs/core/src/tools/handlers/view_image.rs @@ -1,4 +1,3 @@ -use async_trait::async_trait; use codex_protocol::models::FunctionCallOutputBody; use codex_protocol::models::FunctionCallOutputContentItem; use codex_protocol::models::FunctionCallOutputPayload; @@ -37,7 +36,6 @@ enum ViewImageDetail { Original, } -#[async_trait] impl ToolHandler for ViewImageHandler { type Output = ViewImageOutput; diff --git a/codex-rs/core/src/tools/registry.rs b/codex-rs/core/src/tools/registry.rs index f1ebb38c06c8..2723d8a9a445 100644 --- a/codex-rs/core/src/tools/registry.rs +++ b/codex-rs/core/src/tools/registry.rs @@ -13,7 +13,6 @@ use crate::tools::context::FunctionToolOutput; use crate::tools::context::ToolInvocation; use crate::tools::context::ToolOutput; use crate::tools::context::ToolPayload; -use async_trait::async_trait; use codex_hooks::HookEvent; use codex_hooks::HookEventAfterToolUse; use codex_hooks::HookPayload; @@ -26,6 +25,7 @@ use codex_protocol::protocol::SandboxPolicy; use codex_tools::ConfiguredToolSpec; use codex_tools::ToolSpec; use codex_utils_readiness::Readiness; +use futures::future::BoxFuture; use serde_json::Value; use tracing::warn; @@ -35,7 +35,6 @@ pub enum ToolKind { Mcp, } -#[async_trait] pub trait ToolHandler: Send + Sync { type Output: ToolOutput + 'static; @@ -54,8 +53,11 @@ pub trait ToolHandler: Send + Sync { /// user (through file system, OS operations, ...). /// This function must remains defensive and return `true` if a doubt exist on the /// exact effect of a ToolInvocation. - async fn is_mutating(&self, _invocation: &ToolInvocation) -> bool { - false + fn is_mutating( + &self, + _invocation: &ToolInvocation, + ) -> impl std::future::Future + Send { + async { false } } fn pre_tool_use_payload(&self, _invocation: &ToolInvocation) -> Option { @@ -73,7 +75,10 @@ pub trait ToolHandler: Send + Sync { /// Perform the actual [ToolInvocation] and returns a [ToolOutput] containing /// the final output to return to the model. - async fn handle(&self, invocation: ToolInvocation) -> Result; + fn handle( + &self, + invocation: ToolInvocation, + ) -> impl std::future::Future> + Send; } pub(crate) struct AnyToolResult { @@ -112,11 +117,10 @@ pub(crate) struct PostToolUsePayload { pub(crate) tool_response: Value, } -#[async_trait] trait AnyToolHandler: Send + Sync { fn matches_kind(&self, payload: &ToolPayload) -> bool; - async fn is_mutating(&self, invocation: &ToolInvocation) -> bool; + fn is_mutating<'a>(&'a self, invocation: &'a ToolInvocation) -> BoxFuture<'a, bool>; fn pre_tool_use_payload(&self, invocation: &ToolInvocation) -> Option; @@ -127,13 +131,12 @@ trait AnyToolHandler: Send + Sync { result: &dyn ToolOutput, ) -> Option; - async fn handle_any( - &self, + fn handle_any<'a>( + &'a self, invocation: ToolInvocation, - ) -> Result; + ) -> BoxFuture<'a, Result>; } -#[async_trait] impl AnyToolHandler for T where T: ToolHandler, @@ -142,8 +145,8 @@ where ToolHandler::matches_kind(self, payload) } - async fn is_mutating(&self, invocation: &ToolInvocation) -> bool { - ToolHandler::is_mutating(self, invocation).await + fn is_mutating<'a>(&'a self, invocation: &'a ToolInvocation) -> BoxFuture<'a, bool> { + Box::pin(ToolHandler::is_mutating(self, invocation)) } fn pre_tool_use_payload(&self, invocation: &ToolInvocation) -> Option { @@ -159,17 +162,19 @@ where ToolHandler::post_tool_use_payload(self, call_id, payload, result) } - async fn handle_any( - &self, + fn handle_any<'a>( + &'a self, invocation: ToolInvocation, - ) -> Result { - let call_id = invocation.call_id.clone(); - let payload = invocation.payload.clone(); - let output = self.handle(invocation).await?; - Ok(AnyToolResult { - call_id, - payload, - result: Box::new(output), + ) -> BoxFuture<'a, Result> { + Box::pin(async move { + let call_id = invocation.call_id.clone(); + let payload = invocation.payload.clone(); + let output = self.handle(invocation).await?; + Ok(AnyToolResult { + call_id, + payload, + result: Box::new(output), + }) }) } } diff --git a/codex-rs/core/src/tools/registry_tests.rs b/codex-rs/core/src/tools/registry_tests.rs index 687364872c96..287996d7d870 100644 --- a/codex-rs/core/src/tools/registry_tests.rs +++ b/codex-rs/core/src/tools/registry_tests.rs @@ -1,10 +1,8 @@ use super::*; -use async_trait::async_trait; use pretty_assertions::assert_eq; struct TestHandler; -#[async_trait] impl ToolHandler for TestHandler { type Output = crate::tools::context::FunctionToolOutput;