subagent

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Delegation depth matches subagent/src/depth.ts: roots start at zero and each child adds one. Use the maximum persisted and runtime depth so resumed children cannot lower their depth and gain extra delegation budget.

The S02 in-process fork backend reuses process context, including the LLM adapter and tool pipeline, to execute a subtask and return lineage and output. It backs the in-process acceptance tests; ACP and fork-copy remain interface stubs.

Package subagent defines three delegation backends (S02), matching subagent and providers upstream. Provider separates launching from task execution. InProcess reuses agent context; ACP and ForkCopy are stable-interface stubs. ForkLineage records parent/child sessions for causal attribution (M33). Handle manages lifecycle: Drain waits for completion and persistence, while Dispose releases the child as part of cascading parent cleanup.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidDepth = errors.New("subagent: depth must be a non-negative integer")

ErrInvalidDepth indicates a depth or limit that is not a nonnegative integer.

Functions

func CanDelegate

func CanDelegate(depth, maxDepth int) bool

CanDelegate requires depth below maxDepth; negative maxDepth means unlimited.

func ChildDepth

func ChildDepth(parentDepth int) (int, error)

ChildDepth returns the parent depth plus one.

func IsUnknownProvider

func IsUnknownProvider(err error) bool

IsUnknownProvider identifies unknown-backend errors.

func ResolveDepth

func ResolveDepth(headerDepth, runtimeDepth int) (int, error)

ResolveDepth uses the larger persisted or runtime depth; runtime can only deepen it.

Types

type ErrUnknownProvider

type ErrUnknownProvider struct{ Name string }

ErrUnknownProvider indicates an unregistered backend.

func (*ErrUnknownProvider) Error

func (e *ErrUnknownProvider) Error() string

type ForkLineage

type ForkLineage struct {
	Parent  *brand.SessionID `json:"parent,omitempty"` // Parent session; nil for a top-level agent.
	Session brand.SessionID  `json:"session"`          // Child session.
}

ForkLineage records a parent-to-child session relationship.

type Handle

type Handle struct {
	Provider string // Owning backend name.
	Lineage  ForkLineage
	// contains filtered or unexported fields
}

Handle manages a child agent's lifecycle.

func (*Handle) Dispose

func (h *Handle) Dispose()

Dispose marks the child disposed for cascading parent cleanup.

func (*Handle) Drain

func (h *Handle) Drain(ctx context.Context) error

Drain waits for completion or context cancellation.

type InProcessProvider

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

InProcessProvider implements in-process forks.

func NewInProcessProvider

func NewInProcessProvider(runner InProcessRunner) *InProcessProvider

NewInProcessProvider creates a provider; nil runner uses a synchronous placeholder.

func (*InProcessProvider) Name

func (p *InProcessProvider) Name() string

Name implements Provider.

func (*InProcessProvider) Spawn

func (p *InProcessProvider) Spawn(ctx context.Context, req SpawnRequest) (*Handle, error)

Spawn runs the subtask through runner and returns its handle.

type InProcessRunner

type InProcessRunner func(ctx context.Context, req SpawnRequest) (sid brand.SessionID, output string, err error)

InProcessRunner executes the injected transactional subtask implementation and returns the child session ID, output text, and error.

type Provider

type Provider interface {
	// Name returns the backend name, such as in-process, acp, or fork-copy.
	Name() string
	// Spawn starts a child agent and returns a disposable handle.
	Spawn(ctx context.Context, req SpawnRequest) (*Handle, error)
}

Provider abstracts child-agent backends.

type Runtime

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

Runtime owns provider registrations and active child handles.

func NewRuntime

func NewRuntime() *Runtime

NewRuntime registers the built-in ACP and ForkCopy stubs.

func (*Runtime) ActiveCount

func (r *Runtime) ActiveCount() int

ActiveCount returns the registered handle count for diagnostics.

func (*Runtime) DisposeOwner

func (r *Runtime) DisposeOwner(parent brand.SessionID)

DisposeOwner disposes all children belonging to a parent session.

func (*Runtime) Provider

func (r *Runtime) Provider(name string) (Provider, bool)

Provider looks up a backend.

func (*Runtime) RegisterProvider

func (r *Runtime) RegisterProvider(p Provider) error

RegisterProvider registers a backend.

func (*Runtime) Spawn

func (r *Runtime) Spawn(ctx context.Context, providerName string, req SpawnRequest) (*Handle, error)

Spawn launches through the selected backend and registers its handle.

type SpawnRequest

type SpawnRequest struct {
	Parent    *brand.SessionID `json:"parent,omitempty"`
	Input     string           `json:"input"`
	MaxRounds int              `json:"maxRounds,omitempty"`
}

SpawnRequest requests a child agent.

type SpawnResult

type SpawnResult struct {
	Lineage ForkLineage `json:"lineage"`
	Output  string      `json:"output"`
	Err     string      `json:"err,omitempty"`
}

SpawnResult contains a child agent's output.

Jump to

Keyboard shortcuts

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