diff options
Diffstat (limited to 'makima/src/server')
| -rw-r--r-- | makima/src/server/handlers/chat.rs | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/makima/src/server/handlers/chat.rs b/makima/src/server/handlers/chat.rs index 158805b..51f17c1 100644 --- a/makima/src/server/handlers/chat.rs +++ b/makima/src/server/handlers/chat.rs @@ -15,7 +15,7 @@ use crate::llm::{ claude::{self, ClaudeClient, ClaudeError, ClaudeModel}, execute_tool_call, groq::{GroqClient, GroqError, Message, ToolCallResponse}, - LlmModel, ToolCall, ToolResult, VersionToolRequest, AVAILABLE_TOOLS, + LlmModel, ToolCall, ToolResult, UserQuestion, VersionToolRequest, AVAILABLE_TOOLS, }; use crate::server::state::{FileUpdateNotification, SharedState}; @@ -66,6 +66,9 @@ pub struct ChatResponse { pub updated_body: Vec<BodyElement>, /// Updated summary (if changed) pub updated_summary: Option<String>, + /// Questions pending user answers (pauses conversation) + #[serde(skip_serializing_if = "Option::is_none")] + pub pending_questions: Option<Vec<UserQuestion>>, } #[derive(Debug, Serialize, ToSchema)] @@ -326,6 +329,8 @@ You have access to tools for: // Track consecutive failures for agentic retry logic let mut consecutive_failures = 0; const MAX_CONSECUTIVE_FAILURES: usize = 3; + // Track pending user questions (pauses the conversation) + let mut pending_questions: Option<Vec<UserQuestion>> = None; // Multi-turn agentic tool calling loop for round in 0..MAX_TOOL_ROUNDS { @@ -508,6 +513,21 @@ You have access to tools for: ); } + // Check for pending user questions (pauses the conversation) + if let Some(questions) = execution_result.pending_questions { + tracing::info!( + question_count = questions.len(), + "LLM requesting user input, pausing conversation" + ); + pending_questions = Some(questions); + // Track this tool call before breaking + all_tool_call_infos.push(ToolCallInfo { + name: tool_call.name.clone(), + result: execution_result.result, + }); + break; // Exit inner loop + } + // Build tool result message content with enhanced context for agentic reasoning let result_content = if let Some(parsed_data) = &execution_result.parsed_data { // Include parsed data in the result for the LLM to use @@ -559,6 +579,12 @@ You have access to tools for: }); } + // If user questions are pending, pause the conversation + if pending_questions.is_some() { + final_response = result.content; + break; + } + // If finish reason indicates completion, exit loop let finish_lower = result.finish_reason.to_lowercase(); if finish_lower == "stop" || finish_lower == "end_turn" { @@ -637,6 +663,7 @@ You have access to tools for: tool_calls: all_tool_call_infos, updated_body: current_body, updated_summary: current_summary, + pending_questions, }), ) .into_response() |
