Documentation
¶
Index ¶
- type Agent
- func (a *Agent) AddMessage(msg provider.Message)
- func (a *Agent) CancelPreCompact()
- func (a *Agent) CheckpointManager() *checkpoint.Manager
- func (a *Agent) Clear()
- func (a *Agent) Close()
- func (a *Agent) ContextManager() ctxpkg.ContextManager
- func (a *Agent) Messages() []provider.Message
- func (a *Agent) PermissionPolicy() permission.PermissionPolicy
- func (a *Agent) PreCompactStatus() PreCompactStatus
- func (a *Agent) ProjectMemoryFiles() []string
- func (a *Agent) Provider() provider.Provider
- func (a *Agent) RunStream(ctx context.Context, userMsg string, onEvent func(provider.StreamEvent)) error
- func (a *Agent) RunStreamWithContent(ctx context.Context, content []provider.ContentBlock, ...) error
- func (a *Agent) SetApprovalHandler(fn ApprovalFunc)
- func (a *Agent) SetCheckpointHandler(fn func(messages []provider.Message, tokenCount int))
- func (a *Agent) SetCheckpointManager(m *checkpoint.Manager)
- func (a *Agent) SetContextManager(cm ctxpkg.ContextManager)
- func (a *Agent) SetDiffConfirm(fn DiffConfirmFunc)
- func (a *Agent) SetHookConfig(cfg hooks.HookConfig)
- func (a *Agent) SetInterruptionHandler(fn func() string)
- func (a *Agent) SetPermissionPolicy(policy permission.PermissionPolicy)
- func (a *Agent) SetProjectMemoryFiles(files []string)
- func (a *Agent) SetProvider(p provider.Provider)
- func (a *Agent) SetSupportsVision(v bool)
- func (a *Agent) SetUsageHandler(fn func(usage provider.TokenUsage))
- func (a *Agent) SetWorkingDir(dir string)
- func (a *Agent) StartPreCompact()
- func (a *Agent) SupportsVision() bool
- func (a *Agent) SystemPrompt() string
- func (a *Agent) ToolRegistry() *tool.Registry
- func (a *Agent) UpdateSystemPrompt(text string)
- func (a *Agent) WorkingDir() string
- type ApprovalFunc
- type DiffConfirmFunc
- type PreCompactStatus
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 (*Agent) AddMessage ¶
AddMessage appends a message to the conversation context.
func (*Agent) CancelPreCompact ¶ added in v1.1.45
func (a *Agent) CancelPreCompact()
CancelPreCompact aborts any in-flight pre-compact. Safe to call from session-clear, /clear, /compact, SetContextManager or app shutdown.
The goroutine sees its bgCtx cancelled, marks the state as cancelled, then closes done. Any concurrent waitForPreCompact will see ok=false and fall back to inline maybeAutoCompact.
func (*Agent) CheckpointManager ¶
func (a *Agent) CheckpointManager() *checkpoint.Manager
CheckpointManager returns the checkpoint manager.
func (*Agent) Close ¶ added in v1.1.60
func (a *Agent) Close()
Close releases resources held by the agent, including cancelling any in-flight pre-compact operations. Should be called on shutdown.
func (*Agent) ContextManager ¶
func (a *Agent) ContextManager() ctxpkg.ContextManager
func (*Agent) PermissionPolicy ¶
func (a *Agent) PermissionPolicy() permission.PermissionPolicy
PermissionPolicy returns the current policy.
func (*Agent) PreCompactStatus ¶ added in v1.1.45
func (a *Agent) PreCompactStatus() PreCompactStatus
PreCompactStatus reports the current background pre-compact status, or a zero value if none is running. Used by the TUI status panel to surface a "compacting…" indicator instead of leaving the user wondering why tokens are at the threshold.
func (*Agent) ProjectMemoryFiles ¶ added in v1.1.30
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 ApprovalFunc)
SetApprovalHandler sets a callback for interactive approval (Ask → Deny by default). If nil, Ask decisions are treated as Deny. The callback receives the per-run context so it can abort cleanly if the agent is cancelled while waiting.
func (*Agent) SetCheckpointHandler ¶ added in v1.1.43
SetCheckpointHandler sets a callback invoked after summarize compaction to persist the compacted message state.
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
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
SetProjectMemoryFiles seeds the set of already-loaded project memory files so path-triggered dynamic loading can avoid reinjecting startup guidance.
func (*Agent) SetProvider ¶
ContextManager returns the context manager for external inspection.
func (*Agent) SetSupportsVision ¶ added in v1.1.34
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 ¶
SetWorkingDir sets the working directory for hooks.
func (*Agent) StartPreCompact ¶ added in v1.1.45
func (a *Agent) StartPreCompact()
StartPreCompact initiates a background compaction if conditions warrant it. Returns immediately. Safe to call after every agent run; it self-skips when tokens are below threshold or a compact is already in flight.
The background goroutine uses its own context.WithTimeout(60s) — independent of any user request — so a user pressing ctrl+c during the next prompt does NOT abort this work. The result is consumed by waitForPreCompact on the next RunStreamWithContent call.
func (*Agent) SupportsVision ¶ added in v1.1.34
func (*Agent) SystemPrompt ¶ added in v1.1.43
SystemPrompt returns the current system prompt (from the first system message).
func (*Agent) ToolRegistry ¶ added in v1.1.43
ToolRegistry returns the tool registry used by this agent.
func (*Agent) UpdateSystemPrompt ¶ added in v1.1.34
UpdateSystemPrompt replaces the first system message in the context. If no system message exists, it adds one.
func (*Agent) WorkingDir ¶ added in v1.1.45
type ApprovalFunc ¶ added in v1.1.45
ApprovalFunc is called when a tool requires interactive approval. It MUST honor ctx.Done() to avoid a goroutine leak if the TUI exits while a permission prompt is awaiting user input.
type DiffConfirmFunc ¶
DiffConfirmFunc is called before a file write to request user confirmation. It receives a context, the file path and unified diff string, and returns true if approved. Implementations MUST honor ctx.Done() so the agent goroutine doesn't leak when the TUI shuts down while a confirmation is in flight.