Conversations
Most agents run to finish a job: read this document, run this report, answer this webhook. They start, do the work, end with a result. A chat is not that shape. A turn may answer, or it may ask a clarifying question and wait. Nothing ends.
Model a chat session as one run. Each turn appends events to it.
The alternative, a run per message, is the instinct, and it reads badly. A twelve-message conversation becomes twelve unrelated records, none of which is the thing you actually care about: what that conversation did, and what it cost.
Why the session, not the turn
A conversation re-sends its history on every turn, so its cost grows faster than its length. Turn ten pays for turns one through nine again. Measured per turn, that is invisible: ten ordinary-looking runs. Measured per session, it is a single number that explains your bill.
Session-as-run also makes the timeline read the way the conversation happened, turns in order with cost accumulating, instead of a list you have to reassemble.
Opening and appending
Open the run once, on the first message, then append each turn's model calls to it:
# First turn: open the run.
curl -X POST https://eu.ingest.agentping.io/v1/runs \
-H "Authorization: Bearer apk_eu_..." -H "Content-Type: application/json" \
-d '{
"id": "run_eu_018f3a2b9c1d7e8fa4b9c2d7e8f1a3b6",
"agent": "support-chat",
"started_at": "2026-05-15T14:32:01.123Z",
"goal": "Help the customer with their order",
"idle_timeout_seconds": 900,
"idle_timeout_status": "success"
}'
# Every turn, including the first: append what the model did.
curl -X POST https://eu.ingest.agentping.io/v1/runs/run_eu_018f.../events \
-H "Authorization: Bearer apk_eu_..." -H "Content-Type: application/json" \
-d '{"events": [{
"external_id": "evt_eu_...",
"type": "llm_call",
"ts": "2026-05-15T14:32:04.900Z",
"data": {"provider": "anthropic", "model": "claude-sonnet-4-6",
"input_tokens": 1731, "output_tokens": 240}
}]}'
POST /v1/runs is idempotent on id and started_at, so you can send it on every
turn rather than remembering whether the session is new. That keeps a stateless
backend stateless: no session table, no "have I opened this yet" lookup.
With an SDK
The SDKs wrap all of this in one call. Pass the same session id on every turn and they derive the run id and its start time from it, so a stateless request handler rebuilds the conversation without storing anything:
import * as agentping from "@agentping/sdk";
const sessionId = agentping.newSessionId(); // keep this for the life of the chat
// ...on every turn, including the first:
const chat = agentping.conversation("support-chat", sessionId);
chat.event("llm_call", { provider: "anthropic", model, input_tokens, output_tokens });
// ...and when the user closes the chat:
chat.finish({ status: "success" });
They default to a 15 minute idle timeout closing as success.
Closing it
A job finishes itself. A conversation usually does not: the user closes the tab, backgrounds the app, or puts the phone down mid-sentence. Browsers give no reliable "the user has gone" signal.
So a conversational run opts into being closed for you:
| Field | What it does |
|---|---|
idle_timeout_seconds |
Close the run when no event has arrived for this long. 60–86400. |
idle_timeout_status |
What that silence meant. Defaults to timeout; a chat should send success. |
Send idle_timeout_status: "success" for a chat: a conversation the user simply left
is not a failure, and leaving it to default would fill your health rate with timeouts.
The default is timeout because for most runs, silence means the caller died and we
should not pretend otherwise.
The run is closed at its last activity, not at the moment the sweep noticed, so a session's duration is the conversation's length rather than the length plus the timeout.
Close it yourself when you do get a signal, such as the user tapping Close or your UI
firing a visibilitychange, by calling POST /v1/runs/{id}/finish.
Whichever lands first wins; the other is a no-op. Belt and braces is the right posture
here: the explicit close makes the dashboard immediate, the timeout catches everything
else.
Picking a conversation up again
Someone comes back to yesterday's chat and carries on. You have two choices, and Agent Ping supports both because only you know which is true.
Continue the record. Send new events against the same run id. A run that opted
into the idle sweep is resumable: new activity reopens it, finished_at clears, and
the turns join the ones already there. The conversation stays one record with one
running total.
Start a fresh one. Mint a new run id. You get a new record, and the old one stays closed.
Two guards worth knowing about:
- Only runs with an
idle_timeout_secondsare resumable. A run that declared itself finished stays finished: a late event on a completed job is out-of-order delivery, not a continuation. - Only an event newer than the finish reopens a run, so a straggler that was in flight when the session closed will not flap it back open.
Report your tool calls
One turn is often several model calls. The agent calls the model, the model asks for a tool, you run it, then you call the model again with the result. Two billable calls for one exchange: three if it needs a second tool.
If you only report the model calls, a three-message conversation shows six llm_call
events that look like duplicates. Report the tools in between and the timeline
explains itself:
LLM_CALL claude-sonnet-4-6 · 1727 → 69 the model asks for a tool
TOOL_CALL get_week free, instant
LLM_CALL claude-sonnet-4-6 · 2043 → 181 the reply
Send the tool name and whether it failed. Arguments and results are usually your user's data and rarely worth shipping off-box.
Number the events with turn as you go, 1 for the first exchange, 2 for the second,
and the dashboard groups each turn together with its own cost rather than showing one
long list of calls.
What this changes elsewhere
- Duration is wall-clock across the whole session, including the gaps. A forty-minute chat is not a forty-minute job; read it as engagement, not latency.
agent_silentalerts do not suit a chat agent. It is quiet whenever nobody is talking to it, which is most of the time.- Success rate is a blunt instrument on a turn that correctly asked a question rather than answering. Read turns-per-session and cost-per-session instead.
A worked example
Jobs and chat in one app walks through a real app running both shapes on one key: background jobs as a run each, a chat assistant as a run per session.
Doing this over OpenTelemetry
If you already emit OTel traces, see
OpenTelemetry → conversations. The
short version: a trace is normally a run, so a trace per turn gives you the run-per-
message shape this page argues against. Setting agentping.run on the trace makes it
one turn of a run you control instead.