Skip to main content

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 the spawn, .call and magic functions/methods. A listener has the following signature:
(iid: string, chunk: Chunk) => void
passed to either the AgentSpawnConfig, AgentCallConfig or MagicFunctionConfig object. where:
  • iid is a unique invocation ID for the specific invocation/call.
  • chunk is a { role: 'user' | 'assistant' | 'system', content: string } object.
Every time a text chunk is generated (a token in the case of the 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?