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

@ -404,6 +404,14 @@ impl BotOrchestrator {
format!("Erro ao executar '{}': {}", tool_name, tool_result.error.unwrap_or_default())
};
let trimmed_result = response_content.trim();
let has_kb = crate::basic::keywords::use_kb::get_active_kbs_for_session(
&self.state.conn, session_id
).unwrap_or_default();
if !has_kb.is_empty() && (trimmed_result.is_empty() || trimmed_result.eq_ignore_ascii_case(tool_name)) {
info!("[TOOL_EXEC] Tool '{}' activated KB, falling through to LLM pipeline", tool_name);
} else {
let final_response = BotResponse {
bot_id: message.bot_id.clone(),
user_id: message.user_id.clone(),
@ -423,6 +431,7 @@ impl BotOrchestrator {
return Ok(());
}
}
}
// Legacy: Handle direct tool invocation via __TOOL__: prefix
if message_content.starts_with("__TOOL__:") {