Skip to main content

AgentListener

A concrete orchestration class that manages the logging lifecycle, wrapping an AgentLogger and manages the concurrent listening task whilst piping events into the logger.
class AgentListener:

    logger: AgentLogger
    connected: asyncio.Event

    def __init__(self, logger: AgentLogger) -> None: ...

    async def listen(self, csm: ClientSessionManager, uid: str, iid: str | None = None) -> None:

    def close(self) -> None: ...
The following are key methods:
  • listen - Starts the async task that receives chunks
  • close - Cancels the listening task

set_default_agent_listener

A function that can be used to set the global default AgentListener for your runtime.
This will be over-ridden by any contextual logging or listeners provided on spawning and invoking an agentic function or agent. See here for more information.
def set_default_agent_listener(
    listener: Callable[[], AgentListener] | None, local_context: bool = True
) -> None:
Parameters
listener
Callable[[], AgentListener] | None
required
The listener constructor for logging an agent or agentic function’s activity and chat history. If None, no listener will be used.
local_context
bool
If True, the listener only applies for this context.