agent

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package agent implements the agent loop: prompt assembly, model calls, tool iteration, and reply.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

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

Agent runs the prompt → model → (tools) → reply loop.

func New

func New(opts Options) (*Agent, error)

New creates an Agent. Completer and Sessions are required.

func (*Agent) Handle

func (a *Agent) Handle(ctx context.Context, msg channel.Message) (string, error)

Handle is a channel.Handler: assemble prompt, call model (with tools), return reply.

func (*Agent) SetPersona added in v0.0.2

func (a *Agent) SetPersona(text string)

SetPersona replaces the system persona text (e.g. after SIGHUP reload). When memory is enabled, the persona-precedence note is appended.

type History

type History interface {
	Messages(ctx context.Context, sessionID string) ([]session.Message, error)
	Append(ctx context.Context, sessionID string, msgs ...session.Message) error
	Reset(ctx context.Context, sessionID string) error
	Stats(ctx context.Context, sessionID string) (messages int, estTokens int, err error)
	Summary(ctx context.Context, sessionID string) (string, error)
}

History is the session-backed conversation store used by the agent.

type Options

type Options struct {
	Persona       string
	Completer     provider.Completer
	Sessions      History
	Tools         Tools         // optional
	Memory        memory.Memory // optional; hydration + persona precedence note
	Model         string
	MaxToolIters  int
	StreamReplies bool // stream final text via channel.ReplyWriter when Completer is a Streamer
	Logger        *slog.Logger
	StartedAt     time.Time
}

Options configures the agent.

type Tools

type Tools interface {
	Tools() []provider.ToolDef
	Call(ctx context.Context, name string, arguments json.RawMessage) (string, error)
	ToolCount() int
}

Tools executes MCP (or other) tools during the agent loop.

Jump to

Keyboard shortcuts

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