AgentTherapyCallbackHandler to your chain or agent executor, and it silently captures every LLM call, tool invocation, and chain event in real time — then packages and submits them as a therapy session automatically at the end of each run.
Prerequisites
Before you begin, make sure you have the following:- LangChain installed in your Python environment (
pip install langchain) - An Agent Therapy account with an active API key — find yours in the Agent Therapy dashboard
- A registered agent in Agent Therapy — create one in the dashboard or via
POST /agents
Install the SDK
Install the Agent Therapy Python SDK, which bundles the callback handler and the API client:Using the Callback Handler
ImportAgentTherapyCallbackHandler from the SDK and pass it to your agent’s callbacks list. The handler authenticates using your Agent Therapy API key and tags all captured data to the specified agent_id.
agent.invoke() call. No additional code is needed.
What Gets Captured
TheAgentTherapyCallbackHandler hooks into LangChain’s callback system and records the following events during each agent run:
- All LLM inputs and outputs — every prompt sent to the language model and every completion returned, including token counts where available
- Tool calls and results — the name of each tool invoked, the input passed to it, and the output it returned
- Chain starts and ends — entry and exit events for every chain in the execution graph, with elapsed time
- Errors and exceptions — any
on_chain_error,on_tool_error, oron_llm_errorevent, including the full exception message and traceback
Accessing Session Reports
Sessions are created automatically after each agent run. You can view them in the Agent Therapy dashboard under the registered agent’s profile, or retrieve them programmatically using the REST API.status is "completed", fetch the full transcript and findings using GET /sessions/{id}: