agent

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMaxIterations = errors.New("max iterations reached")
	ErrNilModel      = errors.New("agent: model is nil")
)

Functions

This section is empty.

Types

type Agent

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

Agent drives the core loop, invoking middleware, model, and tools.

func New

func New(model Model, tools ToolExecutor, opts Options) (*Agent, error)

New constructs an Agent with the provided collaborators.

func (*Agent) Run

func (a *Agent) Run(ctx context.Context, c *Context) (*ModelOutput, error)

Run executes the agent loop. It terminates when the model returns a final output (Done or no tool calls), the context is canceled, or an error occurs.

type Context

type Context struct {
	Iteration       int
	StartedAt       time.Time
	Values          map[string]any
	ToolResults     []ToolResult
	LastModelOutput *ModelOutput
}

Context carries runtime state for a single agent execution.

func NewContext

func NewContext() *Context

type Model

type Model interface {
	Generate(ctx context.Context, c *Context) (*ModelOutput, error)
}

Model produces the next output for the agent given the current context.

type ModelOutput

type ModelOutput struct {
	Content   string
	ToolCalls []ToolCall
	Done      bool
}

ModelOutput is the result returned by a Model.Generate call.

type Options

type Options struct {
	// MaxIterations limits how many cycles Run may execute.
	// Zero means no limit.
	MaxIterations int
	// Timeout bounds the entire Run invocation. Zero disables it.
	Timeout time.Duration
	// Middleware chain. Defaults to an empty chain when nil.
	Middleware *middleware.Chain
}

Options controls runtime behavior of the Agent.

type ToolCall

type ToolCall struct {
	ID    string
	Name  string
	Input map[string]any
}

ToolCall describes a discrete tool invocation request.

type ToolExecutor

type ToolExecutor interface {
	Execute(ctx context.Context, call ToolCall, c *Context) (ToolResult, error)
}

ToolExecutor performs a tool call emitted by the model.

type ToolResult

type ToolResult struct {
	Name     string
	Output   string
	Metadata map[string]any
}

ToolResult holds the outcome of a tool invocation.

Jump to

Keyboard shortcuts

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