Overview
Listeners enable you to observe and log agent and magic function invocations, chat histories, and interactions. This is useful for debugging, monitoring, and understanding your agent’s behavior. The listening API in TypeScript is a little different from the Python SDK for now. The TypeScript SDK currently approaches this through providing callbacks to thespawn, .call and magic functions/methods.
A listener has the following signature:
AgentSpawnConfig, AgentCallConfig or MagicFunctionConfig object.
where:
iidis a unique invocation ID for the specific invocation/call.chunkis a{ role: 'user' | 'assistant' | 'system', content: string }object.
agent), this callback is triggered,
sending the chunk along with the ID for which the generation is apart of.
Usually, you want to concatenate these chunks into a larger string or log them to a file, console or other container.
See also
TODO: this should not link to these, they’re python only?- Python Listeners Reference - for the complete listener API
- Advanced › Agent Listeners - for usage examples