33 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			33 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package agents
 | 
						|
 | 
						|
import (
 | 
						|
	"context"
 | 
						|
 | 
						|
	gollm "gitea.stevedudenhoeffer.com/steve/go-llm"
 | 
						|
)
 | 
						|
 | 
						|
// SplitQuestion is a utility function that will ask the LLM to split a question into sub-questions.
 | 
						|
// 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) SplitQuestion(ctx context.Context, question string) ([]string, error) {
 | 
						|
	var res []string
 | 
						|
	fnQuestions := gollm.NewFunction(
 | 
						|
		"questions",
 | 
						|
		"split the provided question by the user into sub-questions",
 | 
						|
		func(ctx *gollm.Context, args struct {
 | 
						|
			Questions []string `description:"The questions to evaluate"`
 | 
						|
		}) (any, error) {
 | 
						|
			res = args.Questions
 | 
						|
			return "", nil
 | 
						|
		})
 | 
						|
 | 
						|
	_, err := a.WithSystemPrompt(`The user is going to ask you a question, if the question would be better answered split into multiple questions, please do so.  
 | 
						|
Respond using the "questions" function. 
 | 
						|
If the question is fine as is, respond with the original question passed to the "questions" function.`).
 | 
						|
		WithSystemPromptSuffix(``).
 | 
						|
		WithToolbox(gollm.NewToolBox(fnQuestions)).
 | 
						|
		CallAndExecute(ctx, question)
 | 
						|
 | 
						|
	return res, err
 | 
						|
}
 |