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

subagent

package
v0.4.21 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package subagent runs child agents in-process.

It lives under runtime/ rather than plugins/ because it must import runtime/agent to construct a child — the same reason agent/coding is registered from runtime/agent. Kind names are independent of package paths.

Why the child needs its own tool runtime

Wiring the parent's tool runtime here would be a dependency cycle:

tools.default → tool.subagent.default → subagent.default → tools.default

pluginkit rejects that at build time. So deps.tools must point at a sibling runtime instance, and since that instance does not mount tool/subagent, "only the main agent can delegate" stops being a policy and becomes structural.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DelegationWallClock added in v0.3.55

func DelegationWallClock(req capsubagent.Request, configured time.Duration) (time.Duration, error)

DelegationWallClock returns the wall-clock bound for one delegation. Per-call timeoutSeconds on the request wins when set and positive; otherwise configured applies.

func HelpCommand added in v0.1.2

func HelpCommand(ws workspace.Service, dirs []string) agentkit.Command

HelpCommand exposes the subagent definition help slash command.

func ModelCommand added in v0.4.9

func ModelCommand(ws workspace.Service, spawner subagent.Spawner) agentkit.Command

ModelCommand exposes the /submodel slash command: workspace-wide global model binds for in-process subagents (models["sub:<name>"] and the models["sub:*"] wildcard). Session-scoped model binds never target subagents, so the command has no session store and no -g flag — every read/write goes through the workspace overlay.

func New

func New(cfg Config, deps Deps) (subagent.Spawner, error)

New registers subagent/inprocess: Run a child agent in-process from an agents/<name>.md definition and return only its conclusion.

Best practices:

  • deps.tools must be a sibling tools/runtime instance that does NOT mount tool/subagent: wiring the parent's runtime is a dependency cycle, and the separate instance is what makes 'only the main agent delegates' structural.
  • Give the child a narrower tool set than the parent — read-only is the common case. Delegation is for context isolation, not for a second agent editing the same workspace.
  • Pair with prompt/section/subagents so the parent can see who it may delegate to; the delegate tool's description is static and cannot list definitions read from disk.
  • Raise the delegate entry in the parent's toolTimeouts: a child agent takes far longer than a normal tool call.

func NewComposite added in v0.1.24

func NewComposite(_ struct{}, deps CompositeDeps) (subagent.Spawner, error)

NewComposite registers subagent/composite: merge inprocess and loop-agent delegatable catalogs.

func NewLoopAgent added in v0.1.24

func NewLoopAgent(cfg LoopAgentConfig, deps LoopAgentDeps) (subagent.Spawner, error)

NewLoopAgent registers subagent/loop-agent: delegate to a Loop agent instance and return only its conclusion.

Types

type CompositeDeps added in v0.1.24

type CompositeDeps struct {
	Inprocess subagent.Spawner `json:"inprocess"`
	Loop      subagent.Spawner `json:"loop,omitempty"`
}

CompositeDeps merges multiple spawners. Inprocess definitions win on name conflict.

type Config

type Config struct {
	// Dirs are definition directories in precedence order; defaults to local:agents then global:agents.
	Dirs []string `json:"dirs,omitempty"`
	// TimeoutSeconds is wall clock for one delegation; 0 leaves the delegate tool's own timeout as the only bound.
	TimeoutSeconds int `json:"timeoutSeconds,omitempty"`
}

func (*Config) SetDefaults added in v0.3.48

func (c *Config) SetDefaults()

SetDefaults implements pluginkit.Defaulter.

func (*Config) Validate added in v0.3.48

func (c *Config) Validate() error

Validate implements pluginkit.Validator.

type Deps

type Deps struct {
	Workspace    workspace.Service        `json:"workspace"`
	SessionStore agentkit.SessionStore    `json:"sessionStore"`
	LLM          agentkit.LLMProvider     `json:"llm"`
	Tools        agentkit.ToolRuntime     `json:"tools"`
	Prompt       agentkit.PromptAssembler `json:"prompt"`
	Hooks        agentkit.HookRuntime     `json:"hooks,omitempty"`
	Compaction   []compaction.Service     `json:"compaction,omitempty"`
}

type LoopAgentConfig added in v0.1.24

type LoopAgentConfig struct {
	// Agents lists Loop-backed subagents exposed to the delegate tool.
	Agents []LoopAgentEntry `json:"agents,omitempty"`
	// TimeoutSeconds is the default wall clock for one delegation.
	TimeoutSeconds int `json:"timeoutSeconds,omitempty"`
	// MaxConcurrentJobsPerSession limits async jobs per parent session (channel semaphore).
	// Zero means no limit.
	MaxConcurrentJobsPerSession int `json:"maxConcurrentJobsPerSession,omitempty"`
}

LoopAgentConfig configures subagent/loop-agent.

func (*LoopAgentConfig) Validate added in v0.3.48

func (c *LoopAgentConfig) Validate() error

Validate implements pluginkit.Validator.

type LoopAgentDeps added in v0.1.24

type LoopAgentDeps struct {
	SessionStore agentkit.SessionStore `json:"sessionStore"`
	Agents       []agentkit.Agent      `json:"agents"`
	Telemetry    captelemetry.Exporter `json:"telemetry,omitempty"`
}

LoopAgentDeps holds injected capabilities for Loop-backed delegation.

type LoopAgentEntry added in v0.1.24

type LoopAgentEntry struct {
	Name           string `json:"name"`
	Description    string `json:"description"`
	Agent          string `json:"agent"`
	Async          bool   `json:"async,omitempty"`
	TimeoutSeconds int    `json:"timeoutSeconds,omitempty"`
}

LoopAgentEntry configures one delegatable Loop agent.

type LoopAgentSpawner added in v0.1.24

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

func (*LoopAgentSpawner) BindSubmit added in v0.1.24

func (s *LoopAgentSpawner) BindSubmit(fn capschedule.SubmitFunc)

func (*LoopAgentSpawner) Definitions added in v0.1.24

func (*LoopAgentSpawner) Run added in v0.1.24

type Spawner

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

func (*Spawner) BindSubmit added in v0.3.65

func (s *Spawner) BindSubmit(fn capschedule.SubmitFunc)

BindSubmit receives the runner inbound submit func; required for async delegation (the [subagent-complete] follow-up is delivered through it).

func (*Spawner) Commands added in v0.1.2

func (s *Spawner) Commands() []agentkit.Command

Commands implements agentkit.CommandProvider: subagent/inprocess contributes its own slash commands (/subagent, /submodel), collected by commands/registry through the generic WireContributions channel.

func (*Spawner) Definitions

func (s *Spawner) Definitions(ctx context.Context) ([]subagent.Definition, error)

func (*Spawner) Run

Directories

Path Synopsis
Package definition loads subagent definitions (agents/<name>.md files) and renders them for help output.
Package definition loads subagent definitions (agents/<name>.md files) and renders them for help output.

Jump to

Keyboard shortcuts

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