Refactor function registration in knowledgeworker to use WithFunctions method

This commit is contained in:
Steve Dudenhoeffer 2025-04-12 02:30:01 -04:00
parent 1be5cc047c
commit 1447b73dfb

View File

@ -3,9 +3,10 @@ package shared
import ( import (
"context" "context"
"fmt" "fmt"
"gitea.stevedudenhoeffer.com/steve/answer/pkg/agents"
"strings" "strings"
"gitea.stevedudenhoeffer.com/steve/answer/pkg/agents"
gollm "gitea.stevedudenhoeffer.com/steve/go-llm" gollm "gitea.stevedudenhoeffer.com/steve/go-llm"
) )
@ -72,8 +73,8 @@ func (w KnowledgeWorker) Answer(context context.Context, knowledge *agents.Knowl
Text: lastMsg, Text: lastMsg,
}) })
req.Toolbox = w.ToolBox. req.Toolbox = w.ToolBox.WithFunctions(
WithFunction(*gollm.NewFunction( gollm.NewFunction(
"notes_to_self", "notes_to_self",
"leave future executions of the LLM a note or two, can be called many times", "leave future executions of the LLM a note or two, can be called many times",
func(ctx *gollm.Context, args struct { func(ctx *gollm.Context, args struct {
@ -82,8 +83,8 @@ func (w KnowledgeWorker) Answer(context context.Context, knowledge *agents.Knowl
return agents.Knowledge{ return agents.Knowledge{
NotesToSelf: args.NotesToSelf, NotesToSelf: args.NotesToSelf,
}, nil }, nil
})). }),
WithFunction(*gollm.NewFunction( gollm.NewFunction(
"new_objectives", "new_objectives",
"Set new objectives for the LLM to work on, can be called many times. If no new objectives are set, the LLM will continue to work on the current objectives.", "Set new objectives for the LLM to work on, can be called many times. If no new objectives are set, the LLM will continue to work on the current objectives.",
func(ctx *gollm.Context, args struct { func(ctx *gollm.Context, args struct {
@ -92,8 +93,8 @@ func (w KnowledgeWorker) Answer(context context.Context, knowledge *agents.Knowl
return agents.Knowledge{ return agents.Knowledge{
CurrentObjectives: args.Objectives, CurrentObjectives: args.Objectives,
}, nil }, nil
})). }),
WithFunction(*gollm.NewFunction( gollm.NewFunction(
"learn", "learn",
`Use learn to pass some relevant information to the model. The model will use this information to answer the question. Use it to learn relevant information from the text. Keep these concise and relevant to the question. Can be called many times.`, `Use learn to pass some relevant information to the model. The model will use this information to answer the question. Use it to learn relevant information from the text. Keep these concise and relevant to the question. Can be called many times.`,
func(ctx *gollm.Context, args struct { func(ctx *gollm.Context, args struct {