(
&self,
history: &[Message],
msg_prompt: &str,
effective_prompt: &str,
effective_style: Option<AgentStyle>,
session_id: Option<&str>,
event_tx:
| 49 | /// (should be false when called from `execute_plan` to avoid duplicate End events). |
| 50 | #[allow(clippy::too_many_arguments)] |
| 51 | pub(super) async fn execute_loop_inner( |
| 52 | &self, |
| 53 | history: &[Message], |
| 54 | msg_prompt: &str, |
| 55 | effective_prompt: &str, |
| 56 | effective_style: Option<AgentStyle>, |
| 57 | session_id: Option<&str>, |
| 58 | event_tx: Option<mpsc::Sender<AgentEvent>>, |
| 59 | cancel_token: &tokio_util::sync::CancellationToken, |
| 60 | emit_end: bool, |
| 61 | seed: Option<super::execution_state::ExecutionSeed>, |
| 62 | ) -> Result<AgentResult> { |
| 63 | let mut state = ExecutionLoopState::new_seeded(history, seed); |
| 64 | |
| 65 | let style_prompt = if effective_prompt.is_empty() { |
| 66 | msg_prompt |
| 67 | } else { |
| 68 | effective_prompt |
| 69 | }; |
| 70 | let prompt_mode = self |
| 71 | .resolve_prompt_mode(effective_style, style_prompt, &event_tx) |
| 72 | .await; |
| 73 | let effective_system_prompt = prompt_mode.system_prompt; |
| 74 | |
| 75 | // Send start event |
| 76 | if let Some(tx) = &event_tx { |
| 77 | tx.send(AgentEvent::Start { |
| 78 | prompt: effective_prompt.to_string(), |
| 79 | }) |
| 80 | .await |
| 81 | .ok(); |
| 82 | } |
| 83 | |
| 84 | let _queue_forwarder = QueueEventForwarder::start( |
| 85 | self.command_queue.as_ref(), |
| 86 | event_tx.as_ref(), |
| 87 | cancel_token, |
| 88 | ); |
| 89 | |
| 90 | let turn_context = self |
| 91 | .prepare_turn_context( |
| 92 | &effective_system_prompt, |
| 93 | effective_prompt, |
| 94 | state.messages.len(), |
| 95 | session_id, |
| 96 | &event_tx, |
| 97 | ) |
| 98 | .await; |
| 99 | let effective_prompt = turn_context.effective_prompt.as_str(); |
| 100 | let augmented_system = turn_context.augmented_system; |
| 101 | |
| 102 | // Add user message |
| 103 | if !msg_prompt.is_empty() { |
| 104 | state.messages.push(Message::user(msg_prompt)); |
| 105 | } |
| 106 | |
| 107 | loop { |
| 108 | let llm_turn = match self |
no test coverage detected