n4nAI

Tools for recording chatbot sessions during development

Practical tools record chatbot sessions during development: from LangSmith to self-hosted proxies, with code to capture and replay LLM conversations.

n4n Team4 min read807 words

Audio narration

Coming soon — every post will get a voice note here.

When you are iterating on a conversational agent, the difference between a guess and a fix is usually a faithful log. The tools record chatbot sessions that survive contact with real users and weird model outputs let you replay exactly what the model saw and returned. Below are the options I’ve actually wired into pipelines, from hosted observability platforms to a ten-line middleware you can own.

1. LangSmith

Among the tools record chatbot sessions, LangSmith is the tracing backend from the LangChain team. It captures every chain step, tool call, and LLM completion as a run tree. You get session replay with latency, token counts, and the ability to fork a trace into a new test case.

Integration is a callback handler. Set environment variables and attach the handler:

from langchain.callbacks import LangSmithCallbackHandler
from langchain.chat_models import ChatOpenAI

handler = LangSmithCallbackHandler()
llm = ChatOpenAI(callbacks=[handler])

The web UI lets you filter by session ID, which maps to a conversation. For non-LangChain stacks, the langsmith SDK exposes a low-level Client.trace context manager that logs arbitrary JSON. That’s useful when your chatbot is plain Python and you still want the same replay surface.

One caveat: it’s a hosted service with its own pricing meter. For local-only dev, the overhead is small, but watch the retention defaults.

2. Helicone

Helicone sits as a drop-in proxy in front of OpenAI or Anthropic. You change your base URL to https://api.helicone.ai/v1 and add a provider key header. It records the full request and response, including streaming chunks, and shows them in a session view. Proxy-based tools record chatbot sessions without touching app logic.

import openai

openai.api_base = "https://api.helicone.ai/v1"
openai.api_key = "sk-helicone-proxy"  # your helicone key
# provider key passed via header
openai.default_headers = {"Helicone-Auth": "Bearer <PROVIDER_KEY>"}

Sessions are grouped by a Helicone-Session-Id header you set per conversation. The free tier is sufficient for solo dev; self-hosting via Docker is an option if you need data locality.

If you route through a gateway like n4n.ai, which exposes a single OpenAI-compatible endpoint for 240+ models with per-token metering, you can place Helicone or your own logger in front of that endpoint just as easily, since it speaks the same protocol.

3. PromptLayer

PromptLayer focuses on prompt versioning alongside logging. Every request sent with its SDK is stored with a prompt tag. You can compare how a session played out across prompt revisions.

import promptlayer
promptlayer.api_key = "pl-..."
response = promptlayer.openai.ChatCompletion.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello"}],
    pl_tags=["onboarding-bot"]
)

The session replay is adequate, but the standout feature is the prompt registry: you can pin a prompt version to a session and reproduce the exact input template later. For chatbots with heavy prompt engineering, that linkage saves hours.

4. AgentOps

AgentOps targets autonomous agents, but its session recording works for any multi-turn chatbot that calls tools. It auto-instruments LLM clients and logs state transitions, errors, and tool I/O under a session UUID.

import agentops
agentops.init("YOUR_API_KEY")
# any subsequent openai calls are recorded

The dashboard renders a timeline: model call → tool call → model call. That’s exactly what you need when a chatbot silently fails to call a retriever. The Python SDK also lets you tag sessions with user IDs for filtering later.

5. OpenLLMetry (Traceloop)

OpenLLMetry is open-source instrumentation built on OpenTelemetry. You get spans for each LLM call, vector search, and chain, exported to any OTel backend (Jaeger, Grafana, Datadog). It’s the right pick if your org already runs observability infra and you want sessions as traces.

from traceloop.sdk import Traceloop
Traceloop.init(app_name="chatbot-dev")
# decorators or auto-instrumentation capture calls

Because it’s standard OTel, you can correlate chatbot sessions with backend latency and infra metrics. The cost is setup time: you need a collector and a storage backend. For a quick local replay, Jaeger all-in-one via Docker is enough.

6. LiteLLM Proxy

LiteLLM is a Python proxy that normalizes 100+ model APIs to the OpenAI shape. Its proxy server can log to SQLite, Postgres, or S3 out of the box. You point your app at the proxy and get a spend and request table that includes the full payload.

# litellm config
model_list:
  - model_name: gpt-4o
    litellm_params:
      model: openai/gpt-4o
      api_key: os.environ[OPENAI_KEY]
litellm_settings:
  store_model_in_db: true

Start with litellm --config config.yaml --detailed_debug and every chat completion is recorded with a request_id. You can then query sessions by user_id or metadata. This is fully self-hosted; no external service sees your traffic.

7. Custom Middleware (FastAPI + JSONL)

When you need zero dependencies, a thin middleware that dumps each request and response to JSONL is unbeatable. Below is a minimal FastAPI example that records chatbot sessions locally.

import json
from fastapi import FastAPI, Request

app = FastAPI()

@app.middleware("http")
async def log_sessions(request: Request, call_next):
    body = await request.body()
    response = await call_next(request)
    res_body = b""
    async for chunk in response.body_iterator:
        res_body += chunk
    with open("sessions.jsonl", "a") as f:
        f.write(json.dumps({
            "path": request.url.path,
            "req": body.decode(),
            "res": res_body.decode(),
        }) + "\n")
    return response

This captures raw traffic. Add a session ID from a header or cookie to group turns. The file is grep-able and can be replayed with a small script. The downside: you maintain it, and streaming needs careful buffering.

Summary Table

Tool Hosting Session Grouping Best For
LangSmith Hosted/Self Callback session ID LangChain apps
Helicone Hosted/Self Session header Proxy-based logging
PromptLayer Hosted Prompt tags Prompt versioning
AgentOps Hosted UUID Agent timelines
OpenLLMetry Self OTel trace ID Existing OTel stack
LiteLLM Self Metadata Multi-model proxy
Custom MW Self Your own Full control

Pick based on where your chatbot already runs. If you’re behind a single gateway, a proxy logger or custom middleware is enough. If you live in LangChain, LangSmith removes friction. The goal is the same: tools record chatbot sessions so you can debug what actually happened, not what you think happened.

Tagssession-replaytoolingchatbotlisticle

Written by

n4n Team

The team building n4n — a single OpenAI-compatible API in front of 240+ models, with automatic fallback, load balancing and pay-per-token metering.

More from n4n Team →

All chatbot session replay & debugging posts →