subagent

package
v0.97.8 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package subagent runs a specialized agent loop in isolation so a primary agent can delegate a self-contained task and receive only the final result back.

Index

Constants

This section is empty.

Variables

View Source
var ErrMaxDepth = errors.New("subagent: max delegation depth exceeded")

ErrMaxDepth is returned when subagent nesting exceeds the configured delegation depth.

View Source
var ErrNoModel = errors.New("subagent: model is required")

ErrNoModel is returned when a subagent run is requested without an LLM model.

Functions

func FinalText

func FinalText(messages []agent.AgentMessage) string

FinalText returns the concatenated text of the last assistant message in the run.

Types

type Definition

type Definition struct {
	// Name is the unique subagent identifier referenced by the task tool.
	Name string
	// Description tells the primary agent when to delegate to this subagent.
	Description string
	// SystemPrompt is the isolated instruction set for the subagent loop.
	SystemPrompt string
	// Tools restricts which registered tools the subagent may call.
	Tools []string
	// Skills restricts which agent skills are injected into the subagent prompt and read_skill allowlist.
	Skills []string
	// Model optionally overrides the model used for the subagent loop.
	Model string
}

Definition describes a specialized subagent that the primary agent can delegate to. Tools is an allowlist of tool names exposed to the subagent; empty means all tools registered on the provided registry.

type Deps

type Deps struct {
	// Model is the resolved LLM client for the subagent loop.
	Model llms.Model
	// Registry holds the tools available to the subagent after allowlist filtering.
	Registry *tool.Registry
	// Config is the loop configuration; defaults are applied when zero.
	Config agent.Config
	// Depth is the current delegation depth of the caller (0 for the primary agent).
	Depth int
	// MaxDepth caps nested delegation; values <= 0 default to 1.
	MaxDepth int
}

Deps carries the runtime dependencies required to run a subagent loop in isolation.

type ProgressFn

type ProgressFn func(update string)

ProgressFn receives human-readable progress updates from the subagent run.

type Result

type Result struct {
	// Text is the concatenated assistant text produced by the subagent.
	Text string
	// Messages are all messages generated during the subagent run.
	Messages []agent.AgentMessage
}

Result is the outcome of a completed subagent run.

func Run

func Run(ctx context.Context, def Definition, deps Deps, prompt string, onProgress ProgressFn) (Result, error)

Run executes a subagent in a fresh, isolated context and returns its final assistant text. The run does not share the parent conversation and is not persisted to any session tree, matching the mainstream subagent contract.

Jump to

Keyboard shortcuts

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