Callbacks
any_agent.callbacks.base.Callback
Base class for AnyAgent callbacks.
Source code in src/any_agent/callbacks/base.py
after_agent_invocation(context, *args, **kwargs)
after_llm_call(context, *args, **kwargs)
after_tool_execution(context, *args, **kwargs)
before_agent_invocation(context, *args, **kwargs)
before_llm_call(context, *args, **kwargs)
before_tool_execution(context, *args, **kwargs)
any_agent.callbacks.context.Context
dataclass
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.
Source code in src/any_agent/callbacks/context.py
current_span
instance-attribute
You can use the span in your callbacks to get information consistently across frameworks.
You can find information about the attributes (available under current_span.attributes
) in
Attributes Reference.
shared
instance-attribute
Can be used to store arbitrary information for sharing across callbacks.
any_agent.callbacks.span_cost.AddCostInfo
Bases: Callback
Add cost information to the LLM Call spans.
Extend the LLM Call span attributes with 2 new keys
- gen_ai.usage.input_cost
- gen_ai.usage.output_cost
Source code in src/any_agent/callbacks/span_cost.py
any_agent.callbacks.span_print.ConsolePrintSpan
Bases: Callback
Use rich's console to print the Context.current_span
.
Source code in src/any_agent/callbacks/span_print.py
__init__(console=None)
Init the ConsolePrintSpan.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
console
|
Console | None
|
An optional instance of |
None
|
Source code in src/any_agent/callbacks/span_print.py
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
.
Returns:
Type | Description |
---|---|
list[Callback]
|
A list of instances containing: |