/** * SpawnPolicyGuard (L32) * * Controls whether agents can spawn child agents (sub-agents). * Think of this as Content Security Policy (CSP) but for agent spawning — * it defines which agents are allowed to create other agents, under what * conditions, and with what constraints. * * Threat Model: * - ASI07: Insecure Inter-Agent Communication * - Unauthorized agent spawning (an agent spawns helpers to evade controls) * - Third-party agent injection (untrusted spawned agents carry out attacks) * - Delegation depth explosion (recursive sub-agent spawning) * - Privilege amplification through spawning * * Protection Capabilities: * - Per-origin spawn allowlisting * - Third-party spawn gating * - Delegation depth enforcement * - Human-in-the-loop gate for new agents * - Runtime spawn counter per parent agent */ export interface SpawnPolicyGuardConfig { /** Allow agents to spawn from third-party / untrusted origins (default: false) */ allowThirdPartySpawning?: boolean; /** Maximum delegation depth: 0 = no spawning, 1 = parent→child only (default: 2) */ maxDelegationDepth?: number; /** Gate every spawn through human approval (default: false) */ requireApprovalForNewAgents?: boolean; /** Allowlist of spawn origins that are trusted. Empty = all registered origins allowed */ allowedSpawnOrigins?: string[]; /** Maximum number of active child agents per parent (default: 10) */ maxChildrenPerParent?: number; /** Require the spawning agent to be registered before it can spawn */ requireRegisteredParent?: boolean; } export interface SpawnRequest { /** ID of the agent requesting to spawn */ parentAgentId: string; /** Proposed ID for the new child agent */ childAgentId: string; /** Declared origin / runtime of the child (e.g. "openai", "anthropic", "internal") */ spawnOrigin: string; /** How many hops deep in the delegation chain is the parent */ delegationDepth: number; /** Is the child coming from a third-party / external system? */ isThirdParty: boolean; /** Optional reason / justification */ reason?: string; /** Additional metadata */ metadata?: Record; } export interface SpawnPolicyResult { allowed: boolean; reason: string; violations: string[]; request_id: string; policy_analysis: { third_party_blocked: boolean; depth_exceeded: boolean; origin_blocked: boolean; parent_not_registered: boolean; children_limit_exceeded: boolean; approval_required: boolean; }; requires_human_approval: boolean; } export declare class SpawnPolicyGuard { readonly guardName = "SpawnPolicyGuard"; readonly guardLayer = "L32"; private readonly config; /** parentAgentId → set of active child IDs */ private readonly activeChildren; /** Set of registered parent agent IDs */ private readonly registeredParents; constructor(config?: SpawnPolicyGuardConfig); /** * Register an agent as an approved parent that is allowed to spawn. */ registerParent(agentId: string): void; /** * Record that a child agent has terminated / been removed. */ removeChild(parentAgentId: string, childAgentId: string): void; /** * Validate whether a spawn request should be permitted. * * @param request - Describes the proposed spawn * @param requestId - Optional trace ID */ validateSpawn(request: SpawnRequest, requestId?: string): SpawnPolicyResult; /** Return active child count for a parent. */ getChildCount(parentAgentId: string): number; /** Reset all state (useful between test runs). */ reset(): void; }