Help us shape the future of Go! Take the 2026 Go Developer Survey

depth

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 5 Imported by: 0

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

View Source
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

func FromContext(ctx context.Context) (int, bool)

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

func FromMeta(meta map[string]any) (int, bool)

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 Meta

func Meta(level int) map[string]any

Meta returns an ACP _meta map that carries level.

func Parse

func Parse(raw string) (int, bool)

Parse decodes a non-negative level from a string (env var or header value).

func Resolve

func Resolve(ctx context.Context, sessionID string) int

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 Session

func Session(sessionID string) (int, bool)

Session returns the level recorded for sessionID, if any.

func SetSession

func SetSession(sessionID string, level int)

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.

func WithContext

func WithContext(ctx context.Context, level int) context.Context

WithContext returns a context that records the caller's own nesting level. Negative values are ignored.

Types

This section is empty.

Jump to

Keyboard shortcuts

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