agents

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package agents include BaseAgent

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent[I schema.Schema, O schema.Schema] struct {
	Config
	// contains filtered or unexported fields
}

Agent class for chat agents. This class provides the core functionality for handling chat interactions, including managing memory, generating system prompts, and obtaining responses from a language model.

func NewAgent

func NewAgent[I schema.Schema, O schema.Schema](options ...Option) *Agent[I, O]

NewAgent initializes the AgentAgent

func (*Agent[I, O]) JSONStream added in v1.1.0

func (a *Agent[I, O]) JSONStream(ctx context.Context, userInput *I) (<-chan any, MergeResponse, error)

Run runs the chat agent with the given user input synchronously.

func (Agent[I, O]) Name added in v1.0.8

func (a Agent[I, O]) Name() string

func (*Agent[I, O]) NewMessage added in v1.0.8

func (a *Agent[I, O]) NewMessage(role components.MessageRole, content schema.Schema) *components.Message

func (*Agent[I, O]) RegisterSystemPromptContextProvider

func (a *Agent[I, O]) RegisterSystemPromptContextProvider(provider systemprompt.ContextProvider)

RegisterSystemPromptContextProvider registers a new context provider

func (*Agent[I, O]) ResetMemory

func (a *Agent[I, O]) ResetMemory()

ResetMemory resets the memory to its initial state

func (*Agent[I, O]) Run

func (a *Agent[I, O]) Run(ctx context.Context, userInput *I, output *O, apiResp *components.LLMResponse) error

Run runs the chat agent with the given user input synchronously.

func (*Agent[I, O]) RunForChain added in v1.0.8

func (a *Agent[I, O]) RunForChain(ctx context.Context, userInput any, apiResp *components.LLMResponse) (any, error)

Run runs the chat agent with the given user input for chain.

func (*Agent[I, O]) SetClient

func (a *Agent[I, O]) SetClient(clt instructor.Instructor)

func (*Agent[I, O]) SetEndHook added in v1.0.8

func (a *Agent[I, O]) SetEndHook(fn func(context.Context, *Agent[I, O], *I, *O, *components.LLMResponse))

func (*Agent[I, O]) SetErrorHook added in v1.0.8

func (a *Agent[I, O]) SetErrorHook(fn func(context.Context, *Agent[I, O], *I, *components.LLMResponse, error))

func (*Agent[I, O]) SetMaxTokens

func (a *Agent[I, O]) SetMaxTokens(maxTokens int)

func (*Agent[I, O]) SetMemory

func (a *Agent[I, O]) SetMemory(m *components.Memory)

func (*Agent[I, O]) SetModel

func (a *Agent[I, O]) SetModel(model string)

func (*Agent[I, O]) SetName added in v1.0.8

func (a *Agent[I, O]) SetName(name string)

func (*Agent[I, O]) SetStartHook added in v1.0.8

func (a *Agent[I, O]) SetStartHook(fn func(context.Context, *Agent[I, O], *I))

func (*Agent[I, O]) SetSystemPromptGenerator

func (a *Agent[I, O]) SetSystemPromptGenerator(g systemprompt.Generator)

func (*Agent[I, O]) SetTemperature

func (a *Agent[I, O]) SetTemperature(temperature float32)

func (*Agent[I, O]) Stream added in v1.1.0

func (a *Agent[I, O]) Stream(ctx context.Context, userInput *I) (<-chan string, MergeResponse, error)

Run runs the chat agent with the given user input synchronously.

func (*Agent[I, O]) SystemPrompt

func (a *Agent[I, O]) SystemPrompt() string

SystemPrompt returns the system prompt

func (*Agent[I, O]) SystemPromptContextProvider

func (a *Agent[I, O]) SystemPromptContextProvider(title string) (systemprompt.ContextProvider, error)

SystemPromptContextProvider returns agent systemPromptGenerator's context provider

func (*Agent[I, O]) UnregisterSystemPromptContextProvider

func (a *Agent[I, O]) UnregisterSystemPromptContextProvider(title string)

RegisterSystemPromptContextProvider Unregisters an existing context provider.

type AgentSelector added in v1.0.8

type AgentSelector[I schema.Schema] func(req *I) (ChainableAgent, any, error)

AgentSelector will returns a Tool based on input param

type AgentSetter

type AgentSetter interface {
	SetClient(clt instructor.Instructor)
	SetMemory(m *components.Memory)
	SetSystemPromptGenerator(g *systemprompt.Generator)
	SetModel(model string)
	SetTemperature(temperature float32)
	SetMaxTokens(maxTokens int)
}

type Chain added in v1.0.8

type Chain[I schema.Schema, O schema.Schema] struct {
	// contains filtered or unexported fields
}

Chain agents chain

func NewChain added in v1.0.8

func NewChain[I schema.Schema, O schema.Schema](agents ...ChainableAgent) *Chain[I, O]

NewChain returns a new Chain instance

func (*Chain[I, O]) Name added in v1.0.8

func (c *Chain[I, O]) Name() string

func (*Chain[I, O]) Run added in v1.0.8

func (c *Chain[I, O]) Run(ctx context.Context, input *I, output *O) ([]components.LLMResponse, error)

Run runs the chat agents with the given user input synchronously.

func (*Chain[I, O]) RunForChain added in v1.0.8

func (c *Chain[I, O]) RunForChain(ctx context.Context, input any, apiResp *components.LLMResponse) (any, error)

Run runs the chat agents with the given user input synchronously.

func (*Chain[I, O]) SetEndHook added in v1.0.8

func (c *Chain[I, O]) SetEndHook(fn func(context.Context, *Chain[I, O], *I, *O, []components.LLMResponse))

func (*Chain[I, O]) SetErrorHook added in v1.0.8

func (c *Chain[I, O]) SetErrorHook(fn func(context.Context, *Chain[I, O], *I, []components.LLMResponse, error))

func (*Chain[I, O]) SetName added in v1.0.8

func (c *Chain[I, O]) SetName(name string)

func (*Chain[I, O]) SetStartHook added in v1.0.8

func (c *Chain[I, O]) SetStartHook(fn func(context.Context, *Chain[I, O], *I))

type ChainableAgent added in v1.0.8

type ChainableAgent interface {
	IAgent
	RunForChain(context.Context, any, *components.LLMResponse) (any, error)
}

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config represents general agents configuration

type IAgent added in v1.0.8

type IAgent interface {
	Name() string
}

type MergeResponse added in v1.1.0

type MergeResponse = func(*components.LLMResponse)

type Option

type Option func(a *Config)

func WithClient

func WithClient(clt instructor.Instructor) Option

func WithMaxTokens

func WithMaxTokens(maxTokens int) Option

func WithMemory

func WithMemory(m *components.Memory) Option

func WithModel

func WithModel(model string) Option

func WithName added in v1.0.8

func WithName(name string) Option

func WithSystemPromptGenerator

func WithSystemPromptGenerator(g systemprompt.Generator) Option

func WithTemperature

func WithTemperature(temperature float32) Option

type OrchestrationAgent added in v1.0.8

type OrchestrationAgent[I schema.Schema, O schema.Schema] struct {
	// contains filtered or unexported fields
}

OrchestrationAgent is an agent for orchestration

func NewOrchestrationAgent added in v1.0.8

func NewOrchestrationAgent[I schema.Schema, O schema.Schema](selector AgentSelector[I]) *OrchestrationAgent[I, O]

func (*OrchestrationAgent[I, O]) Name added in v1.0.8

func (a *OrchestrationAgent[I, O]) Name() string

func (*OrchestrationAgent[I, O]) Run added in v1.0.8

func (a *OrchestrationAgent[I, O]) Run(ctx context.Context, input *I, output *O, apiResp *components.LLMResponse) error

func (*OrchestrationAgent[I, O]) RunForChain added in v1.0.8

func (a *OrchestrationAgent[I, O]) RunForChain(ctx context.Context, input any, apiResp *components.LLMResponse) (any, error)

func (*OrchestrationAgent[I, O]) SetName added in v1.0.8

func (a *OrchestrationAgent[I, O]) SetName(name string)

type ToolAgent added in v1.0.8

type ToolAgent[I schema.Schema, T schema.Schema, O schema.Schema] struct {
	// contains filtered or unexported fields
}

ToolAgent represent agent with tool callback

func NewToolAgent added in v1.0.8

func NewToolAgent[I schema.Schema, T schema.Schema, O schema.Schema](options ...Option) *ToolAgent[I, T, O]

NewToolAgent returns a new ToolAgent instance

func (*ToolAgent[I, T, O]) Name added in v1.0.8

func (t *ToolAgent[I, T, O]) Name() string

func (*ToolAgent[I, T, O]) ResetMemory added in v1.0.8

func (t *ToolAgent[I, T, O]) ResetMemory()

func (*ToolAgent[I, T, O]) Run added in v1.0.8

func (t *ToolAgent[I, T, O]) Run(ctx context.Context, userInput *I, output *O, apiResp *components.LLMResponse) error

Run runs the chat agent with the given user input synchronously.

func (*ToolAgent[I, T, O]) RunForChain added in v1.0.8

func (t *ToolAgent[I, T, O]) RunForChain(ctx context.Context, userInput any, apiResp *components.LLMResponse) (any, error)

Run runs the chat agent with the given user input for chain.

func (*ToolAgent[I, T, O]) SetClient added in v1.0.8

func (t *ToolAgent[I, T, O]) SetClient(clt instructor.Instructor)

func (*ToolAgent[I, T, O]) SetEndAgentEndHook added in v1.0.8

func (t *ToolAgent[I, T, O]) SetEndAgentEndHook(fn func(context.Context, *Agent[I, O], *I, *O, *components.LLMResponse))

func (*ToolAgent[I, T, O]) SetEndAgentErrorHook added in v1.0.8

func (t *ToolAgent[I, T, O]) SetEndAgentErrorHook(fn func(context.Context, *Agent[I, O], *I, *components.LLMResponse, error))

func (*ToolAgent[I, T, O]) SetEndAgentName added in v1.0.8

func (t *ToolAgent[I, T, O]) SetEndAgentName(name string)

func (*ToolAgent[I, T, O]) SetEndAgentStartHook added in v1.0.8

func (t *ToolAgent[I, T, O]) SetEndAgentStartHook(fn func(context.Context, *Agent[I, O], *I))

func (*ToolAgent[I, T, O]) SetEndHook added in v1.0.8

func (t *ToolAgent[I, T, O]) SetEndHook(fn func(context.Context, *ToolAgent[I, T, O], *I, *O, *components.LLMResponse))

func (*ToolAgent[I, T, O]) SetErrorHook added in v1.0.8

func (t *ToolAgent[I, T, O]) SetErrorHook(fn func(context.Context, *ToolAgent[I, T, O], *I, *components.LLMResponse, error))

func (*ToolAgent[I, T, O]) SetMaxTokens added in v1.0.8

func (t *ToolAgent[I, T, O]) SetMaxTokens(maxTokens int)

func (*ToolAgent[I, T, O]) SetMemory added in v1.0.8

func (t *ToolAgent[I, T, O]) SetMemory(m *components.Memory)

func (*ToolAgent[I, T, O]) SetModel added in v1.0.8

func (t *ToolAgent[I, T, O]) SetModel(model string)

func (*ToolAgent[I, T, O]) SetName added in v1.0.8

func (t *ToolAgent[I, T, O]) SetName(name string)

func (*ToolAgent[I, T, O]) SetStartAgentEndHook added in v1.0.8

func (t *ToolAgent[I, T, O]) SetStartAgentEndHook(fn func(context.Context, *Agent[I, T], *I, *T, *components.LLMResponse))

func (*ToolAgent[I, T, O]) SetStartAgentErrorHook added in v1.0.8

func (t *ToolAgent[I, T, O]) SetStartAgentErrorHook(fn func(context.Context, *Agent[I, T], *I, *components.LLMResponse, error))

func (*ToolAgent[I, T, O]) SetStartAgentName added in v1.0.8

func (t *ToolAgent[I, T, O]) SetStartAgentName(name string)

func (*ToolAgent[I, T, O]) SetStartAgentStartHook added in v1.0.8

func (t *ToolAgent[I, T, O]) SetStartAgentStartHook(fn func(context.Context, *Agent[I, T], *I))

func (*ToolAgent[I, T, O]) SetStartHook added in v1.0.8

func (t *ToolAgent[I, T, O]) SetStartHook(fn func(context.Context, *ToolAgent[I, T, O], *I))

func (*ToolAgent[I, T, O]) SetSystemPromptGenerator added in v1.0.8

func (t *ToolAgent[I, T, O]) SetSystemPromptGenerator(g systemprompt.Generator)

func (*ToolAgent[I, T, O]) SetTemperature added in v1.0.8

func (t *ToolAgent[I, T, O]) SetTemperature(temperature float32)

func (*ToolAgent[I, T, O]) SetTool added in v1.0.8

func (t *ToolAgent[I, T, O]) SetTool(tool tools.AnonymousTool) *ToolAgent[I, T, O]

func (*ToolAgent[I, T, O]) SetToolEndHook added in v1.0.8

func (t *ToolAgent[I, T, O]) SetToolEndHook(fn func(context.Context, tools.AnonymousTool, any, any))

func (*ToolAgent[I, T, O]) SetToolErrorHook added in v1.0.8

func (t *ToolAgent[I, T, O]) SetToolErrorHook(fn func(context.Context, tools.AnonymousTool, any, error))

func (*ToolAgent[I, T, O]) SetToolStartHook added in v1.0.8

func (t *ToolAgent[I, T, O]) SetToolStartHook(fn func(context.Context, tools.AnonymousTool, any))

Jump to

Keyboard shortcuts

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