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 ¶
- Variables
- func CanDelegate(depth, maxDepth int) bool
- func ChildDepth(parentDepth int) (int, error)
- func IsUnknownProvider(err error) bool
- func ResolveDepth(headerDepth, runtimeDepth int) (int, error)
- type ErrUnknownProvider
- type ForkLineage
- type Handle
- type InProcessProvider
- type InProcessRunner
- type Provider
- type Runtime
- func (r *Runtime) ActiveCount() int
- func (r *Runtime) DisposeOwner(parent brand.SessionID)
- func (r *Runtime) Provider(name string) (Provider, bool)
- func (r *Runtime) RegisterProvider(p Provider) error
- func (r *Runtime) Spawn(ctx context.Context, providerName string, req SpawnRequest) (*Handle, error)
- type SpawnRequest
- type SpawnResult
Constants ¶
This section is empty.
Variables ¶
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 ¶
CanDelegate requires depth below maxDepth; negative maxDepth means unlimited.
func ChildDepth ¶
ChildDepth returns the parent depth plus one.
func IsUnknownProvider ¶
IsUnknownProvider identifies unknown-backend errors.
func ResolveDepth ¶
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.
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 ¶
ActiveCount returns the registered handle count for diagnostics.
func (*Runtime) DisposeOwner ¶
DisposeOwner disposes all children belonging to a parent session.
func (*Runtime) RegisterProvider ¶
RegisterProvider registers a backend.
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.