Versions in this module Expand all Collapse all v2 v2.7.0 Jul 20, 2026 Changes in this version + const CheckpointEventTag + const CheckpointNoteKey + const CompactionEventTag + const CompactionFocusKey + const CompactionMetadataKey + const DefaultAppName + const DefaultCompactionThreshold + const DefaultInstruction + const DefaultSchedulingInstruction + const SubtaskDefaultMaxTurns + const SubtaskDefaultMaxWallclock + var ErrDepthExceeded = errors.New("agent: BackgroundAgentManager: max subagent depth exceeded") + var ErrInboxClosed = errors.New("agent: inbox closed") + var ErrManagerClosed = errors.New("agent: BackgroundAgentManager: closed") + var ErrNoCheckpointer = errors.New("agent: no checkpointer wired (pass WithCheckpointer at agent.New)") + var ErrNoCompactor = errors.New("agent: no compactor wired (pass WithCompactor at agent.New)") + var ErrNoParent = errors.New(...) + var ErrNoSpawner = errors.New(...) + var ErrSubagentExists = errors.New("agent: BackgroundAgentManager: subagent with this name already exists") + var ErrSubagentSpawnerUnavailable = errors.New("agent: subagent spawner unavailable (no BackgroundAgentManager wired)") + var ErrSubtaskSpecInvalid = errors.New("agent: invalid SubtaskSpec") + var ErrTooManyConcurrent = errors.New("agent: BackgroundAgentManager: max concurrent subagents reached") + var ErrUnknownScheduler = errors.New("agent: BackgroundAgentManager: unknown scheduler choice") + var ErrUnknownTool = errors.New("agent: BackgroundAgentManager: unknown tool") + func CurrentSubagentDepth(ctx context.Context) int + func EventlogMetadataExtractor() eventlog.MetadataExtractor + func FormatAutoContinueInbox(messages []string) string + func IsCostCeilingExceeded(err error) bool + func NewBackgroundSpawnTools(mgr *BackgroundAgentManager) []tool.Tool + func NewCheckAgentTool(mgr *BackgroundAgentManager) tool.Tool + func NewListAgentsTool(mgr *BackgroundAgentManager) tool.Tool + func NewMarkTaskDoneTool(getter func() *Agent) tool.Tool + func NewSpawnAgentTool(mgr *BackgroundAgentManager) tool.Tool + func NewSpawnRemoteAgentTool(spawner RemoteAgentSpawner, mgr *BackgroundAgentManager) (tool.Tool, error) + func NewStopAgentTool(mgr *BackgroundAgentManager) tool.Tool + func NewSubagentTool(opts SubagentOptions) (tool.Tool, error) + type Agent struct + func New(model adkmodel.LLM, opts ...Option) (*Agent, error) + func (a *Agent) AgentName() string + func (a *Agent) AppName() string + func (a *Agent) AskSideQuestion(ctx context.Context, question string) (string, error) + func (a *Agent) AttachAddAllow(patterns []string) error + func (a *Agent) AttachAddDeny(patterns []string) error + func (a *Agent) AttachAgents() []attach.AgentInfo + func (a *Agent) AttachAskSideQuestion(ctx context.Context, question string) (string, error) + func (a *Agent) AttachCheckpoint(ctx context.Context, note string) (attach.CheckpointResponse, error) + func (a *Agent) AttachCompact(ctx context.Context, focus string) (attach.CompactResponse, error) + func (a *Agent) AttachContext() attach.ContextInfo + func (a *Agent) AttachInterrupt() bool + func (a *Agent) AttachMCP() attach.MCPInfo + func (a *Agent) AttachMemory() []attach.MemorySource + func (a *Agent) AttachPerms() attach.PermsInfo + func (a *Agent) AttachPricing() attach.PricingInfo + func (a *Agent) AttachPromptBroker() *attach.PromptBroker + func (a *Agent) AttachRefreshPricing(ctx context.Context) (attach.PricingRefreshResponse, error) + func (a *Agent) AttachReload(ctx context.Context) attach.ReloadResponse + func (a *Agent) AttachReplan(ctx context.Context, req attach.ReplanRequest) (attach.ReplanResponse, error) + func (a *Agent) AttachSetManualPricing(req attach.PricingSetRequest) error + func (a *Agent) AttachSkills() []attach.SkillInfo + func (a *Agent) AttachSpawnSubagent(ctx context.Context, spec attach.SubagentSpec) (attach.SubagentSpawnResponse, error) + func (a *Agent) AttachStatus() attach.StatusInfo + func (a *Agent) AttachTools() []attach.ToolInfo + func (a *Agent) AttachUsage() attach.UsageInfo + func (a *Agent) BackgroundManager() *BackgroundAgentManager + func (a *Agent) Checkpoint(ctx context.Context, taskNote string) (CheckpointResult, error) + func (a *Agent) Compact(ctx context.Context, focus string) (CompactionResult, error) + func (a *Agent) CompactIfNeeded(ctx context.Context, focus string) (CompactionResult, error) + func (a *Agent) ContextStats() ContextStats + func (a *Agent) CostCeilingTripped() (bool, string) + func (a *Agent) Description() string + func (a *Agent) DrainInbox() []string + func (a *Agent) EventLog() *eventlog.Handle + func (a *Agent) HasCheckpointer() bool + func (a *Agent) HasCompactor() bool + func (a *Agent) InboxArrived() <-chan struct{} + func (a *Agent) Inject(message string) error + func (a *Agent) InjectAs(message string, caller auth.Caller) error + func (a *Agent) Interrupt() bool + func (a *Agent) ModelName() string + func (a *Agent) PendingInboxCount() int + func (a *Agent) RequestWake() + func (a *Agent) ResetCostCeiling() + func (a *Agent) Run(ctx context.Context, prompt string) iter.Seq2[*session.Event, error] + func (a *Agent) RunSubtask(ctx context.Context, spec SubtaskSpec) (SubtaskResult, error) + func (a *Agent) RunWithContents(ctx context.Context, contents []*genai.Content) iter.Seq2[*session.Event, error] + func (a *Agent) SessionID() string + func (a *Agent) SessionService() session.Service + func (a *Agent) SetAttachEmitter(f func(eventType string, payload any)) + func (a *Agent) Tools() []tool.Tool + func (a *Agent) UserID() string + func (a *Agent) WakeRequested() <-chan struct{} + type Alert struct + From string + Kind string + Text string + Timestamp time.Time + type AutonomousHandle struct + func StartAutonomous(ctx context.Context, build BuildFunc, goal string, opts ...AutonomousOption) (*AutonomousHandle, error) + func (h *AutonomousHandle) Done() <-chan struct{} + func (h *AutonomousHandle) Inject(message string) error + func (h *AutonomousHandle) InjectAs(message string, caller auth.Caller) error + func (h *AutonomousHandle) Pause() error + func (h *AutonomousHandle) Ready() <-chan struct{} + func (h *AutonomousHandle) RequestWake() + func (h *AutonomousHandle) Resume() error + func (h *AutonomousHandle) Status() AutonomousStatus + func (h *AutonomousHandle) Stop() error + func (h *AutonomousHandle) Wait() (RunResult, error) + type AutonomousOption func(*autoConfig) + func WithBeforeTurn(cb func(ctx context.Context, turnNo int) error) AutonomousOption + func WithContinuationPrompt(s string) AutonomousOption + func WithDoneToolDescription(desc string) AutonomousOption + func WithDoneToolName(name string) AutonomousOption + func WithMaxCost(usd float64) AutonomousOption + func WithMaxDefer(d time.Duration) AutonomousOption + func WithMaxTokens(input, output int) AutonomousOption + func WithMaxTurns(n int) AutonomousOption + func WithMaxWallclock(d time.Duration) AutonomousOption + func WithPerTurnTimeout(d time.Duration) AutonomousOption + func WithPermissionsGate(g *permissions.Gate) AutonomousOption + func WithPricing(p usage.Pricing) AutonomousOption + func WithProgress(cb func(turn int, ev *session.Event)) AutonomousOption + func WithRetryPolicy(p RetryPolicy) AutonomousOption + func WithScheduleToolDescription(desc string) AutonomousOption + func WithScheduleToolMaxDefer(d time.Duration) AutonomousOption + func WithScheduleToolName(name string) AutonomousOption + func WithScheduler(s coretools.Scheduler) AutonomousOption + func WithTracker(t *usage.Tracker, p usage.Pricing) AutonomousOption + type AutonomousStatus int + const AutonomousCompleted + const AutonomousFailed + const AutonomousPaused + const AutonomousRunning + const AutonomousStopped + func (s AutonomousStatus) String() string + type BackgroundAgentManager struct + func NewBackgroundAgentManager(opts ...BackgroundManagerOption) (*BackgroundAgentManager, error) + func (m *BackgroundAgentManager) Alerts() <-chan Alert + func (m *BackgroundAgentManager) Close() error + func (m *BackgroundAgentManager) Get(name string) (*BackgroundHandle, bool) + func (m *BackgroundAgentManager) List() []*BackgroundHandle + func (m *BackgroundAgentManager) OnAlert(h func(Alert)) + func (m *BackgroundAgentManager) Parent() *Agent + func (m *BackgroundAgentManager) PrependPendingAlerts(prompt string) string + func (m *BackgroundAgentManager) Spawn(ctx context.Context, parentBranch string, spec BackgroundSpec) (*BackgroundHandle, error) + func (m *BackgroundAgentManager) Stop(name string) error + type BackgroundBudgets struct + MaxCost float64 + MaxTurns int + MaxWallclock time.Duration + PerTurnTimeout time.Duration + type BackgroundHandle struct + Branch string + Name string + StartedAt time.Time + func (h *BackgroundHandle) Done() <-chan struct{} + func (h *BackgroundHandle) Err() error + func (h *BackgroundHandle) Result() *RunResult + func (h *BackgroundHandle) Status() BackgroundStatus + type BackgroundManagerOption func(*bgMgrConfig) + func WithBackgroundAlertBuffer(n int) BackgroundManagerOption + func WithBackgroundCatalog(tools []tool.Tool) BackgroundManagerOption + func WithBackgroundDefaultBudgets(b BackgroundBudgets) BackgroundManagerOption + func WithBackgroundDefaultScheduler(s coretools.Scheduler) BackgroundManagerOption + func WithBackgroundGate(g *permissions.Gate) BackgroundManagerOption + func WithBackgroundMaxConcurrent(n int) BackgroundManagerOption + func WithBackgroundMaxDepth(n int) BackgroundManagerOption + func WithBackgroundProvider(p models.Provider, modelID string) BackgroundManagerOption + type BackgroundSpec struct + Budgets BackgroundBudgets + Extras []string + Goal string + Name string + Scheduler string + SystemPrompt string + Tools []string + type BackgroundStatus int + const StatusCompleted + const StatusDeferred + const StatusFailed + const StatusRunning + const StatusStopped + func (s BackgroundStatus) String() string + type BuildFunc func(extraTools []tool.Tool) (*Agent, error) + type CheckpointResult struct + CheckpointEventID string + Duration time.Duration + Skipped bool + SummaryText string + TaskNote string + type Checkpointer interface + CheckpointInstruction func(taskNote string) string + ShouldCheckpoint func(ctx context.Context, a *Agent) bool + func NewDefaultCheckpointer() Checkpointer + type CompactionResult struct + Duration time.Duration + Skipped bool + SummaryEventID string + SummaryText string + type Compactor interface + ShouldCompact func(ctx context.Context, a *Agent) bool + SummarizerInstruction func(focus string) string + func NewDefaultCompactor() Compactor + type ContextStats struct + CheckpointCount int + CompactionCount int + DigestSavings usage.DigestSavingsTotals + LastCheckpointNote string + LastCheckpointTime time.Time + LastCompactionFocus string + LastCompactionTime time.Time + ModelBreakdown map[string]usage.Totals + SubtaskCostUSD float64 + SubtaskCount int + SubtaskInputTokens int + SubtaskOutputTokens int + TotalSummaryChars int + type CostCeiling struct + MaxSessionUSD float64 + MaxTurnUSD float64 + type DefaultCheckpointer struct + func (c *DefaultCheckpointer) CheckpointInstruction(taskNote string) string + func (c *DefaultCheckpointer) ShouldCheckpoint(_ context.Context, _ *Agent) bool + type DefaultCompactor struct + Threshold float64 + ThresholdByTier map[string]float64 + TierClassifier func(modelID string) string + func (c *DefaultCompactor) ShouldCompact(_ context.Context, a *Agent) bool + func (c *DefaultCompactor) SummarizerInstruction(focus string) string + type Option func(*options) + func WithAppName(s string) Option + func WithAttachMCPProvider(fn func() attach.MCPInfo) Option + func WithAttachMemoryProvider(fn func() []attach.MemorySource) Option + func WithAttachPricingProvider(fn func() attach.PricingInfo) Option + func WithAttachPricingSetter(fn func(req attach.PricingSetRequest) error) Option + func WithAttachPromptBroker(b *attach.PromptBroker) Option + func WithAttachRefreshPricer(fn func(ctx context.Context) (attach.PricingRefreshResponse, error)) Option + func WithAttachReloader(fn func(ctx context.Context) attach.ReloadResponse) Option + func WithAttachReplanner(...) Option + func WithAttachSkillsProvider(fn func() []attach.SkillInfo) Option + func WithBackgroundManager(mgr *BackgroundAgentManager) Option + func WithCheckpointer(c Checkpointer) Option + func WithCompactor(c Compactor) Option + func WithCostCeiling(c CostCeiling) Option + func WithDescription(s string) Option + func WithEventHook(onEvent func(*session.Event), onTurnEnd func()) Option + func WithEventLog(h *eventlog.Handle) Option + func WithGate(g *permissions.Gate) Option + func WithInstruction(s string) Option + func WithName(s string) Option + func WithPostConstruct(f func(*Agent)) Option + func WithSession(userID, sessionID string) Option + func WithSessionRegistry(r attachRegistrar) Option + func WithSessionService(s session.Service) Option + func WithStreaming(m adkagent.StreamingMode) Option + func WithSubagents(agents []*Agent) Option + func WithSystemInstructionPrefix(prefix string) Option + func WithTools(ts []tool.Tool) Option + func WithToolsets(ts []tool.Toolset) Option + func WithUsageTracker(t *usage.Tracker) Option + func WithWatchdog(w watchdog.Watchdog, onAlert func(watchdog.Alert)) Option + type RemoteAgentEvent struct + Kind string + Text string + Timestamp time.Time + type RemoteAgentHandle interface + Events func() <-chan RemoteAgentEvent + ID func() string + Status func(ctx context.Context) (RemoteAgentStatus, error) + Stop func(ctx context.Context) error + type RemoteAgentSpawner interface + Spawn func(ctx context.Context, spec RemoteAgentSpec) (RemoteAgentHandle, error) + func RefuseRemoteAgentSpawner(reason string) RemoteAgentSpawner + type RemoteAgentSpec struct + Budgets BackgroundBudgets + Extras []string + Goal string + ID string + Name string + SystemPrompt string + Tools []string + type RemoteAgentStatus int + const RemoteStatusCompleted + const RemoteStatusFailed + const RemoteStatusPending + const RemoteStatusRunning + const RemoteStatusStopped + func (s RemoteAgentStatus) String() string + type ResumeBuildFunc func(extras []tool.Tool, sessionID string) (*Agent, error) + type RetryDecision int + const AbortRun + const RetryTurn + const SkipTurn + type RetryPolicy func(turnErr error, attempt int) RetryDecision + type RunResult struct + CostUSD float64 + DoneDetail string + Duration time.Duration + FinalText string + InputTokens int + NextWakeAt time.Time + OutputTokens int + Reason StopReason + Turns int + func ResumeAutonomous(ctx context.Context, build ResumeBuildFunc, ref SessionRef, ...) (RunResult, error) + func RunAutonomous(ctx context.Context, build func(extraTools []tool.Tool) (*Agent, error), ...) (RunResult, error) + type SessionRef struct + AppName string + Handle *eventlog.Handle + SessionID string + UserID string + type StopReason string + const StopReasonCompleted + const StopReasonContextCancelled + const StopReasonDeferred + const StopReasonMaxCost + const StopReasonMaxTokens + const StopReasonMaxTurns + const StopReasonRetryAborted + const StopReasonWallclockExceeded + type SubagentOptions struct + Branch string + Description string + Inner *Agent + MaxDepth int + Name string + ParentAppName string + ParentService session.Service + ParentSessionID string + ParentUserID string + type SubtaskBudgets struct + MaxTurns int + MaxWallclock time.Duration + type SubtaskResult struct + CostUSD float64 + Digest string + Duration time.Duration + InputTokens int + Name string + OutputTokens int + Truncated bool + TurnsUsed int + type SubtaskSpec struct + Budgets SubtaskBudgets + Model adkmodel.LLM + Name string + SystemPrompt string + Tools []tool.Tool + UserMessage string v2.7.0-dev.5 Jul 20, 2026