Help us shape the future of Go! Take the 2026 Go Developer Survey

agent

package
v0.10.4 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

internal/agent/compact.go

Index

Constants

View Source
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

View Source
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 BuiltinSubagentTypeSet() map[string]bool

func LoadAgentsMD

func LoadAgentsMD(start, stop string) string

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

func ParseRequireTools(csv string) map[string]bool

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

func RequireToolPrompt(required map[string]bool) string

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 New

func New(p ai.Provider, t *tools.Registry, s *session.Session, systemPrompt string) *Agent

func NewWithSubagentConfig

func NewWithSubagentConfig(p ai.Provider, t *tools.Registry, s *session.Session, systemPrompt string, cfg SubagentConfig) *Agent

func (*Agent) Compact

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

func (*Agent) Mode

func (a *Agent) Mode() Mode

func (*Agent) Provider

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

func (*Agent) ReasoningEffort

func (a *Agent) ReasoningEffort() string

func (*Agent) RegisterSubagentTools

func (a *Agent) RegisterSubagentTools()

func (*Agent) RegisterSubagentToolsEnabled

func (a *Agent) RegisterSubagentToolsEnabled(enabled bool)

func (*Agent) RepoMapBudget added in v0.2.0

func (a *Agent) RepoMapBudget() int

func (*Agent) RepoMapEnabled added in v0.2.0

func (a *Agent) RepoMapEnabled() bool

func (*Agent) RequireTools added in v0.4.0

func (a *Agent) RequireTools() map[string]bool

func (*Agent) Run

func (a *Agent) Run(ctx context.Context, userMsg ai.Message) <-chan Event

func (*Agent) SetCodeIndex added in v0.2.0

func (a *Agent) SetCodeIndex(idx *codeindex.Index)

func (*Agent) SetMode

func (a *Agent) SetMode(mode Mode)

func (*Agent) SetModelCapabilities added in v0.1.22

func (a *Agent) SetModelCapabilities(caps map[string]config.ModelCapabilities)

func (*Agent) SetReasoningEffort

func (a *Agent) SetReasoningEffort(effort string)

func (*Agent) SetRepoMapBudget added in v0.2.0

func (a *Agent) SetRepoMapBudget(tokens int)

func (*Agent) SetRepoMapEnabled added in v0.2.0

func (a *Agent) SetRepoMapEnabled(enabled bool)

func (*Agent) SetRequireTools added in v0.4.0

func (a *Agent) SetRequireTools(names map[string]bool)

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

func (*Agent) System

func (a *Agent) System() string

func (*Agent) Tools

func (a *Agent) Tools() *tools.Registry

type AssistantText

type AssistantText struct{ Delta string }

type ContextOverflow

type ContextOverflow struct{}

type Event

type Event interface {
	// contains filtered or unexported methods
}

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 Mode

type Mode string
const (
	ModeAct  Mode = "act"
	ModePlan Mode = "plan"
)

type RequiredToolPending added in v0.4.0

type RequiredToolPending struct {
	Names   []string
	Attempt int
}

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 SubagentDefinition struct {
	Name         string
	Description  string
	Model        string
	Timeout      time.Duration
	Tools        SubagentToolMode
	Instructions string
	Path         string
}

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 (*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 (*SubagentSupervisor) SetDefinitions added in v0.1.3

func (s *SubagentSupervisor) SetDefinitions(defs map[string]SubagentDefinition)

func (*SubagentSupervisor) Spawn

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 SubagentTypeInfo struct {
	Name        string
	Builtin     bool
	Description string
	Model       string
	Timeout     time.Duration
	Tools       SubagentToolMode
	Path        string
}

type ThinkingText

type ThinkingText struct{ Delta string }

type ToolFinished

type ToolFinished struct {
	Call   ai.ToolCall
	Result tools.Result
}

type ToolStarted

type ToolStarted struct{ Call ai.ToolCall }

type TurnAborted

type TurnAborted struct{}

type TurnDone

type TurnDone struct{ Reason string }

type TurnError

type TurnError struct{ Err error }

type TurnUsage

type TurnUsage struct {
	Usage ai.Usage
	Cost  float64
}

Jump to

Keyboard shortcuts

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