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 ¶
- func ComposeBranch(parent, this string) string
- func CurrentDepth(ctx context.Context) int
- func DeriveSessionID(parent, branch, invocation string) string
- func WithDepth(ctx context.Context, n int) context.Context
- type BranchInjectingService
- func (s *BranchInjectingService) AppendEvent(ctx context.Context, sess session.Session, ev *session.Event) error
- func (s *BranchInjectingService) Create(ctx context.Context, req *session.CreateRequest) (*session.CreateResponse, error)
- func (s *BranchInjectingService) Delete(ctx context.Context, req *session.DeleteRequest) error
- func (s *BranchInjectingService) Get(ctx context.Context, req *session.GetRequest) (*session.GetResponse, error)
- func (s *BranchInjectingService) List(ctx context.Context, req *session.ListRequest) (*session.ListResponse, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComposeBranch ¶
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 ¶
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 ¶
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.
Types ¶
type BranchInjectingService ¶
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 (s *BranchInjectingService) Create(ctx context.Context, req *session.CreateRequest) (*session.CreateResponse, error)
func (*BranchInjectingService) Delete ¶
func (s *BranchInjectingService) Delete(ctx context.Context, req *session.DeleteRequest) error
func (*BranchInjectingService) Get ¶
func (s *BranchInjectingService) Get(ctx context.Context, req *session.GetRequest) (*session.GetResponse, error)
func (*BranchInjectingService) List ¶
func (s *BranchInjectingService) List(ctx context.Context, req *session.ListRequest) (*session.ListResponse, error)