agent

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNothingToCompact = errors.New("nothing to compact yet")

Functions

This section is empty.

Types

type Agent

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

func NewAgent

func NewAgent(opts AgentOptions) *Agent

func (*Agent) Compact

func (a *Agent) Compact(ctx context.Context) error

Replaces the history with a summary to free context

func (*Agent) ContextTokens

func (a *Agent) ContextTokens() int

Returns the estimated tokens in the conversation

func (*Agent) ContextWindow

func (a *Agent) ContextWindow() int

Returns the context window size; 0 means unknown

func (*Agent) GetLastAssistantMessage

func (a *Agent) GetLastAssistantMessage() string

Returns the content of the last assistant message

func (*Agent) GetMessages

func (a *Agent) GetMessages() []openai.ChatCompletionMessageParamUnion

Returns a copy of the conversation history

func (*Agent) Inject

func (a *Agent) Inject(text string) bool

Queues a user message for the running Run; false if no run is active

func (*Agent) LogTail

func (a *Agent) LogTail(epoch, from int) ([]json.RawMessage, int, error)

Returns messages from index from, each encoded as JSON, and the current epoch; if epoch is stale the history was compacted, so all messages are returned

func (*Agent) MemoryDir

func (a *Agent) MemoryDir(scope string) string

func (*Agent) Mode

func (a *Agent) Mode() Mode

func (*Agent) Model

func (a *Agent) Model() string

Returns the model the agent talks to

func (*Agent) Restore

func (a *Agent) Restore(raw []json.RawMessage) error

Replaces the conversation history with messages saved by LogTail

func (*Agent) Run

func (a *Agent) Run(ctx context.Context, userPrompt string) error

func (*Agent) SetInjectedCallback

func (a *Agent) SetInjectedCallback(fn func(texts []string))

Sets a callback fired when injected messages enter the conversation

func (*Agent) SetMode

func (a *Agent) SetMode(m Mode)

Switches the mode The switch is recorded in the conversation so the model knows the rules changed

func (*Agent) SetNoticeCallback

func (a *Agent) SetNoticeCallback(fn func(text string))

Sets a callback for status notices such as compaction

func (*Agent) SetTextCallback

func (a *Agent) SetTextCallback(fn func(delta string))

Sets a callback to receive assistant text deltas as they stream in

func (*Agent) SetToolCallCallback

func (a *Agent) SetToolCallCallback(fn func(name, arguments string))

Sets a callback for tool calls

type AgentOptions

type AgentOptions struct {
	Client          *openai.Client
	Model           string
	PermissiveShell bool
	PermissiveWrite bool
	TavilyAPIKey    string
	ContextWindow   int
	MCPServers      []*mcpclient.MCPServer
	Logger          *log.Logger
	WhitelistedCmds []string
	OnWhitelist     func(string)
	OnToolCall      func(name, arguments string)
}

type Mode

type Mode int

Controls what the agent is allowed to do.

const (
	ModeNormal Mode = iota
	ModePlan        // Restricts the agent to read-only tools and asks it to produce a plan instead of making changes
)

func ParseMode

func ParseMode(s string) (Mode, error)

Converts a user-supplied name into a Mode.

func (Mode) String

func (m Mode) String() string

Jump to

Keyboard shortcuts

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