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,
&user_id,
).await;
let response_content = if tool_result.success {
tool_result.result
} else {
format!("Erro ao executar '{}': {}", tool_name, tool_result.error.unwrap_or_default())
};
let final_response = BotResponse {
bot_id: message.bot_id.clone(),
user_id: message.user_id.clone(),
session_id: message.session_id.clone(),
channel: message.channel.clone(),
content: response_content,
message_type: MessageType::BOT_RESPONSE,
stream_token: None,
is_complete: true,
suggestions: vec![],
context_name: None,
context_length: 0,
context_max_length: 0,
};
let _ = response_tx.send(final_response).await;
return Ok(());
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(),
session_id: message.session_id.clone(),
channel: message.channel.clone(),
content: response_content,
message_type: MessageType::BOT_RESPONSE,
stream_token: None,
is_complete: true,
suggestions: vec![],
context_name: None,
context_length: 0,
context_max_length: 0,
};
let _ = response_tx.send(final_response).await;
return Ok(());
}
}
}