agent

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent interface {
	// Return the name of the agent
	Name() string

	// Return the models
	Models(context.Context) ([]Model, error)

	// Generate a response from a prompt
	Generate(context.Context, Model, []Context, ...Opt) (*Response, error)

	// Create user message context
	UserPrompt(string) Context
}

An LLM Agent is a client for the LLM service

type Context

type Context interface {
	Role() string
}

Context is fed to the agent to generate a response. Role can be assistant, user, tool, tool_result, ...

type Model

type Model interface {
	// Return the name of the model
	Name() string
}

An LLM Agent is a client for the LLM service

type Opt

type Opt func(*Opts) error

func OptStream

func OptStream(fn func(Response)) Opt

OptStream sets the stream function, which is called during the response generation process

func OptTools

func OptTools(t ...Tool) Opt

OptTools sets the tools for the chat request

type Opts

type Opts struct {
	Tools    []Tool
	StreamFn func(Response)
}

type Response

type Response struct {
	Agent     string                  `json:"agent,omitempty"`   // The agent name
	Model     string                  `json:"model,omitempty"`   // The model name
	Context   []Context               `json:"context,omitempty"` // The context for the response
	Text      string                  `json:"text,omitempty"`    // The response text
	*ToolCall `json:"tool,omitempty"` // The tool call, if not nil
	Tokens    uint                    `json:"tokens,omitempty"`   // The number of tokens
	Duration  time.Duration           `json:"duration,omitempty"` // The response duration
}

func (Response) String

func (r Response) String() string

type Tool

type Tool interface {
	// Return the provider of the tool
	Provider() string

	// Return the name of the tool
	Name() string

	// Return the description of the tool
	Description() string

	// Tool parameters
	Params() []ToolParameter

	// Execute the tool with a specific tool
	Run(context.Context, *ToolCall) (*ToolResult, error)
}

A tool can be called from an LLM

type ToolCall

type ToolCall struct {
	Id   string         `json:"id"`
	Name string         `json:"name"`
	Args map[string]any `json:"args"`
}

A call to a tool

func (*ToolCall) Int

func (t *ToolCall) Int(name string) (int, error)

Return parameter as an integer

func (*ToolCall) JSON

func (t *ToolCall) JSON() string

Return the arguments for the call as a JSON

func (*ToolCall) String

func (t *ToolCall) String(name string) (string, error)

Return parameter as a string

type ToolParameter

type ToolParameter struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Required    bool   `json:"required,omitempty"`
}

A tool parameter

type ToolResult

type ToolResult struct {
	Id     string         `json:"id"`
	Result map[string]any `json:"result,omitempty"`
}

The result of a tool call

func (*ToolResult) Role

func (t *ToolResult) Role() string

Return role for the tool result

Jump to

Keyboard shortcuts

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