feat: emit session_ready & tools_resolve lifecycle events#113
feat: emit session_ready & tools_resolve lifecycle events#113NovusEdge wants to merge 2 commits into
Conversation
Add a new lifecycle event that fires when an agent's session is created and ready for use. This enables extensions that need to attach state to subagent sessions (memory systems, context managers, telemetry) to do so cleanly without relying on internal APIs. Event payload: - id: agent ID - type: subagent type (Explore, Plan, etc.) - session: the AgentSession object - record: the full AgentRecord for metadata Use case: Memory/context systems like Veil that fork parent context for subagents and merge findings back on completion.
Allows extensions to inject additional tools into subagent sessions before they are created. Two mechanisms: 1. SpawnOptions.onToolsResolve callback - per-spawn tool injection 2. subagents:tools_resolve event - global hook for all spawns The event payload includes a mutable `tools` array that extensions can modify to add their own tools (e.g., memory/context tools). Use case: Veil injects veil_recall, veil_remember, etc. into subagents so they can use the parent's context system. Event fires after built-in tool filtering but before session creation.
|
I think I need to look a little deeper into this. for example the tools injection. question is if this should be done on subagent creating. also, do we want to all all connected extensions to mess with the subagents. |
|
Hmm fair point. I think I have a proposal in that case. For For Buuut I do agree, the mutable array is too open. Some options that come to mind to fix this:
|
Summary
Add two new lifecycle events that enable extensions to integrate properly with subagent sessions:
subagents:session_ready- Fires when an agent's session is created and readysubagents:tools_resolve- Fires before session creation to allow tool injectionMotivation
Extensions like memory/context systems need to:
Currently, the existing events (
subagents:started,subagents:completed) don't expose the session object or allow tool injection, making this impossible without relying on internal APIs.Changes
subagents:session_readyevent inagent-manager.tsright afteronSessionCreatedfiressubagents:tools_resolveevent inagent-runner.tsbefore session creationonToolsResolvecallback option toSpawnOptionsandRunOptionsEvent Payloads
session_ready
tools_resolve
Use Cases
Context propagation (session_ready)
Tool injection (tools_resolve)
Backward Compatibility
This is purely additive - existing code is unaffected. Extensions can opt-in to the new events.