Skip to content

Commit d906314

Browse files
0xrinegadeclaude
andcommitted
fix: only use finalization prompt when plan was actually executed
Corrected finalization logic: ❌ Previous (wrong): - Used finalization prompt for direct queries (no execution) - Normal query path had no finalization ✅ Now (correct): - Direct queries (no execution) → normal AI response - Tool execution results → finalization with ownPlan:true Logic flow: 1. If no tools executed → query_with_debug() for normal response 2. If tools executed → query_osvm_ai_with_options() with: - Finalization system prompt - ownPlan: true (prevents server from executing) - Formatted execution results to finalize This ensures finalization ONLY happens after plan execution, not for regular conversational queries. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 57ef717 commit d906314

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

src/utils/streaming_agent.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -868,17 +868,31 @@ pub async fn execute_streaming_agent(query: &str, verbose: u8) -> Result<()> {
868868
.collect();
869869

870870
if tool_results_for_ai.is_empty() && tool_plan.osvm_tools_to_use.is_empty() {
871-
// No tools - direct response
871+
// No tools - direct response (no execution happened)
872+
match ai_service.query_with_debug(query, verbose > 1).await {
873+
Ok(resp) => {
874+
println!(" ✅");
875+
resp
876+
}
877+
Err(e) => {
878+
println!(" ❌");
879+
eprintln!("❌ Failed to generate response: {}", e);
880+
format!("Error: {}", e)
881+
}
882+
}
883+
} else {
884+
// Format results from tool execution - use finalization prompt
872885
let finalization_prompt = format!(
873886
"You are finalizing the answer to this user query: \"{}\"\n\n\
874-
The execution has completed. Your task is to:\n\
875-
1. Format the results in a clear, human-readable way\n\
887+
Plan execution has completed. Your task is to:\n\
888+
1. Format the execution results in a clear, human-readable way\n\
876889
2. Directly answer the user's question based on the data\n\
877890
3. DO NOT generate any new plans or code\n\
878891
4. DO NOT suggest additional steps or actions\n\
879892
5. Just present the final answer clearly and concisely\n\n\
880-
Results to format:\n{:?}",
881-
query, tool_results_for_ai
893+
Execution results to format:\n{}",
894+
query,
895+
format_plan_execution_results(&tool_plan, &tool_results_for_ai)
882896
);
883897

884898
match ai_service.query_osvm_ai_with_options(
@@ -893,14 +907,11 @@ pub async fn execute_streaming_agent(query: &str, verbose: u8) -> Result<()> {
893907
}
894908
Err(e) => {
895909
println!(" ❌");
896-
eprintln!("❌ Failed to generate response: {}", e);
897-
format!("Error: {}", e)
910+
eprintln!("❌ Failed to finalize results: {}", e);
911+
// Fallback to raw formatted results if finalization fails
912+
format_plan_execution_results(&tool_plan, &tool_results_for_ai)
898913
}
899914
}
900-
} else {
901-
// Format results from tool execution
902-
println!(" ✅");
903-
format_plan_execution_results(&tool_plan, &tool_results_for_ai)
904915
}
905916
};
906917

0 commit comments

Comments
 (0)