Request confirmation for a tool execution Returns a receiver that will receive the confirmation response. Emits a ConfirmationRequired event.
(
&self,
tool_id: &str,
tool_name: &str,
args: &serde_json::Value,
)
| 236 | /// Returns a receiver that will receive the confirmation response. |
| 237 | /// Emits a ConfirmationRequired event. |
| 238 | pub async fn request_confirmation( |
| 239 | &self, |
| 240 | tool_id: &str, |
| 241 | tool_name: &str, |
| 242 | args: &serde_json::Value, |
| 243 | ) -> oneshot::Receiver<ConfirmationResponse> { |
| 244 | let (tx, rx) = oneshot::channel(); |
| 245 | |
| 246 | let policy = self.policy.read().await; |
| 247 | let timeout_ms = policy.default_timeout_ms; |
| 248 | drop(policy); |
| 249 | |
| 250 | let pending = PendingConfirmation { |
| 251 | tool_id: tool_id.to_string(), |
| 252 | tool_name: tool_name.to_string(), |
| 253 | args: args.clone(), |
| 254 | created_at: Instant::now(), |
| 255 | timeout_ms, |
| 256 | response_tx: tx, |
| 257 | }; |
| 258 | |
| 259 | // Store the pending confirmation |
| 260 | { |
| 261 | let mut pending_map = self.pending.write().await; |
| 262 | pending_map.insert(tool_id.to_string(), pending); |
| 263 | } |
| 264 | |
| 265 | // Emit confirmation required event |
| 266 | let _ = self.event_tx.send(AgentEvent::ConfirmationRequired { |
| 267 | tool_id: tool_id.to_string(), |
| 268 | tool_name: tool_name.to_string(), |
| 269 | args: args.clone(), |
| 270 | timeout_ms, |
| 271 | }); |
| 272 | |
| 273 | rx |
| 274 | } |
| 275 | |
| 276 | /// Handle a confirmation response from the user |
| 277 | /// |