Execute with planning phase. If `pre_analysis` is provided (from a single pre-analysis LLM call in `execute_with_session`), the goal and plan are already available and no additional LLM calls are needed for planning. Otherwise, falls back to calling `extract_goal` and `plan` individually.
(
&self,
history: &[Message],
prompt: &str,
session_id: Option<&str>,
event_tx: Option<mpsc::Sender<AgentEvent>>,
pre_analysis: Option<PreAnalysis>,
| 59 | /// additional LLM calls are needed for planning. Otherwise, falls back to |
| 60 | /// calling `extract_goal` and `plan` individually. |
| 61 | pub async fn execute_with_planning( |
| 62 | &self, |
| 63 | history: &[Message], |
| 64 | prompt: &str, |
| 65 | session_id: Option<&str>, |
| 66 | event_tx: Option<mpsc::Sender<AgentEvent>>, |
| 67 | pre_analysis: Option<PreAnalysis>, |
| 68 | ) -> Result<AgentResult> { |
| 69 | // Send planning start event |
| 70 | if let Some(tx) = &event_tx { |
| 71 | tx.send(AgentEvent::PlanningStart { |
| 72 | prompt: prompt.to_string(), |
| 73 | }) |
| 74 | .await |
| 75 | .ok(); |
| 76 | } |
| 77 | |
| 78 | // Use pre-analysis result if available (goal + plan already computed in one LLM call). |
| 79 | let (goal, plan) = if let Some(analysis) = pre_analysis { |
| 80 | ( |
| 81 | Some(analysis.goal.clone()), |
| 82 | Self::preserve_plan_goal_context(analysis.execution_plan.clone(), prompt), |
| 83 | ) |
| 84 | } else { |
| 85 | // Fall back: extract goal and create plan via separate LLM calls. |
| 86 | let g = if self.config.goal_tracking { |
| 87 | Some(self.extract_goal(prompt).await?) |
| 88 | } else { |
| 89 | None |
| 90 | }; |
| 91 | let p = self.plan(prompt, None).await?; |
| 92 | (g, p) |
| 93 | }; |
| 94 | |
| 95 | // Send GoalExtracted event if goal_tracking is enabled. |
| 96 | if self.config.goal_tracking { |
| 97 | if let Some(ref g) = goal { |
| 98 | if let Some(tx) = &event_tx { |
| 99 | tx.send(AgentEvent::GoalExtracted { goal: g.clone() }) |
| 100 | .await |
| 101 | .ok(); |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | // Send planning end event |
| 107 | if let Some(tx) = &event_tx { |
| 108 | tx.send(AgentEvent::PlanningEnd { |
| 109 | estimated_steps: plan.steps.len(), |
| 110 | plan: plan.clone(), |
| 111 | }) |
| 112 | .await |
| 113 | .ok(); |
| 114 | } |
| 115 | |
| 116 | let plan_start = std::time::Instant::now(); |
| 117 | |
| 118 | // Execute the plan step by step |
no test coverage detected