answer/pkg/agents/steps.go

30 lines
1.1 KiB
Go

package agents
import (
"context"
gollm "gitea.stevedudenhoeffer.com/steve/go-llm"
)
// Steps is a utility function that will ask the LLM to split a goal into smaller steps.
// It is a utility function and as such it does not use the agent's set system prompts, it will however use any
// contextual information that it has.
func (a Agent) Steps(ctx context.Context, goal string) ([]string, error) {
var res []string
fnSteps := gollm.NewFunction(
"steps",
"split the provided goal by the user into sub-steps",
func(ctx *gollm.Context, args struct {
Steps []string `description:"The steps that should be taken to achieve the goal"`
}) (any, error) {
res = append(res, args.Steps...)
return "", nil
})
_, err := a.WithSystemPrompt(`The user is going to mention a goal to you, and you are to respond using only one call of the "steps" function. You should provide the "steps" function with steps that should be taken to achieve the goal the user requests.`).
WithSystemPromptSuffix(``).
WithToolbox(gollm.NewToolBox(fnSteps)).
CallAndExecute(ctx, goal)
return res, err
}