bodhi-realtime-agent / PersistentSubagentManager
Class: PersistentSubagentManager
Defined in: src/agent/persistent-subagent-manager.ts:19
Manages persistent subagent instances scoped to a VoiceSession lifetime.
Persistent instances are keyed by a subagentKey string and reused across multiple tool calls within the same session. This enables stateful subagents (e.g., a Claude Code session that retains conversation history).
Concurrency safety: concurrent acquirePersistent() calls for the same key coalesce on a single factory invocation — no double-creates.
Constructors
Constructor
new PersistentSubagentManager():
PersistentSubagentManager
Returns
PersistentSubagentManager
Accessors
activeKeys
Get Signature
get activeKeys():
string[]
Defined in: src/agent/persistent-subagent-manager.ts:151
Return all active persistent instance keys.
Returns
string[]
Methods
acquirePersistent()
acquirePersistent(
key,config,factory):Promise<PersistentSubagentInstance>
Defined in: src/agent/persistent-subagent-manager.ts:33
Acquire (or reuse) a persistent subagent instance for the given key.
If an instance already exists for key, it is returned immediately. Otherwise, factory is called to create one. Concurrent calls for the same key share the same factory promise — no double-creates.
Parameters
key
string
config
factory
Returns
Promise<PersistentSubagentInstance>
disposeAllPersistent()
disposeAllPersistent():
Promise<void>
Defined in: src/agent/persistent-subagent-manager.ts:128
Dispose all persistent instances. Called on VoiceSession close.
Idempotent — safe to call multiple times. Individual dispose errors are caught so remaining instances are still cleaned up.
Returns
Promise<void>
has()
has(
key):boolean
Defined in: src/agent/persistent-subagent-manager.ts:146
Check if a persistent instance exists for the given key.
Parameters
key
string
Returns
boolean
invoke()
invoke(
key,taskDescription,args,signal?):Promise<string>
Defined in: src/agent/persistent-subagent-manager.ts:67
Invoke a previously acquired persistent instance.
Parameters
key
string
taskDescription
string
args
Record<string, unknown>
signal?
AbortSignal
Returns
Promise<string>
Throws
FrameworkError if no instance exists for key.
invokeWithScheduling()
invokeWithScheduling(
key,taskDescription,args,signal?):Promise<BackgroundToolResult>
Defined in: src/agent/persistent-subagent-manager.ts:92
Like invoke, but keeps the delivery scheduling an instance's optional invokeWithScheduling returns (PersistentSubagentResult); a plain string comes back as { text }.
Parameters
key
string
taskDescription
string
args
Record<string, unknown>
signal?
AbortSignal
Returns
Promise<BackgroundToolResult>
Throws
FrameworkError if no instance exists for key.
releasePersistent()
releasePersistent(
key):Promise<void>
Defined in: src/agent/persistent-subagent-manager.ts:114
Release a single persistent instance by key. Calls dispose() and removes it from the registry. No-op if the key does not exist.
Parameters
key
string
Returns
Promise<void>