restructured answers a bit

This commit is contained in:
2025-03-01 01:25:34 -05:00
parent 090b28d956
commit ff1c369772
11 changed files with 114 additions and 43 deletions

View File

@@ -3,12 +3,14 @@ package agent
import (
"encoding/json"
"fmt"
"gitea.stevedudenhoeffer.com/steve/answer/pkg/toolbox"
)
var AskTool = FromFunction(
var AskTool = toolbox.FromFunction(
func(ctx *Context, args struct {
Question string `description:"the question to answer"`
}) (FuncResponse, error) {
}) (toolbox.FuncResponse, error) {
var q Question
q.Question = args.Question
@@ -17,15 +19,15 @@ var AskTool = FromFunction(
answers, err := ask(ctx, q)
if err != nil {
return FuncResponse{}, err
return toolbox.FuncResponse{}, err
}
tb := ToolBox{}
tb := toolbox.ToolBox{}
tb.Register(SummarizeAnswers)
b, err := json.Marshal(answers.Answers)
if err != nil {
return FuncResponse{}, fmt.Errorf("failed to marshal answers: %w", err)
return toolbox.FuncResponse{}, fmt.Errorf("failed to marshal answers: %w", err)
}
q = Question{Question: string(b)}
@@ -33,14 +35,14 @@ var AskTool = FromFunction(
answers, err = tb.Run(ctx, q)
if err != nil {
return FuncResponse{}, fmt.Errorf("failed to summarize answers: %w", err)
return toolbox.FuncResponse{}, fmt.Errorf("failed to summarize answers: %w", err)
}
if len(answers.Answers) == 0 {
return FuncResponse{}, fmt.Errorf("no response from model")
return toolbox.FuncResponse{}, fmt.Errorf("no response from model")
}
return FuncResponse{Result: answers.Answers[0].Answer}, nil
return toolbox.FuncResponse{Result: answers.Answers[0].Answer}, nil
}).
WithName("ask").
WithDescription("Ask the agent a question, this is useful for splitting a question into multiple parts")