Documentation
¶
Overview ¶
Package depth carries the delegation nesting level of a running agent across every path a delegated task can take, so the MaxDepth cap holds no matter how a subagent was launched:
- cold CLI / ACP subprocesses read EnvVar, set by the spawner;
- external CLI agents (claude, copilot, ...) reach Pando through the per-task MCP config, whose "pando" stdio entry carries EnvVar too;
- warm ACP instances and IPC delegations run many sessions inside one long-lived process, so the level travels with the request (ACP session/prompt _meta under MetaKey, or the IPC delegation params) and is recorded per session with SetSession;
- HTTP MCP callers may send HeaderName, which lands in the request context.
The value is always the level the agent itself runs at: 0 for an interactive top-level session, 1 for a subagent it spawned, and so on. A spawn from an agent at level N creates a task at level N+1.
The package is a leaf (standard library only) so the orchestrator, the project manager, the IPC bridge, the ACP agent and the tools can all share it without import cycles.
Index ¶
- Constants
- func ClearSession(sessionID string)
- func FromContext(ctx context.Context) (int, bool)
- func FromEnv() int
- func FromMeta(meta map[string]any) (int, bool)
- func Meta(level int) map[string]any
- func Parse(raw string) (int, bool)
- func Resolve(ctx context.Context, sessionID string) int
- func Session(sessionID string) (int, bool)
- func SetSession(sessionID string, level int)
- func WithContext(ctx context.Context, level int) context.Context
Constants ¶
const ( // EnvVar is the environment variable a delegated subprocess reads to learn // its own nesting level. EnvVar = "PANDO_DELEGATION_DEPTH" // MetaKey is the ACP _meta key (session/prompt) that carries the level of a // warm delegated session. MetaKey = "pando:delegationDepth" // HeaderName is the HTTP header an MCP client may send to declare its level. HeaderName = "X-Pando-Delegation-Depth" )
Variables ¶
This section is empty.
Functions ¶
func ClearSession ¶
func ClearSession(sessionID string)
ClearSession forgets a session's level (session deleted / closed).
func FromContext ¶
FromContext returns the level recorded by WithContext, if any.
func FromEnv ¶
func FromEnv() int
FromEnv returns the level declared by EnvVar for this process, or 0 when it is unset or invalid (an interactive top-level Pando).
func FromMeta ¶
FromMeta reads MetaKey from an ACP _meta map. JSON numbers decode as float64, but a string or int is accepted too so non-Go clients are not penalised.
func Resolve ¶
Resolve returns the caller's own nesting level using, in order: an explicit context value, the level recorded for sessionID, then the process env var.
func SetSession ¶
SetSession records the nesting level of a session that runs inside a long-lived process (warm ACP instance, IPC delegation target). The entry is kept for the session's lifetime: a delegated session may be resumed later (await / resurrection) and must still know its level then.
Types ¶
This section is empty.