Skip to main content

AgentLogger

A pluggable base class that powers listeners by defining the logging behaviour itself.
class AgentLogger(ABC):

    local_id: int | None
    parent_local_id: int | None

    @abstractmethod
    def on_spawn(self) -> None: ...

    @abstractmethod
    def on_call_enter(self, user_prompt: str, parent_local_id: int | None = None) -> None: ...

    @abstractmethod
    def on_call_exit(self, result: object) -> None: ...

    @abstractmethod
    async def on_chunk(self, chunk: Chunk) -> None: ...
Abstract methods that must be implemented:
  • on_spawn - Called when an agent is spawned
  • on_call_enter - Called when an agent receives a prompt
  • on_call_exit - Called when an agent returns a result
  • on_chunk - Called when a streaming chunk is received

Chunk

A single piece of streamed content from an agent invocation.
@dataclass
class Chunk:
    role: Role          # 'agent', 'user', or 'system'
    content: str        # The text content of the chunk
    type: str | None    # 'reasoning', 'output_text', 'code', 'usage', 'invocation_exit', or None
The type field lets consumers distinguish different kinds of streamed content:
TypeDescription
'reasoning'Internal reasoning / chain-of-thought
'output_text'Final output text
'code'Code being executed in the REPL
'usage'Token usage statistics
'invocation_exit'Signals the end of an invocation
NoneUntyped chunk