Listeners
Listeners enable you to observe and log agent and agentic function invocations, chat histories, and interactions. This includes both chat histories in and out of the REPL, as well as outputs of code execution in the REPL. In TypeScript, this takes the form of callbacks referred to as listeners; every time a text chunk is generated (a token in the case of theagent), this callback is triggered,
sending the chunk along with the ID for which the generation is apart of.
iid: a unique invocation ID for the specific invocation/callchunk: aChunkobject:
type field allows consumers to handle different kinds of streamed content (e.g. distinguishing reasoning traces from output text).
The TypeScript SDK allows users to provide a callback to
spawninAgentSpawnConfig,Agent.callinAgentCallConfigandagenticinAgenticConfig
listener.
Usage Chunks
By default, usage-reporting chunks (chunk.type === 'usage') are filtered out of the listener stream. To include them, set listenerIncludeUsage: true: