Documentation
¶
Overview ¶
Package subagent installs spawn_subagent: self-forking and cross-agent delegation under shared depth and budget caps.
What it buys the parent is CONTEXT, not compute: a child explores in its own isolated history and returns only its final answer, so the tool churn, dead ends, and large intermediate results never enter the parent's window.
A spawned child is an ordinary governed tool call — same policy gate, same credential boundary, same trace — not a privileged side channel. Depth rides the context, so an A -> B -> A cycle is bounded by the same MaxDepth as a straight chain, and the plugin declines a run already at the cap rather than advertising a tool that would only refuse.
Index ¶
Constants ¶
const ToolSpawnSubagent = "spawn_subagent"
ToolSpawnSubagent is the stable name of the built-in delegation tool (ARCHITECT-AGENT-TEAM P1): the model forks an ephemeral child agent for one self-contained task and receives only its final answer, keeping the child's exploration (tool churn, dead ends, large intermediate results) out of the parent's context window.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Delegate ¶
type Delegate struct {
// Name is the stable identifier the model selects with (the target agent's
// human name). Matched case-insensitively.
Name string
// Description is a one-line hint helping the model pick the right teammate.
Description string
// Run executes the delegated task on the target agent.
Run func(ctx context.Context, task string, sink agentcore.StreamSink) (string, agentcore.Usage, error)
}
Delegate is one named other agent this agent may hand a task to (cross-agent delegation). agentcore never builds the target itself: Run is an opaque closure the consumer injects, executing the target agent under its own identity — its persona, tools, policy, and secrets, not the caller's. The closure receives the caller's ctx (so cancelling the parent cancels the delegate, and the delegation depth carried on ctx caps recursion across agents) and an optional sink for live tool-activity notes; it returns the target's final answer plus its token usage for parent-run accounting.
type ForkRequest ¶
type ForkRequest struct {
SessionID string
Prompt string
Task string
Previous *agentcore.RunResult
}
ForkRequest describes one isolated task or one corrective retry. Previous is the original result, including native state; adapters must not reconstruct a native transcript from its display-only Messages projection.
type ForkRunner ¶
type ForkRunner func(context.Context, *agentcore.Agent, ForkRequest, agentcore.StreamSink) (agentcore.RunResult, error)
type Plugin ¶
type Plugin struct {
// AllowAsync offers run-owned jobs for ephemeral forks. Durable delegation
// must continue using its host journal and reattachment protocol.
AllowAsync bool
// MaxDepth is how many nesting levels may spawn: 1 (the default) lets the
// top-level agent spawn children but forbids grandchildren.
MaxDepth int
// MaxPerRun caps how many children one run may spawn in total. Zero derives
// it from the run's own tool budget (a third of Limits.MaxToolCalls, floor
// 8), so a long run gets a proportionate delegation budget without the
// consumer having to restate one.
MaxPerRun int
// MaxOutputBytes caps the child answer surfaced to the parent model.
MaxOutputBytes int
// Delegates names the other agents this one may hand a task to. Each Run is
// an opaque closure the consumer injects — agentcore never loads another
// agent itself. Empty leaves only self-delegation.
Delegates []Delegate
// RunFork selects the consumer's runtime for self-delegation. The child is
// always created by Agent.Fork first, so runtime selection cannot widen its
// inherited capabilities. Nil uses the native engine with consumer checkpoints
// for ephemeral runs; durable self-forks require a native session host.
RunFork ForkRunner
}
Plugin caps the delegation surface. A child inherits the parent's provider, model ladder, tools, policy, hooks, memory, and definition — it can never widen access — and runs with isolated history, so only its final answer (truncated to MaxOutputBytes) returns to the parent.
func SelfOnly ¶
func SelfOnly() Plugin
SelfOnly enables delegation to ephemeral forks of this agent, with no cross-agent roster.
func (Plugin) BeginRun ¶
BeginRun installs the tool for a run still above the nesting cap, and DECLINES one that is already at it.
Declining is how delegation bottoms out structurally: a run at MaxDepth is never offered the tool, so the cap is enforced by absence rather than by a refusal the model would have to read, reason about, and work around. The depth rides the context, so it survives crossing into another agent's run.