Callbacks
Callback
Section titled “Callback”Base class for AnyAgent callbacks.
Base class for AnyAgent callbacks. Subclass and override any subset of the lifecycle methods.
Callback.before_agent_invocation()
Section titled “Callback.before_agent_invocation()”Will be called before the Agent invocation starts.
def before_agent_invocation( self, context: Context, *args, **kwargs,) -> ContextCallback.before_llm_call()
Section titled “Callback.before_llm_call()”Will be called before any LLM Call starts.
def before_llm_call( self, context: Context, *args, **kwargs,) -> ContextCallback.after_llm_call()
Section titled “Callback.after_llm_call()”Will be called after any LLM Call is completed.
def after_llm_call( self, context: Context, *args, **kwargs,) -> ContextCallback.before_tool_execution()
Section titled “Callback.before_tool_execution()”Will be called before any Tool Execution starts.
def before_tool_execution( self, context: Context, *args, **kwargs,) -> ContextCallback.after_tool_execution()
Section titled “Callback.after_tool_execution()”Will be called after any Tool Execution is completed.
def after_tool_execution( self, context: Context, *args, **kwargs,) -> ContextCallback.after_agent_invocation()
Section titled “Callback.after_agent_invocation()”Will be called once the Agent invocation ends.
def after_agent_invocation( self, context: Context, *args, **kwargs,) -> ContextContext
Section titled “Context”Object that will be shared across callbacks. Each AnyAgent.run has a separate Context available. shared can be used to store and pass information across different callbacks.
Shared context object passed through all callbacks during an agent run.
Fields
Section titled “Fields”| Field | Type | Description |
|---|---|---|
current_span | Span | The active OpenTelemetry span with attributes (see GenAI) |
trace | AgentTrace | Current execution trace |
tracer | Tracer | OpenTelemetry tracer instance |
shared | dict[str, Any] | Arbitrary shared state across callbacks |
ConsolePrintSpan
Section titled “ConsolePrintSpan”Default callback that prints span information to the console using Rich formatting.
any_agent.callbacks.get_default_callbacks()
Section titled “any_agent.callbacks.get_default_callbacks()”Return instances of the default callbacks used in any-agent. This function is called internally when the user doesn’t provide a value for [AgentConfig.callbacks][any_agent.config.AgentConfig.callbacks].
def get_default_callbacks() -> list[Callback]Returns: A list of instances containing: - [ConsolePrintSpan][any_agent.callbacks.span_print.ConsolePrintSpan]