subsession

package
v2.8.0-dev.2 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package subsession holds the session-derivation plumbing shared by the two subagent-spawning paths: the core parallel-tool-call path in pkg/agent (subagent.go) and the long-lived background path in pkg/agent/background. Both derive a child session row from the parent's, tag emitted events with a hierarchical branch label, and track recursion depth through the context chain. Keeping these helpers in one internal package lets the background package spawn subagents without importing pkg/agent's unexported internals (which would form an import cycle).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComposeBranch

func ComposeBranch(parent, this string) string

ComposeBranch builds the full branch path for a subagent call: the parent's branch (possibly empty for top-level), joined with the subagent's own branch label by ADK's "." separator.

func CurrentDepth

func CurrentDepth(ctx context.Context) int

CurrentDepth returns the recursion depth of the current subagent invocation. Zero when we're not inside a subagent (i.e. the parent's top-level turn).

func DeriveSessionID

func DeriveSessionID(parent, branch, invocation string) string

DeriveSessionID composes the session ID a subagent's runner uses. It lives in the same database as the parent's session so audit queries can find both (via the shared "<parent>:sub:<branch>" prefix + branch tag), but as a separate row per invocation so ADK's per-session optimistic-concurrency check doesn't trip and independent requests don't accumulate one another's history (#364).

Format: "<parent>:sub:<branch>:<invocation>". When parent is empty the parent prefix is dropped. When invocation is empty the suffix is dropped — the parallel-tool-call path always passes a value; the background path intentionally passes "" because a background subagent is addressed by its stable name and its derived row must be deterministic.

func WithDepth

func WithDepth(ctx context.Context, n int) context.Context

WithDepth returns a context carrying subagent recursion depth n. Callers increment CurrentDepth(ctx)+1 when descending into a nested subagent.

Types

type BranchInjectingService

type BranchInjectingService struct {
	Inner  session.Service
	Branch string
}

BranchInjectingService wraps a session.Service so every appended event picks up Branch before landing in storage. The CRUD methods pass through unchanged. This is how a subagent's events end up tagged for the audit log without requiring the subagent's runner to know anything about branching.

func (*BranchInjectingService) AppendEvent

func (s *BranchInjectingService) AppendEvent(ctx context.Context, sess session.Session, ev *session.Event) error

AppendEvent stamps Branch on the event before delegating. We only override an empty Branch — events that already carry one (e.g., nested subagent invocations) keep their existing label so the branch hierarchy stays accurate.

func (*BranchInjectingService) Create

func (*BranchInjectingService) Delete

func (*BranchInjectingService) Get

func (*BranchInjectingService) List

Jump to

Keyboard shortcuts

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