Documentation
¶
Overview ¶
Package agent implements the core agentic loop for the Go sidecar.
Index ¶
- func BuildTeamLeadContext(memberIDs []string) string
- func CheckAccessibilityPermission() bool
- func DestroyBrowserSession(sessionID string)
- func Dispatch(ctx context.Context, cfg *Config, toolName string, inp map[string]any) (string, string, bool)
- func Execute(ctx context.Context, cfg Config) (hadError bool)
- func FormatSkillsAsPrompt(skills []SkillDef) string
- func ListSnapshots(sessionID string) ([]string, error)
- func LookupAgentCfg(agentID string) *agentCfg
- func NativeCaptureScreen() (imageData string, width, height int, err error)
- func RecallMemory(workspace, query string, k int) string
- func RestoreSnapshot(workspace, sessionID, messageID string) error
- func SnapshotDir(sessionID, messageID string) (string, error)
- func TryGitSnapshot(workspace, sessionID, messageID string)
- func WorkspaceTools(ctx context.Context, workspace string, ...) []ai.ToolDef
- type ClarificationAnswer
- type Config
- type ExtDispatchFunc
- type SkillDef
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildTeamLeadContext ¶
BuildTeamLeadContext generates the CustomInstructions injected into a team lead's session. It lists each member's full profile and embeds the delegation protocol so the lead knows exactly who to delegate to, in what order, and how.
func CheckAccessibilityPermission ¶
func CheckAccessibilityPermission() bool
CheckAccessibilityPermission returns true when the running process has macOS Accessibility permission (kTCCServiceAccessibility). Always returns true on non-macOS platforms — no gating is needed there.
func DestroyBrowserSession ¶
func DestroyBrowserSession(sessionID string)
DestroyBrowserSession closes a session's tab and removes it. Called from browser_close and from session teardown (delete_session / sub-agent exit).
func Dispatch ¶
func Dispatch(ctx context.Context, cfg *Config, toolName string, inp map[string]any) (string, string, bool)
Dispatch executes a named tool and returns (textContent, imageData, isError). imageData is a base64-encoded image; empty string means no image.
func Execute ¶
Execute runs one user turn of the agentic loop. It loads the session, streams the LLM, executes tools in a loop, persists messages, and emits all events via cfg.EmitFn. Returns true when the turn ended due to a provider / agent error so callers can mark the session as "failed" rather than "idle".
func FormatSkillsAsPrompt ¶
FormatSkillsAsPrompt formats active skills into a system prompt section.
func ListSnapshots ¶
ListSnapshots returns all message IDs that have a snapshot for sessionID.
func LookupAgentCfg ¶
func LookupAgentCfg(agentID string) *agentCfg
LookupAgentCfg returns the stored config for agentID, or nil if not found.
func NativeCaptureScreen ¶
NativeCaptureScreen takes a screenshot of the PRIMARY display only using built-in OS tools (no external dependencies). Returns base64-encoded PNG, width, height. Exported so the CLI can use it as a TakeScreenshot callback for /screen.
func RecallMemory ¶
RecallMemory returns a "Learned context" system-prompt block built from the saved memories most relevant to query, or "" when memory is disabled, empty, or nothing scores above zero. Scoring is purely lexical (token overlap + recency + outcome weighting) so it needs no embeddings and works offline.
func RestoreSnapshot ¶
RestoreSnapshot restores the workspace to the state captured in the snapshot for the given (session, message) pair.
func SnapshotDir ¶
SnapshotDir returns the directory for a specific (session, message) pair.
func TryGitSnapshot ¶
func TryGitSnapshot(workspace, sessionID, messageID string)
TryGitSnapshot copies the current working-tree changes for workspace into a per-(session,message) cache directory. No git commits are created. Silently no-ops when workspace is empty.
func WorkspaceTools ¶
func WorkspaceTools(ctx context.Context, workspace string, memoryEnabled, desktopAvailable, browserAvailable bool, teamMemberIDs []string) []ai.ToolDef
WorkspaceTools returns the ToolDef list sent to the LLM. Pass memoryEnabled=true to include the save_memory tool. Pass desktopAvailable=true to include desktop screen-control tools. Pass browserAvailable=true to include browser tools (dev mode only). workspace is used to load MCP and custom tool definitions.
Types ¶
type ClarificationAnswer ¶
type ClarificationAnswer struct {
Selected []string `json:"selected"`
Details string `json:"details"`
}
ClarificationAnswer is the structured result returned by ask_followup_question. Selected carries the user's chosen suggestions; Details carries optional free-text.
func ClarificationAnswerFromLegacy ¶
func ClarificationAnswerFromLegacy(answer string, suggestions []string, multiChoice bool) ClarificationAnswer
ClarificationAnswerFromLegacy converts a plain string answer into a structured ClarificationAnswer. For backward compatibility, treat the raw string as the selected suggestion when it is one of the provided suggestions and there is no free text; otherwise store it in Details.
type Config ¶
type Config struct {
SessionID string
Workspace string
Message string
Mode string // override session mode; empty = use session's mode
ThinkingBudget int
ThinkLevel string // Ollama: "", "true", "false", "low", "medium", "high"
DesktopPermitted bool
IsSubAgent bool
// EmitFn writes one event to the transport (stdout or WebSocket).
EmitFn func(map[string]any)
// RequestPerm asks the user to allow a shell command.
// Returns (allow, allowAll). Nil → always deny.
RequestPerm func(ctx context.Context, command string) (allow, allowAll bool)
// RequestClarification pauses the agent and asks the user a clarifying question.
// suggestions is an optional list of pre-written answers to show as chips.
// multiChoice allows the user to select multiple suggestions simultaneously.
// Returns the user's structured answer and ok=true, or (zero ClarificationAnswer, false) on timeout/cancel.
// Nil → clarification not available (sub-agents, legacy callers).
RequestClarification func(ctx context.Context, question string, suggestions []string, multiChoice bool) (answer ClarificationAnswer, ok bool)
// TakeScreenshot triggers Tauri to capture the screen.
// Returns the payload {image, width, height} or an error.
// Nil → screenshot not available.
TakeScreenshot func(ctx context.Context) (map[string]any, error)
// EmitEvent is the full emit function (stdout + JSONL + session bus).
// Set by Execute(); tools should use this instead of EmitFn so that
// events like screen_event are visible to WebSocket clients.
EmitEvent func(map[string]any)
// TeamMemberIDs, when non-empty, switches the agent into team-lead mode.
// In this mode spawn_sub_agent is replaced by delegate_task/wait_for_team
// so the lead delegates to configured team members instead of spawning
// ad-hoc sub-agents.
TeamMemberIDs []string
// ShellAutoAllow bypasses the per-command permission prompt for run_shell.
// Set true to auto-allow all shell commands without asking the user.
ShellAutoAllow bool
// BrowserAvailable enables the browser tool set.
// True in dev mode; false in channels (physical screen control only).
BrowserAvailable bool
// AgentName is the display name of a configured agent running as a team member.
// When set, buildSystem puts the agent's identity at the very top of the system
// prompt so the LLM anchors on its specialist role before reading anything else.
AgentName string
// CustomInstructions is the agent's persona/systemPrompt text.
// Placed at the top of the system prompt when AgentName is set; appended otherwise.
CustomInstructions string
// Audit identity — attributed to actions in the tamper-evident audit log.
// Any field may be empty on surfaces without that identity (e.g. desktop).
UserID string
TenantID string
ActorLabel string
// OverrideModel, when non-empty, replaces the session's stored model for this turn only.
// Used by the CLI agent picker to honour per-agent model preferences.
OverrideModel string
// Images are user-attached base64-encoded images for the current turn.
// Not persisted to disk — injected only into the in-memory user ChatMessage.
Images []string
// ProviderID is the ID of the session's active provider.
// Set by Execute() after loading the session; used by RAG tools for embeddings.
ProviderID string
// ExtDispatch, when non-nil, is called before the built-in tool switch in Dispatch.
// If it returns handled=true the built-in switch is skipped entirely.
// Pro edition uses this to route "integration__*" tool calls.
ExtDispatch ExtDispatchFunc
// SystemOverride, when non-nil, replaces the output of buildSystem() entirely.
// Pro edition uses this to inject identity, integrations, and persona instructions.
SystemOverride *string
// MemoryEnabled is set by Execute() from the workspace memory config.
// When true, the save_memory tool is included and the system prompt mentions it.
MemoryEnabled bool
// RequestSystemPermission asks the frontend to guide the user to grant a macOS
// system permission. permType is "accessibility" (mouse/keyboard control).
// Returns true when the user grants it, false on timeout or denial.
// Nil → permission flow not available (sub-agents, legacy callers).
RequestSystemPermission func(ctx context.Context, permType string) bool
// RequestContinue is called when ConfirmContinue is enabled and the agent
// reaches the confirmation threshold. It pauses the loop and asks the user
// whether to keep going. Returns true to continue, false to stop.
// Nil → always continue (no prompt).
RequestContinue func(ctx context.Context, iteration, maxIter int) bool
// contains filtered or unexported fields
}
Config bundles everything Execute needs to run an agent turn.
type ExtDispatchFunc ¶
type ExtDispatchFunc func(ctx context.Context, cfg *Config, toolName string, inp map[string]any) (output, imageData string, isError, handled bool)
ExtDispatchFunc is the pro-edition extension hook type for tool dispatch. If handled is true the built-in switch is skipped.
type SkillDef ¶
type SkillDef struct {
Name string
Description string
Source string // "global" | "workspace"
Body string
}
SkillDef holds one parsed skill file.
func LoadActiveSkills ¶
LoadActiveSkills reads all skill .md files from global and workspace skill directories and returns only those whose names appear in the activeSkills list. If activeSkills is empty, it returns an empty slice (no skills active).
Source Files
¶
- executor.go
- filediff.go
- git_snapshot.go
- history.go
- memory_auto.go
- memory_recall.go
- skills.go
- subagent.go
- tools_browser.go
- tools_calendar.go
- tools_custom.go
- tools_desktop.go
- tools_dir.go
- tools_email.go
- tools_file.go
- tools_memory.go
- tools_misc.go
- tools_rag.go
- tools_registry.go
- tools_screenshot.go
- tools_shell.go
- tools_shell_unix.go
- tools_web.go