agent

package
v1.1.34 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 21 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 struct {
	// contains filtered or unexported fields
}

Agent orchestrates the agentic loop: send messages to LLM, execute tool calls, loop.

func NewAgent

func NewAgent(p provider.Provider, tools *tool.Registry, systemPrompt string, maxIter int) *Agent

NewAgent creates a new agent with optional permission policy.

func (*Agent) AddMessage

func (a *Agent) AddMessage(msg provider.Message)

AddMessage appends a message to the conversation context.

func (*Agent) CheckpointManager

func (a *Agent) CheckpointManager() *checkpoint.Manager

CheckpointManager returns the checkpoint manager.

func (*Agent) Clear

func (a *Agent) Clear()

Clear resets the conversation (keeps system prompt).

func (*Agent) ContextManager

func (a *Agent) ContextManager() ctxpkg.ContextManager

func (*Agent) Messages

func (a *Agent) Messages() []provider.Message

Messages returns the current conversation messages.

func (*Agent) PermissionPolicy

func (a *Agent) PermissionPolicy() permission.PermissionPolicy

PermissionPolicy returns the current policy.

func (*Agent) ProjectMemoryFiles added in v1.1.30

func (a *Agent) ProjectMemoryFiles() []string

func (*Agent) Provider

func (a *Agent) Provider() provider.Provider

func (*Agent) RunStream

func (a *Agent) RunStream(ctx context.Context, userMsg string, onEvent func(provider.StreamEvent)) error

RunStream runs the agent loop with streaming, sending events to the callback.

func (*Agent) RunStreamWithContent

func (a *Agent) RunStreamWithContent(ctx context.Context, content []provider.ContentBlock, onEvent func(provider.StreamEvent)) error

RunStreamWithContent runs the agent loop and emits UI events for complete model turns.

func (*Agent) SetApprovalHandler

func (a *Agent) SetApprovalHandler(fn func(toolName string, input string) permission.Decision)

SetApprovalHandler sets a callback for interactive approval (Ask → Deny by default). If nil, Ask decisions are treated as Deny.

func (*Agent) SetCheckpointManager

func (a *Agent) SetCheckpointManager(m *checkpoint.Manager)

SetCheckpointManager sets the checkpoint manager for undo support.

func (*Agent) SetContextManager

func (a *Agent) SetContextManager(cm ctxpkg.ContextManager)

SetContextManager replaces the default context manager.

func (*Agent) SetDiffConfirm

func (a *Agent) SetDiffConfirm(fn DiffConfirmFunc)

SetDiffConfirm sets the diff confirmation callback.

func (*Agent) SetHookConfig

func (a *Agent) SetHookConfig(cfg hooks.HookConfig)

SetHookConfig sets the hooks configuration.

func (*Agent) SetInterruptionHandler added in v1.1.15

func (a *Agent) SetInterruptionHandler(fn func() string)

SetInterruptionHandler sets a callback that drains user guidance arriving mid-run.

func (*Agent) SetPermissionPolicy

func (a *Agent) SetPermissionPolicy(policy permission.PermissionPolicy)

SetPermissionPolicy sets the permission policy for tool checks.

func (*Agent) SetProjectMemoryFiles added in v1.1.30

func (a *Agent) SetProjectMemoryFiles(files []string)

SetProjectMemoryFiles seeds the set of already-loaded project memory files so path-triggered dynamic loading can avoid reinjecting startup guidance.

func (*Agent) SetProvider

func (a *Agent) SetProvider(p provider.Provider)

ContextManager returns the context manager for external inspection.

func (*Agent) SetSupportsVision added in v1.1.34

func (a *Agent) SetSupportsVision(v bool)

SetSupportsVision controls whether tool_result images are included in messages sent to the provider. When false, image data is stripped from tool results and only the text placeholder is sent.

func (*Agent) SetUsageHandler

func (a *Agent) SetUsageHandler(fn func(usage provider.TokenUsage))

SetUsageHandler sets a callback invoked after each API call with token usage.

func (*Agent) SetWorkingDir

func (a *Agent) SetWorkingDir(dir string)

SetWorkingDir sets the working directory for hooks.

func (*Agent) SupportsVision added in v1.1.34

func (a *Agent) SupportsVision() bool

func (*Agent) UpdateSystemPrompt added in v1.1.34

func (a *Agent) UpdateSystemPrompt(text string)

UpdateSystemPrompt replaces the first system message in the context. If no system message exists, it adds one.

type DiffConfirmFunc

type DiffConfirmFunc func(filePath, diffText string) bool

DiffConfirmFunc is called before a file write to request user confirmation. It receives the file path and unified diff string, and returns true if approved.

Jump to

Keyboard shortcuts

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