fix: TOOL_EXEC with USE KB now falls through to LLM pipeline for KB-injected response
All checks were successful
BotServer CI/CD / build (push) Successful in 3m50s

When a tool button like Cartas activates a KB via USE KB, instead of
returning just the tool result (empty/label), the handler now checks
if session has active KBs. If so and result is empty/trivial,
falls through to the full LLM pipeline which injects KB context.
This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2026-04-13 10:02:47 -03:00
parent 1f77d7f099
commit e98dc47ea1

View file

@ -397,30 +397,39 @@ impl BotOrchestrator {
&session_id, &session_id,
&user_id, &user_id,
).await; ).await;
let response_content = if tool_result.success { let response_content = if tool_result.success {
tool_result.result tool_result.result
} else { } else {
format!("Erro ao executar '{}': {}", tool_name, tool_result.error.unwrap_or_default()) format!("Erro ao executar '{}': {}", tool_name, tool_result.error.unwrap_or_default())
}; };
let final_response = BotResponse { let trimmed_result = response_content.trim();
bot_id: message.bot_id.clone(), let has_kb = crate::basic::keywords::use_kb::get_active_kbs_for_session(
user_id: message.user_id.clone(), &self.state.conn, session_id
session_id: message.session_id.clone(), ).unwrap_or_default();
channel: message.channel.clone(),
content: response_content, if !has_kb.is_empty() && (trimmed_result.is_empty() || trimmed_result.eq_ignore_ascii_case(tool_name)) {
message_type: MessageType::BOT_RESPONSE, info!("[TOOL_EXEC] Tool '{}' activated KB, falling through to LLM pipeline", tool_name);
stream_token: None, } else {
is_complete: true, let final_response = BotResponse {
suggestions: vec![], bot_id: message.bot_id.clone(),
context_name: None, user_id: message.user_id.clone(),
context_length: 0, session_id: message.session_id.clone(),
context_max_length: 0, channel: message.channel.clone(),
}; content: response_content,
message_type: MessageType::BOT_RESPONSE,
let _ = response_tx.send(final_response).await; stream_token: None,
return Ok(()); is_complete: true,
suggestions: vec![],
context_name: None,
context_length: 0,
context_max_length: 0,
};
let _ = response_tx.send(final_response).await;
return Ok(());
}
} }
} }