MCPcopy Create free account
hub / github.com/AI45Lab/Code / parse_pre_analysis_response

Method parse_pre_analysis_response

core/src/planning/llm_planner.rs:251–304  ·  view source on GitHub ↗
(text: &str, original_prompt: &str)

Source from the content-addressed store, hash-verified

249 }
250
251 fn parse_pre_analysis_response(text: &str, original_prompt: &str) -> Result<PreAnalysis> {
252 let parsed: PreAnalysisResponse = Self::parse_json_lenient(text)
253 .context("Failed to parse pre-analysis JSON from LLM response")?;
254
255 let intent = match parsed.intent.to_lowercase().as_str() {
256 "plan" => crate::prompts::AgentStyle::Plan,
257 "explore" => crate::prompts::AgentStyle::Explore,
258 "verification" => crate::prompts::AgentStyle::Verification,
259 "codereview" | "code review" => crate::prompts::AgentStyle::CodeReview,
260 _ => crate::prompts::AgentStyle::GeneralPurpose,
261 };
262
263 let goal_description = parsed.goal.description.clone();
264 let goal =
265 AgentGoal::new(goal_description.clone()).with_criteria(parsed.goal.success_criteria);
266
267 let complexity = match parsed.execution_plan.complexity.as_str() {
268 "Simple" => Complexity::Simple,
269 "Medium" => Complexity::Medium,
270 "Complex" => Complexity::Complex,
271 "VeryComplex" => Complexity::VeryComplex,
272 _ => Complexity::Medium,
273 };
274
275 let mut plan = ExecutionPlan::new(goal_description, complexity);
276 for step_resp in parsed.execution_plan.steps {
277 let mut task = Task::new(step_resp.id, step_resp.description);
278 if let Some(tool) = step_resp.tool {
279 task = task.with_tool(tool);
280 }
281 if !step_resp.dependencies.is_empty() {
282 task = task.with_dependencies(step_resp.dependencies);
283 }
284 if let Some(criteria) = step_resp.success_criteria {
285 task = task.with_success_criteria(criteria);
286 }
287 plan.add_step(task);
288 }
289 for tool in parsed.execution_plan.required_tools {
290 plan.add_required_tool(tool);
291 }
292
293 Ok(PreAnalysis {
294 intent,
295 requires_planning: parsed.requires_planning,
296 goal,
297 execution_plan: plan,
298 optimized_input: if parsed.optimized_input.is_empty() {
299 original_prompt.to_string()
300 } else {
301 parsed.optimized_input
302 },
303 })
304 }
305
306 // ========================================================================
307 // JSON parsing helpers

Callers

nothing calls this directly

Calls 10

contextMethod · 0.80
with_criteriaMethod · 0.80
with_dependenciesMethod · 0.80
with_success_criteriaMethod · 0.80
add_stepMethod · 0.80
add_required_toolMethod · 0.80
as_strMethod · 0.45
cloneMethod · 0.45
with_toolMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected