headless_lms_chatbot/azure_chatbot/client_tool_calls/
abort.rs1use crate::chatbot_tools::ClientToolCallRefusal;
5use crate::prelude::*;
6
7pub(crate) enum ToolCallAbortReason {
9 Hanging,
11 Replaced,
13 NotAuthorized,
16 CategoryDisabled,
19}
20
21impl ToolCallAbortReason {
22 pub(crate) fn model_output(&self) -> &'static str {
26 match self {
27 Self::Hanging => "Unexpected error encountered, tool call aborted.",
28 Self::Replaced => {
29 "The user sent a new message instead of answering this tool call, so it was never carried out and returned no data. Answer their new message; ask again only if you still need this."
30 }
31 Self::NotAuthorized => {
32 "The tool call was aborted and returned no data, because the user is not allowed to use this tool on what the call named. Do not call this tool again in this conversation. Answer without it, or tell the user that you cannot do that step for them."
33 }
34 Self::CategoryDisabled => {
35 "The tool call was aborted and returned no data, because this chatbot no longer offers this kind of tool: its configuration changed while the call was waiting for them. Do not call this tool again in this conversation. Answer without it, or tell the user that you cannot do that step for them."
36 }
37 }
38 }
39}
40
41pub(crate) fn refused_call_output(refusal: ClientToolCallRefusal, tool_name: &str) -> &'static str {
47 match refusal {
48 ClientToolCallRefusal::NotAuthorized => {
49 warn!(
50 tool_name,
51 "Aborting a chatbot tool call: its caller is not allowed to make it"
52 );
53 ToolCallAbortReason::NotAuthorized.model_output()
54 }
55 ClientToolCallRefusal::CategoryDisabled => {
56 warn!(
57 tool_name,
58 "Aborting a chatbot tool call: its category is no longer enabled on the chatbot configuration"
59 );
60 ToolCallAbortReason::CategoryDisabled.model_output()
61 }
62 }
63}