Documentation
¶
Overview ¶
internal/agent/compact.go
Index ¶
- Constants
- Variables
- func BasePrompt() string
- func BuildRepoMapBlock(s *session.Session, idx *codeindex.Index, enabled bool, maxTokens int) string
- func BuiltinSubagentTypeSet() map[string]bool
- func LoadAgentsMD(start, stop string) string
- func ParseRequireTools(csv string) map[string]bool
- func PlanModePrompt() string
- func RequireToolPrompt(required map[string]bool) string
- func RuntimeContext() string
- func SubagentDefinitionsFromAgentDefs(defs map[string]agentdef.Definition) map[string]SubagentDefinition
- type Agent
- func (a *Agent) Compact(ctx context.Context, userInstructions string) error
- func (a *Agent) Mode() Mode
- func (a *Agent) Provider() ai.Provider
- func (a *Agent) ReasoningEffort() string
- func (a *Agent) RegisterSubagentTools()
- func (a *Agent) RegisterSubagentToolsEnabled(enabled bool)
- func (a *Agent) RepoMapBudget() int
- func (a *Agent) RepoMapEnabled() bool
- func (a *Agent) RequireTools() map[string]bool
- func (a *Agent) Run(ctx context.Context, userMsg ai.Message) <-chan Event
- func (a *Agent) SetCodeIndex(idx *codeindex.Index)
- func (a *Agent) SetMode(mode Mode)
- func (a *Agent) SetModelCapabilities(caps map[string]config.ModelCapabilities)
- func (a *Agent) SetReasoningEffort(effort string)
- func (a *Agent) SetRepoMapBudget(tokens int)
- func (a *Agent) SetRepoMapEnabled(enabled bool)
- func (a *Agent) SetRequireTools(names map[string]bool)
- func (a *Agent) SetSubagentDefinitions(defs map[string]SubagentDefinition)
- func (a *Agent) Subagents() *SubagentSupervisor
- func (a *Agent) System() string
- func (a *Agent) Tools() *tools.Registry
- type AssistantText
- type ContextOverflow
- type Event
- type InvalidToolCallRecovered
- type Mode
- type RequiredToolPending
- type SubagentConfig
- type SubagentDefinition
- type SubagentEvent
- type SubagentStatus
- type SubagentSupervisor
- func (s *SubagentSupervisor) AnyCompletion() <-chan struct{}
- func (s *SubagentSupervisor) Cancel(id string) error
- func (s *SubagentSupervisor) DrainCompletedSummaries() []tools.SubagentTask
- func (s *SubagentSupervisor) Get(id string) *tools.SubagentTask
- func (s *SubagentSupervisor) HasInFlight() bool
- func (s *SubagentSupervisor) List() []tools.SubagentTask
- func (s *SubagentSupervisor) SetDefinitions(defs map[string]SubagentDefinition)
- func (s *SubagentSupervisor) Spawn(ctx context.Context, req tools.SpawnSubagentRequest) (*tools.SubagentTask, error)
- func (s *SubagentSupervisor) Subscribe(ctx context.Context) <-chan SubagentEvent
- func (s *SubagentSupervisor) Types() []SubagentTypeInfo
- func (s *SubagentSupervisor) WaitForAnyCompletion() (<-chan struct{}, bool)
- type SubagentTask
- type SubagentToolMode
- type SubagentTypeInfo
- type ThinkingText
- type ToolFinished
- type ToolStarted
- type TurnAborted
- type TurnDone
- type TurnError
- type TurnUsage
Constants ¶
const ReasonIncompleteRequiredTool = "incomplete_required_tool"
ReasonIncompleteRequiredTool is the TurnDone reason emitted when the agent exhausted its nudge budget without calling a required completion tool.
Variables ¶
var ErrIncompleteRequiredTool = errors.New("agent ended turn without calling a required completion tool")
ErrIncompleteRequiredTool is returned by a headless run (--require-tool) that ended without the model calling one of the required tools. Callers map it to a distinct process exit code so an orchestrator can tell "agent went quiet" apart from a real crash.
Functions ¶
func BasePrompt ¶
func BasePrompt() string
BasePrompt is the default rune system prompt. Centralized here so cmd/rune and internal/tui share one source of truth.
func BuildRepoMapBlock ¶ added in v0.2.0
func BuildRepoMapBlock(s *session.Session, idx *codeindex.Index, enabled bool, maxTokens int) string
BuildRepoMapBlock assembles the per-turn <repo_map> system-prompt block. Returns "" silently on any failure path — never fails a turn over the map.
func BuiltinSubagentTypeSet ¶ added in v0.1.3
func LoadAgentsMD ¶
LoadAgentsMD walks from start up to (and including) stop, collecting AGENTS.md files. Returns them concatenated, root-first (broadest scope first).
func ParseRequireTools ¶ added in v0.4.0
ParseRequireTools splits a comma-separated --require-tool value into a set, trimming whitespace and dropping empties. Returns nil when no names remain.
func PlanModePrompt ¶
func PlanModePrompt() string
func RequireToolPrompt ¶ added in v0.4.0
RequireToolPrompt is the system-prompt block injected when --require-tool is set. It overrides the base prompt's interactive "ask one question / wait for approval" guidance: a headless worker has no human to answer, so it must decide, proceed, and end only by calling a completion tool.
func RuntimeContext ¶
func RuntimeContext() string
RuntimeContext returns a <system-context> block describing the runtime: date/time, cwd, os/arch, shell, user. Called per turn from loop.go so the date doesn't drift in long sessions.
func SubagentDefinitionsFromAgentDefs ¶ added in v0.1.3
func SubagentDefinitionsFromAgentDefs(defs map[string]agentdef.Definition) map[string]SubagentDefinition
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
func NewWithSubagentConfig ¶
func (*Agent) ReasoningEffort ¶
func (*Agent) RegisterSubagentTools ¶
func (a *Agent) RegisterSubagentTools()
func (*Agent) RegisterSubagentToolsEnabled ¶
func (*Agent) RepoMapBudget ¶ added in v0.2.0
func (*Agent) RepoMapEnabled ¶ added in v0.2.0
func (*Agent) RequireTools ¶ added in v0.4.0
func (*Agent) SetCodeIndex ¶ added in v0.2.0
func (*Agent) SetModelCapabilities ¶ added in v0.1.22
func (a *Agent) SetModelCapabilities(caps map[string]config.ModelCapabilities)
func (*Agent) SetReasoningEffort ¶
func (*Agent) SetRepoMapBudget ¶ added in v0.2.0
func (*Agent) SetRepoMapEnabled ¶ added in v0.2.0
func (*Agent) SetRequireTools ¶ added in v0.4.0
SetRequireTools enables headless completion enforcement: the agent may only end its turn after one of these tools succeeds; otherwise it is nudged to continue (see loop.go). Pass nil/empty to disable.
func (*Agent) SetSubagentDefinitions ¶ added in v0.1.3
func (a *Agent) SetSubagentDefinitions(defs map[string]SubagentDefinition)
func (*Agent) Subagents ¶
func (a *Agent) Subagents() *SubagentSupervisor
type AssistantText ¶
type AssistantText struct{ Delta string }
type ContextOverflow ¶
type ContextOverflow struct{}
type InvalidToolCallRecovered ¶ added in v0.1.1
type InvalidToolCallRecovered struct{ Names []string }
InvalidToolCallRecovered fires when the model emitted one or more tool calls whose names are not in the request's tool list. The bad calls are dropped from session history and a nudge is appended; the agent continues the turn instead of failing.
type RequiredToolPending ¶ added in v0.4.0
RequiredToolPending fires in headless (--require-tool) mode when the model ended its turn without calling a required completion tool. A nudge is appended and the turn continues; Attempt is the 1-based nudge count.
type SubagentConfig ¶
type SubagentConfig struct {
MaxConcurrent int
DefaultTimeout time.Duration
MaxCompletedRetain int
Definitions map[string]SubagentDefinition
}
func SubagentConfigFromSettings ¶
func SubagentConfigFromSettings(s config.SubagentSettings) SubagentConfig
type SubagentDefinition ¶ added in v0.1.3
type SubagentEvent ¶
type SubagentEvent struct {
Task tools.SubagentTask `json:"task"`
Status SubagentStatus `json:"status"`
}
type SubagentStatus ¶
type SubagentStatus string
const ( SubagentBlocked SubagentStatus = "blocked" SubagentPending SubagentStatus = "pending" SubagentRunning SubagentStatus = "running" SubagentCompleted SubagentStatus = "completed" SubagentFailed SubagentStatus = "failed" SubagentCancelled SubagentStatus = "cancelled" )
type SubagentSupervisor ¶
type SubagentSupervisor struct {
// contains filtered or unexported fields
}
func NewSubagentSupervisor ¶
func NewSubagentSupervisor(parent *Agent, cfg SubagentConfig) *SubagentSupervisor
func (*SubagentSupervisor) AnyCompletion ¶ added in v0.2.0
func (s *SubagentSupervisor) AnyCompletion() <-chan struct{}
AnyCompletion returns a channel that closes the next time any tracked subagent transitions to a terminal state. The channel is re-armed after each fire; callers must call AnyCompletion again before each wait.
func (*SubagentSupervisor) Cancel ¶
func (s *SubagentSupervisor) Cancel(id string) error
func (*SubagentSupervisor) DrainCompletedSummaries ¶
func (s *SubagentSupervisor) DrainCompletedSummaries() []tools.SubagentTask
func (*SubagentSupervisor) Get ¶
func (s *SubagentSupervisor) Get(id string) *tools.SubagentTask
func (*SubagentSupervisor) HasInFlight ¶ added in v0.2.0
func (s *SubagentSupervisor) HasInFlight() bool
HasInFlight reports whether any tracked subagent is pending, blocked, or running. Used by the agent loop to decide whether to wait for completion instead of ending the turn.
func (*SubagentSupervisor) List ¶
func (s *SubagentSupervisor) List() []tools.SubagentTask
func (*SubagentSupervisor) SetDefinitions ¶ added in v0.1.3
func (s *SubagentSupervisor) SetDefinitions(defs map[string]SubagentDefinition)
func (*SubagentSupervisor) Spawn ¶
func (s *SubagentSupervisor) Spawn(ctx context.Context, req tools.SpawnSubagentRequest) (*tools.SubagentTask, error)
func (*SubagentSupervisor) Subscribe ¶
func (s *SubagentSupervisor) Subscribe(ctx context.Context) <-chan SubagentEvent
func (*SubagentSupervisor) Types ¶ added in v0.1.3
func (s *SubagentSupervisor) Types() []SubagentTypeInfo
func (*SubagentSupervisor) WaitForAnyCompletion ¶ added in v0.2.0
func (s *SubagentSupervisor) WaitForAnyCompletion() (<-chan struct{}, bool)
WaitForAnyCompletion atomically checks whether any tracked subagent is in flight and, if so, returns the channel that will close on the next terminal transition. The (channel, true) pair is captured under a single lock acquisition so callers cannot race with a concurrent finish() / Cancel() that closes and replaces the channel. Returns (nil, false) when nothing is in flight.
type SubagentTask ¶
type SubagentTask struct {
ID string `json:"task_id"`
Name string `json:"name"`
FamiliarName string `json:"familiar_name,omitempty"`
AgentType string `json:"agent_type"`
Prompt string `json:"-"`
TimeoutSecs int `json:"-"`
Status SubagentStatus `json:"status"`
Dependencies []string `json:"dependencies,omitempty"`
CreatedAt time.Time `json:"created_at"`
StartedAt *time.Time `json:"started_at,omitempty"`
CompletedAt *time.Time `json:"completed_at,omitempty"`
InputTokens int `json:"input_tokens,omitempty"`
OutputTokens int `json:"output_tokens,omitempty"`
Summary string `json:"summary,omitempty"`
Error string `json:"error,omitempty"`
// contains filtered or unexported fields
}
type SubagentToolMode ¶ added in v0.1.3
type SubagentToolMode string
const ( SubagentToolsReadOnly SubagentToolMode = "readonly" SubagentToolsFull SubagentToolMode = "full" )
type SubagentTypeInfo ¶ added in v0.1.3
type ThinkingText ¶
type ThinkingText struct{ Delta string }
type ToolStarted ¶
type TurnAborted ¶
type TurnAborted struct{}