agents

package
v0.6.76 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: AGPL-3.0, Apache-2.0, MIT Imports: 36 Imported by: 0

Documentation

Overview

Package agents is the daemon's ACP session service (DBX-41, DBX-48): one ACP connection per agent type, shared by that agent's threads; threads mapped onto ACP's session built-ins; the prompt lifecycle with the per-instance running-thread limit; permission and elicitation interactions; config options (models included); slash commands; subagent lineage; and the live entity store whose normalized, v2-shaped changes are appended to the daemon's event log, with settled entities written to the box's transcript.

Index

Constants

View Source
const (
	// MaxAttachments and MaxAttachmentBytes bound one prompt; console enforces the same limits before sending.
	MaxAttachments     = 10
	MaxAttachmentBytes = 24 << 20
)
View Source
const AttachmentsDir = ".plural/attachments"

AttachmentsDir holds prompt attachments, relative to the home directory: <dir>/<prompt id>/<name>.

View Source
const DefaultMaxRunningThreads = 4

DefaultMaxRunningThreads is the per-instance running-thread limit (section 4.6b).

View Source
const PendingInteractionBusy = 15 * time.Minute

PendingInteractionBusy is how long a pending interaction keeps the box awake (section 4.3a).

View Source
const ProbeTimeout = 90 * time.Second

ProbeTimeout bounds one agent's probe.

Variables

View Source
var Version = "dev"

Version is the daemon version sent as ACP clientInfo.

Functions

func AutonomyPrincipal

func AutonomyPrincipal(level devboxv1.Autonomy) *devboxv1.Principal

AutonomyPrincipal is who answered interactions the daemon approved by policy.

func AutonomyValue

func AutonomyValue(a devboxv1.Autonomy) string

AutonomyValue is a level's config option value: manual, auto or full.

func Probe

Probe starts each agent with its golden-boot configuration, opens a scratch session and reports the agent's capabilities, models, config options and initial slash commands (section 4.2a).

func ReviewerPrincipal

func ReviewerPrincipal() *devboxv1.Principal

ReviewerPrincipal is who answered interactions the daemon's reviewer approved at AUTO.

func ToStatus

func ToStatus(err error) error

ToStatus converts agent failures to gRPC errors with typed reasons; other errors pass through.

Types

type AgentCallError

type AgentCallError struct {
	Op  string
	Err *devboxv1.AgentError
	// contains filtered or unexported fields
}

AgentCallError is a failed agent call with its typed error.

func (*AgentCallError) Error

func (e *AgentCallError) Error() string

func (*AgentCallError) Unwrap

func (e *AgentCallError) Unwrap() error

type Emitter

type Emitter interface {
	Emit(ev *devboxv1.DaemonEvent)
}

Emitter appends events to the daemon's event log.

type EmitterFunc

type EmitterFunc func(ev *devboxv1.DaemonEvent)

EmitterFunc adapts a function to Emitter.

func (EmitterFunc) Emit

func (f EmitterFunc) Emit(ev *devboxv1.DaemonEvent)

Emit implements Emitter.

type Launcher

type Launcher interface {
	Spec(launch *devboxv1.AgentLaunch, endpoints *devboxv1.HarnessEndpoints, bootModel string) (*harness.Spec, error)
}

Launcher builds an agent's launch spec.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager owns every agent connection, thread and subagent session in the instance.

func New

func New(opts Options) *Manager

New returns a Manager. Call Start to load persisted threads and run background work.

func (*Manager) BusyReasons

func (m *Manager) BusyReasons(now time.Time) []*devboxv1.BusyReason

BusyReasons reports agent activity for idle detection: running turns and fresh pending interactions.

func (*Manager) CancelPrompt

func (m *Manager) CancelPrompt(ctx context.Context, ref *devboxv1.ThreadRef) (bool, error)

CancelPrompt cancels the thread's current turn (`session/cancel`). Held prompts stay queued.

func (*Manager) CloseThread

func (m *Manager) CloseThread(ctx context.Context, ref *devboxv1.ThreadRef) (*devboxv1.Session, error)

CloseThread cancels the thread's turn and closes its session (`session/close`, or just drops it).

func (*Manager) Configure

func (m *Manager) Configure(instanceID string, agent devboxv1.AgentType, model string, options []*devboxv1.ConfigOptionSetting, launches []*devboxv1.AgentLaunch, maxRunning int)

Configure applies the instance configuration from Initialize.

func (*Manager) Connections

func (m *Manager) Connections() []*devboxv1.AgentConnection

Connections returns the live agent connections.

func (*Manager) CreateThread

func (m *Manager) CreateThread(ctx context.Context, req *devboxv1.CreateThreadRequest) (*devboxv1.Session, error)

CreateThread starts a thread: `session/new` with the thread's cwd and MCP servers, then the requested model and config options. Idempotent on thread_id.

func (*Manager) DeleteThread

func (m *Manager) DeleteThread(ctx context.Context, ref *devboxv1.ThreadRef) (*devboxv1.Session, bool, error)

DeleteThread closes the thread and deletes the agent-side session when the agent supports it.

func (*Manager) Flush

func (m *Manager) Flush()

Flush writes settled entities to the transcript, emits dirty session rows and the instance aggregate, and persists thread state.

func (*Manager) Forget

func (m *Manager) Forget()

Forget drops every thread and its transcript and stops every connection: the box was restored from a snapshot as a new instance, whose console has none of the old instance's threads. Agent-side sessions stay importable.

func (*Manager) ForkThread

func (m *Manager) ForkThread(ctx context.Context, req *devboxv1.ForkThreadRequest) (*devboxv1.Session, error)

ForkThread forks the thread's session into a new thread (`session/fork`). UNSUPPORTED when not advertised.

func (*Manager) ImportThread

func (m *Manager) ImportThread(ctx context.Context, req *devboxv1.ImportThreadRequest) (*devboxv1.Session, error)

ImportThread adopts a session the agent listed: `session/resume` with replay (or `session/load`), with the replayed history kept as the new thread's transcript.

func (*Manager) Interactions

func (m *Manager) Interactions() []*devboxv1.Interaction

Interactions returns pending interactions.

func (*Manager) Launch

Launch returns the launch settings for an agent.

func (*Manager) ListCommands

func (m *Manager) ListCommands(ref *devboxv1.ThreadRef, sessionID string) ([]*devboxv1.AvailableCommand, error)

ListCommands returns a session's live slash commands.

func (*Manager) ListThreads

func (m *Manager) ListThreads(ctx context.Context, includeImportable bool) (*devboxv1.ListThreadsResponse, error)

ListThreads implements the RPC; importable sessions come from session/list on each launched agent.

func (*Manager) Prompt

Prompt accepts a prompt for a thread. A prompt to an idle thread under the running-thread limit is sent at once; otherwise it is held (QUEUED) and the thread shows WAITING while it's behind the limit. A repeated prompt_id is a no-op (DUPLICATE).

func (*Manager) RecentPrompts

func (m *Manager) RecentPrompts(threadID string) []string

RecentPrompts are the text of a thread's last few prompts, oldest first.

func (*Manager) RespondInteraction

func (m *Manager) RespondInteraction(req *devboxv1.RespondInteractionRequest) (*devboxv1.Interaction, error)

RespondInteraction answers a pending interaction. Answering one that is no longer pending returns it unchanged with STALE_REVISION.

func (*Manager) ResumeThread

func (m *Manager) ResumeThread(ctx context.Context, ref *devboxv1.ThreadRef, replay bool) (*devboxv1.Session, error)

ResumeThread reopens a closed thread or reattaches a detached one.

func (*Manager) Sessions

func (m *Manager) Sessions() *devboxv1.GetSessionsResponse

Sessions returns every thread and subagent row, oldest first, and the live agent connections.

func (*Manager) SetAgentBilling

func (m *Manager) SetAgentBilling(ctx context.Context, launch *devboxv1.AgentLaunch) (*devboxv1.AgentConnection, []string, error)

SetAgentBilling restarts one agent's connection with new billing and resumes its open threads on it.

func (*Manager) SetAutonomy

func (m *Manager) SetAutonomy(p *devboxv1.AutonomyPolicy)

SetAutonomy sets the runner's autonomy policy. Unset fields default to AUTO.

func (*Manager) SetDecisionReview

func (m *Manager) SetDecisionReview(on bool)

SetDecisionReview sets whether the AI proxy serves decisions, which lets AUTO run with the daemon reviewing permission requests where the agent's own reviewer isn't available.

func (*Manager) SetThreadConfigOption

func (m *Manager) SetThreadConfigOption(ctx context.Context, ref *devboxv1.ThreadRef, setting *devboxv1.ConfigOptionSetting) ([]*devboxv1.ConfigOption, error)

SetThreadConfigOption implements the RPC.

func (*Manager) SettleAll

func (m *Manager) SettleAll()

SettleAll settles every in-flight entity (PrepareSuspend).

func (*Manager) Start

func (m *Manager) Start() error

Start loads persisted threads, re-resumes open threads in the background and runs the settle sweeper and index flusher.

func (*Manager) Stop

func (m *Manager) Stop(ctx context.Context)

Stop stops every agent connection.

func (*Manager) StopAgents

func (m *Manager) StopAgents(match func(devboxv1.AgentType, devboxv1.BillingMode) bool) []devboxv1.AgentType

StopAgents stops agent connections (PrepareSuspend for shared snapshots stops subscription Codex). Threads reattach on the next prompt.

func (*Manager) Threads

func (m *Manager) Threads() []*devboxv1.Session

Threads returns the index rows of every thread and subagent.

func (*Manager) Timeline

Timeline pages a session's transcript (forwards from after_position, backwards from before_position, or the newest page), merged with its in-flight entities, and returns the event log head the page reflects: live deltas past it apply on top.

func (*Manager) UpdateQueuedPrompt

UpdateQueuedPrompt edits, drops or promotes a held prompt. A prompt that already started (or was dropped) is left alone and reported as not updated, so a stale shelf can't touch a turn in progress.

type Options

type Options struct {
	Home     string
	StateDir string
	Emitter  Emitter
	// Head is the event log's latest offset, which timeline pages report as their delta offset.
	Head func() uint64
	// Transcript stores settled entities; in memory when nil.
	Transcript *transcript.Store
	Launcher   Launcher
	// Supervisor runs the harness processes.
	Supervisor *proc.Supervisor
	Clock      clock.Clock
	Log        *slog.Logger
	MaxRunning int
	// Endpoints returns the harness endpoints from Initialize.
	Endpoints func() *devboxv1.HarnessEndpoints
	// Worktrees creates thread worktrees (workspace package).
	Worktrees WorktreeFunc
	// Checkouts lists the workspace's checkouts for the instance aggregate.
	Checkouts func() []*devboxv1.Checkout
	// ExtraMCPServers are added to every session (e.g. the Playwright MCP driving the sandbox browser).
	ExtraMCPServers func() []any
	// OnAgentProcess is told about every harness process start and stop (credential managers hook in here).
	OnAgentProcess func(agent devboxv1.AgentType, started bool)
	// ReviewClient calls the AI proxy's decisions route for reviewed AUTO; http.DefaultClient when nil.
	ReviewClient *http.Client
}

Options configure a Manager.

type ProbeOptions

type ProbeOptions struct {
	Launcher   Launcher
	Supervisor *proc.Supervisor
	Log        *slog.Logger
	// Present reports whether an agent's ACP command exists (nil: always).
	Present func(devboxv1.AgentType) bool
	// AdapterVersion is the image's pinned adapter version.
	AdapterVersion func(devboxv1.AgentType) string
	// ScratchDir is where probe sessions run.
	ScratchDir string
	Endpoints  *devboxv1.HarnessEndpoints
}

ProbeOptions configure Probe.

type WorktreeFunc

type WorktreeFunc func(threadID string, repos []string) (string, error)

WorktreeFunc creates per-thread worktrees and returns the session cwd.

Jump to

Keyboard shortcuts

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