SimpleChatTC: Trap any exception raised during tool call

and inform the GenAi/LLM about the same
This commit is contained in:
hanishkvc 2025-10-12 02:53:08 +05:30
parent 17c5daa52c
commit b4776da670
2 changed files with 8 additions and 2 deletions

View File

@ -536,8 +536,12 @@ class SimpleChat {
}
for (const fn in tools.tc_switch) {
if (fn == toolname) {
tools.tc_switch[fn]["handler"](JSON.parse(ar.response.toolargs))
return tools.tc_switch[fn]["result"]
try {
tools.tc_switch[fn]["handler"](JSON.parse(ar.response.toolargs))
return tools.tc_switch[fn]["result"]
} catch (error) {
return `Tool/Function call raised an exception:${error.name}:${error.message}`
}
}
}
return `Unknown Tool/Function Call:${toolname}`

View File

@ -73,10 +73,12 @@ exit
"content": "what is your name."
"content": "What and all tools you have access to"
"content": "do you have access to any tools"
"content": "Print a hello world message with python."
"content": "Print a hello world message with javascript."
"content": "Calculate the sum of 5 and 27."
"content": "Can you get me todays date."
"content": "Can you get me a summary of latest news from bbc world"
"content": "Can you get todays date. And inturn add 10 to todays date"
"content": "Who is known as father of the nation in India, also is there a similar figure for USA as well as UK"
"content": "Who is known as father of the nation in India, Add 10 to double his year of birth and show me the results."