Orchestrator + Tooling rework #4

Merged
JohnCosta27 merged 17 commits from feat/orchestrator into main 2025-04-09 17:00:53 +01:00
12 changed files with 785 additions and 940 deletions
Showing only changes of commit f5f4008034 - Show all commits

View File

@ -22,6 +22,8 @@ type ToolsHandlers struct {
var NoToolCallError = errors.New("An assistant tool call with no tool calls was provided.")
const NonExistantTool = "This tool does not exist"
func (handler ToolsHandlers) Handle(info ToolHandlerInfo, toolCallMessage AgentAssistantToolCall) ([]AgentTextMessage, error) {
if len(toolCallMessage.ToolCalls) == 0 {
return []AgentTextMessage{}, NoToolCallError
@ -33,19 +35,21 @@ func (handler ToolsHandlers) Handle(info ToolHandlerInfo, toolCallMessage AgentA
fnName := toolCall.Function.Name
arguments := toolCall.Function.Arguments
fnHandler, exists := handler.handlers[fnName]
if !exists {
return []AgentTextMessage{}, errors.New("Could not find tool with this name.")
}
res, err := fnHandler.Fn(info, arguments, toolCallMessage.ToolCalls[0])
responseMessage := AgentTextMessage{
Role: "tool",
Name: fnName,
ToolCallId: toolCall.Id,
}
fnHandler, exists := handler.handlers[fnName]
if !exists {
responseMessage.Content = NonExistantTool
responses[i] = responseMessage
continue
}
res, err := fnHandler.Fn(info, arguments, toolCallMessage.ToolCalls[0])
if err != nil {
responseMessage.Content = err.Error()
} else {

View File

@ -151,6 +151,14 @@ func (suite *ToolTestSuite) TestMultipleToolCallsWithErrors() {
{
Index: 1,
Id: "2",
Function: FunctionCall{
Name: "non-existant",
Arguments: "",
},
},
{
Index: 2,
Id: "3",
Function: FunctionCall{
Name: "a",
Arguments: "no-error",
@ -170,8 +178,14 @@ func (suite *ToolTestSuite) TestMultipleToolCallsWithErrors() {
},
{
Role: "tool",
Content: "\"no-error\"",
Content: "This tool does not exist",
ToolCallId: "2",
Name: "non-existant",
},
{
Role: "tool",
Content: "\"no-error\"",
ToolCallId: "3",
Name: "a",
},
})