agents

package
v0.0.0-...-f8640d3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2023 License: Apache-2.0 Imports: 11 Imported by: 2

Documentation

Overview

Package agents holds the logic for the ReAct agent.

Index

Constants

This section is empty.

Variables

View Source
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

func NewDefaultParser[TOut any]() parsers.Parser[Reasoning[TOut]]

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 WithCLILoggerPrefix[TOut any](prefix string) func(*cliLogger[TOut])

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.

func WithRules

func WithRules[TLLMParams, TOut any](rules ...string) prompters.Option[PromptData[TOut]]

WithRules replaces the default rules with the given rules.

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.

func (Agent[TOut]) Run

func (a Agent[TOut]) Run(ctx context.Context, goal string) (TOut, error)

Run a ReAct Agent in attempt a to reach the given goal. The FinalAnswer is output unless there is an error first.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL