Skip to main content
Agent Therapy is framework-agnostic. If your agent produces conversation logs — whether it’s a custom LangGraph workflow, a hand-rolled ReAct loop, a fine-tuned open-source model, or anything else — you can connect it to Agent Therapy using the REST API. All you need to do is collect the turns your agent produces, format them according to the universal log schema, and submit them as a session. Agent Therapy handles the analysis and returns a structured health report.

The Universal Log Format

Every session submitted to Agent Therapy is built from a behavior_log array. Each element in the array represents a single conversation turn. The schema supports four roles and a flexible metadata object for any additional context you want to preserve.
Field reference:

Collecting Logs in Your Application

The easiest way to collect logs is to wrap your agent’s conversation loop with a lightweight logger class. The AgentTherapyLogger below accumulates turns as your agent runs and flushes them to Agent Therapy when the session ends.

Calling the API Directly

If you prefer to use the REST API without the helper class — or you’re working in a language other than Python — here’s the minimal flow using curl: register your agent, submit a session, and poll for the completed report.

Best Practices

Always include timestamps

Even if your agent doesn’t natively track turn timing, add datetime.now().isoformat() to each turn when you log it. Timestamps let Agent Therapy detect latency spikes, time-based behavioral drift, and unusually long reasoning chains that might indicate a reasoning loop.

Log tool calls as separate turns

Don’t embed tool results inside the assistant turn’s content. Log each tool invocation as its own turn with role: "tool" and a tool_name. This gives Agent Therapy the resolution it needs to identify which specific tools are contributing to failures — and which are working correctly.

Submit sessions regularly, not just on failures

Submitting sessions only when something goes wrong creates survivorship bias in your agent’s health history. Regular submissions from healthy runs establish a behavioral baseline, making it much easier for Agent Therapy to flag genuine anomalies when they appear.

Add descriptive context strings

The context field is free text that appears in your dashboard and in session reports. Use it to capture the task type, environment, user segment, or run ID — for example, "Customer onboarding flow — prod — user_segment: enterprise". Good context strings make it far easier to correlate behavioral findings with specific workloads.
Sessions are processed asynchronously. After you submit a session, the API immediately returns a session object with "status": "queued" — the analysis runs in the background. To know when the report is ready, either poll GET /sessions/{id} until status is "completed", or register a webhook endpoint via POST /webhooks to receive a session.completed event pushed to your endpoint automatically.