(
&self,
tool_calls: &[ToolCall],
state: &mut ExecutionLoopState,
event_tx: &Option<mpsc::Sender<AgentEvent>>,
)
| 9 | |
| 10 | impl AgentLoop { |
| 11 | pub(super) async fn execute_parallel_write_batch( |
| 12 | &self, |
| 13 | tool_calls: &[ToolCall], |
| 14 | state: &mut ExecutionLoopState, |
| 15 | event_tx: &Option<mpsc::Sender<AgentEvent>>, |
| 16 | ) { |
| 17 | tracing::info!( |
| 18 | count = tool_calls.len(), |
| 19 | "Parallel write batch: executing {} independent file writes concurrently", |
| 20 | tool_calls.len() |
| 21 | ); |
| 22 | |
| 23 | let tool_calls = tool_calls.to_vec(); |
| 24 | let tool_context = self.tool_context.clone(); |
| 25 | let tool_executor = Arc::clone(&self.tool_executor); |
| 26 | let results = crate::ordered_parallel::run_ordered_parallel_with_limit( |
| 27 | tool_calls.clone(), |
| 28 | self.config.max_parallel_tasks, |
| 29 | { |
| 30 | let tool_context = tool_context.clone(); |
| 31 | let tool_executor = Arc::clone(&tool_executor); |
| 32 | move |_index, tc| { |
| 33 | let ctx = tool_context.clone(); |
| 34 | let executor = Arc::clone(&tool_executor); |
| 35 | let name = tc.name.clone(); |
| 36 | let args = tc.args.clone(); |
| 37 | async move { executor.execute_with_context(&name, &args, &ctx).await } |
| 38 | } |
| 39 | }, |
| 40 | ) |
| 41 | .await; |
| 42 | |
| 43 | for (tc, result) in tool_calls.iter().zip(results) { |
| 44 | state.record_tool_call(); |
| 45 | let execution_result = match result.output { |
| 46 | Ok(result) => result, |
| 47 | Err(error) => Err(anyhow::anyhow!("parallel tool execution failed: {}", error)), |
| 48 | }; |
| 49 | let normalized = NormalizedToolResult::from_execution(execution_result); |
| 50 | Self::collect_verification_report( |
| 51 | &mut state.verification_reports, |
| 52 | &normalized.metadata, |
| 53 | ); |
| 54 | self.track_tool_result(&tc.name, &tc.args, normalized.exit_code); |
| 55 | |
| 56 | let output = if let Some(ref sp) = self.config.security_provider { |
| 57 | sp.sanitize_output(&normalized.output) |
| 58 | } else { |
| 59 | normalized.output.clone() |
| 60 | }; |
| 61 | |
| 62 | if let Some(tx) = event_tx { |
| 63 | tx.send(AgentEvent::ToolEnd { |
| 64 | id: tc.id.clone(), |
| 65 | name: tc.name.clone(), |
| 66 | output: output.clone(), |
| 67 | exit_code: normalized.exit_code, |
| 68 | metadata: normalized.metadata.clone(), |
no test coverage detected