Documentation
¶
Overview ¶
Package agents holds the logic for the ReAct agent.
Index ¶
- Variables
- func DefaultRules() []string
- func NewCLILogger[TOut any](p predictors.Predictor[PromptData[TOut], Reasoning[TOut]], out io.Writer, ...) predictors.Predictor[PromptData[TOut], Reasoning[TOut]]
- func NewDefaultParser[TOut any]() parsers.Parser[Reasoning[TOut]]
- func NewDefaultPrompt[TLLMParams, TOut any](params TLLMParams, opts ...prompters.Option[PromptData[TOut]]) prompters.Prompter[PromptData[TOut], TLLMParams]
- func WithCLILoggerPrefix[TOut any](prefix string) func(*cliLogger[TOut])
- func WithExamples[TLLMParams, TOut any](examples ...PromptDataExample[TOut]) prompters.Option[PromptData[TOut]]
- func WithPreamble[TLLMParams, TOut any](preamble string) prompters.Option[PromptData[TOut]]
- func WithRules[TLLMParams, TOut any](rules ...string) prompters.Option[PromptData[TOut]]
- type Agent
- type CLILoggerOption
- type PromptData
- type PromptDataExample
- type Reasoning
- type ThoughtIteration
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidTool = errors.New("invalid tool")
ErrInvalidTool is returned when a tool is not found.
Functions ¶
func DefaultRules ¶
func DefaultRules() []string
DefaultRules are the default rules for the ReAct loop.
func NewCLILogger ¶
func NewCLILogger[TOut any]( p predictors.Predictor[PromptData[TOut], Reasoning[TOut]], out io.Writer, opts ...CLILoggerOption[TOut], ) predictors.Predictor[PromptData[TOut], Reasoning[TOut]]
NewCLILogger chains a Predictor that provides logging around the output of the Predictor that is suitable for a CLI.
func NewDefaultParser ¶
NewDefaultParser returns the default parser for a ReAct loop.
func NewDefaultPrompt ¶
func NewDefaultPrompt[TLLMParams, TOut any]( params TLLMParams, opts ...prompters.Option[PromptData[TOut]], ) prompters.Prompter[PromptData[TOut], TLLMParams]
NewDefaultPrompt returns the default prompt for a ReAct loop. It's highly recommened to use your own examples to help the LLM return the proper typing and to better capture your use case.
func WithCLILoggerPrefix ¶
func WithExamples ¶
func WithExamples[TLLMParams, TOut any](examples ...PromptDataExample[TOut]) prompters.Option[PromptData[TOut]]
WithExamples replaces the default examples with the given examples.
func WithPreamble ¶
func WithPreamble[TLLMParams, TOut any](preamble string) prompters.Option[PromptData[TOut]]
WithPreamble replaces the preamble.
Types ¶
type Agent ¶
type Agent[TOut any] struct { // contains filtered or unexported fields }
Agent reasons and acts using its given tools and LLM.
func NewAgent ¶
func NewAgent[TOut any]( basePredictor predictors.Predictor[PromptData[TOut], Reasoning[TOut]], toolSet ...tools.Tool, ) Agent[TOut]
NewAgent returns a new ReAct Agent. It properly wraps the basePredictor in the necessary retry and extra validation logic.
type CLILoggerOption ¶
type CLILoggerOption[TOut any] func(*cliLogger[TOut])
CLILoggerOption is an option for NewCLILogger.
type PromptData ¶
type PromptData[TOut any] struct { Tools []tools.Tool Goal string Chains []ThoughtIteration[TOut] Preamble string Examples []PromptDataExample[TOut] Rules []string }
PromptData is the data used to hydrate the ReAct prompt.
type PromptDataExample ¶
type PromptDataExample[TOut any] struct { Question string PreviousContext []ThoughtIteration[TOut] Output Reasoning[TOut] }
PromptDataExample is an example used to build up the prompt.
type Reasoning ¶
type Reasoning[TOut any] struct { Thought string `json:"thought,omitempty"` Action string `json:"action,omitempty"` Input string `json:"input,omitempty"` FinalAnswer TOut `json:"final_answer,omitempty"` }
Reasoning is the expected output from a LLM where it reasons about the given problem.
type ThoughtIteration ¶
type ThoughtIteration[TOut any] struct { Reasoning[TOut] `json:",inline"` Observation any `json:"observation,omitempty"` }
ThoughtIteration is used to store an Observation along with the Reasoning. The Observation comes from the requested Action and its associated Input.