agentconnect.utils.callbacks module¶
Agent activity tracing and status update callback handler for AgentConnect.
This module provides a LangChain callback handler for tracking agent activity, including tool usage, LLM calls, chain steps, and the LLM’s generated text output (which may contain reasoning steps), with configurable console output.
- class ToolTracerCallbackHandler(agent_id, print_tool_activity=True, print_reasoning_steps=True)¶
Bases:
BaseCallbackHandler
Callback handler for tracing agent activity. Logs detailed activity and optionally prints concise updates (like LLM generation text, tool usage, etc.) to the console based on configuration.
- on_tool_start(serialized, input_str, *, run_id, parent_run_id=None, tags=None, metadata=None, inputs=None, **kwargs)¶
Run when the tool starts running.
- Parameters:
serialized (Dict[str, Any]) – The serialized tool.
input_str (str) – The input string.
run_id (UUID) – The run ID. This is the ID of the current run.
parent_run_id (UUID) – The parent run ID. This is the ID of the parent run.
tags (Optional[List[str]]) – The tags.
metadata (Optional[Dict[str, Any]]) – The metadata.
inputs (Optional[Dict[str, Any]]) – The inputs.
kwargs (Any) – Additional keyword arguments.
- Return type:
- on_tool_end(output, *, run_id, parent_run_id=None, tags=None, name='UnknownTool', **kwargs)¶
Run when the tool ends running.
- on_tool_error(error, *, run_id, parent_run_id=None, tags=None, name='UnknownTool', **kwargs)¶
Run when tool errors.
- Parameters:
error (BaseException) – The error that occurred.
run_id (UUID) – The run ID. This is the ID of the current run.
parent_run_id (UUID) – The parent run ID. This is the ID of the parent run.
kwargs (Any) – Additional keyword arguments.
name (str)
- Return type:
- on_agent_action(action, *, run_id, parent_run_id=None, **kwargs)¶
Run on agent action.
- Parameters:
action (AgentAction) – The agent action.
run_id (UUID) – The run ID. This is the ID of the current run.
parent_run_id (UUID) – The parent run ID. This is the ID of the parent run.
kwargs (Any) – Additional keyword arguments.
- Return type:
- on_chain_end(outputs, **kwargs)¶
Print the agent’s ‘thought’ steps (reasoning before tool calls) in a clean, sequential manner. Handles different AIMessage structures from various models (e.g., Gemini, Anthropic). Uses REASONING_COLOR for output and msg.id for deduplication.