delegate

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package delegate lets an agent hand work to other agents: the delegate tool runs a full sub-agent (its own thread and sandbox, a role-specific prompt) and returns its report, and the prompt sections tell a thread which role and task it was started for.

Index

Constants

View Source
const (
	DefaultMaxDepth    = 2
	DefaultMaxParallel = 3
	DefaultTimeout     = 30 * time.Minute
)

Defaults and limits.

Variables

This section is empty.

Functions

func DefaultRoles

func DefaultRoles() map[string]Role

DefaultRoles is the built-in catalogue: planner, coder, reviewer, tester and explorer.

func Roster

func Roster(catalogue ...map[string]Role) agent.PromptSection

Roster lists the roles a thread may delegate to. Add it only where the delegate tool is offered; the tool's own description carries the same list for models that do not read the system prompt closely, so this is the short form. The optional argument is the catalogue (default: DefaultRoles).

func Section

func Section(st factory.Store, roles map[string]Role) agent.PromptSection

Section tells a thread that was started for a factory task what it is for: its role instructions (the thread's own when set, else the role's from roles; nil is DefaultRoles), the task, the repository and branch, and the policy it runs under. Ordinary threads get nothing.

Types

type Options

type Options struct {
	// Spawner runs the sub-agents.
	Spawner factory.Spawner
	// Store reads the calling thread's ThreadInfo: its login, task, policy and
	// repository are inherited, its ParentThreadID chain gives the depth. Nil
	// treats every thread as an ordinary one at depth 0.
	Store factory.Store
	// Roles is the catalogue (nil: DefaultRoles).
	Roles map[string]Role
	// MaxDepth is how deep delegation nests: a thread already that many
	// delegations below an ordinary thread gets no delegate tool (0: 2).
	MaxDepth int
	// MaxParallel bounds the sub-agents one run has running at once (0: 3).
	MaxParallel int
	// Models are the model ids the caller may pick with the model argument;
	// empty means the caller cannot choose and the role or spawner default applies.
	Models []string
	// Timeout bounds one delegation (0: 30 minutes).
	Timeout time.Duration
	// Task loads the factory task of a thread so the sub-agent also gets the
	// task's title and spec. Optional.
	Task func(ctx context.Context, taskID string) (*factory.Task, error)
	// OnSpend is told what each finished sub-run spent, for the thread's task
	// (only when the thread has one). Optional.
	OnSpend func(ctx context.Context, taskID string, d factory.Spend)
}

Options configures a Provider.

type Provider

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

Provider offers the delegate and delegate_many tools.

func New

func New(o Options) *Provider

New returns a Provider; zero Options fields take their defaults.

func (*Provider) Name

func (p *Provider) Name() string

Name implements tools.Provider.

func (*Provider) Tools

func (p *Provider) Tools(ctx context.Context, rc tools.RunContext) ([]ai.BaseTool, func(), error)

Tools implements tools.Provider. A thread already at the maximum delegation depth gets no tools, which is what bounds recursion.

type Role

type Role struct {
	Name string
	// Description is the one-liner the delegating agent reads to pick a role.
	Description string
	// Instructions is the role's prompt text, added to the sub-agent's system prompt.
	Instructions string
	// ReadOnly roles run in plan mode: nothing they do changes anything.
	ReadOnly bool
	// Model "" uses the spawner's default model.
	Model string
}

Role is a kind of sub-agent the delegate tool can start.

Jump to

Keyboard shortcuts

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