steer_core/app/
context_util.rs1use std::sync::Arc;
2use tokio_util::sync::CancellationToken;
3use tracing::{debug, warn};
4
5use crate::api::ToolCall;
6use crate::app::ToolExecutor;
7use steer_tools::result::ToolResult;
8
9pub async fn execute_tool_task_logic(
15 tool_call: ToolCall,
16 tool_executor: Arc<ToolExecutor>,
17 token: CancellationToken,
21) -> std::result::Result<ToolResult, steer_tools::ToolError> {
22 let tool_id = tool_call.id.clone();
24 let tool_name = tool_call.name.clone();
25
26 debug!(
27 target: "app.context_util.execute_tool_task_logic",
28 "Executing tool {} (ID: {}) logic", tool_name, tool_id,
29 );
30
31 if token.is_cancelled() {
33 return Err(steer_tools::ToolError::Cancelled(format!(
35 "{tool_name} ({tool_id})"
36 )));
37 }
38
39 let result = tool_executor
41 .execute_tool_with_cancellation(&tool_call, token)
42 .await;
43
44 match &result {
46 Ok(output) => debug!(
47 target:"app.context_util.execute_tool_task_logic",
48 "Tool {} ({}) completed successfully. Output type: {:?}",
49 tool_name,
50 tool_id,
51 std::mem::discriminant(output),
52 ),
53 Err(e) => warn!(
54 target:"app.context_util.execute_tool_task_logic",
55 "Tool {} ({}) failed: {}", tool_name, tool_id, e,
56 ),
57 }
58
59 result
61}