DEV Community

anusha
anusha

Posted on

Your AI Agent Already Keeps a Flight Recorder. Here's How to Play It Back.

Agent Message Replay — a Telnyx Edge Compute sample that replays recorded agent conversations as live WebSocket streams, re-enacts the agent's state changes, and annotates each step with LLM commentary.

Clone it here:

https://github.com/team-telnyx/telnyx-code-examples/tree/main/agent-message-replay

The problem it solves

AI agents are non-deterministic. The moment one goes wrong in production, teams discover they have no way to answer a simple question: what did the agent know, and what had it concluded, at the moment it went wrong?

A transcript tells you who said what. It doesn't tell you what stage the agent was in, what it had verified, or what changed its plan. So teams reconstruct sessions from log lines, guess at state, and argue about what the agent "must have" done.

The Telnyx Agent SDK quietly solves the hard part: every conversation is persisted in a durable message log. The sample asks — what if you could just press play on that?

What the replay looks like

One conversation, one durable actor. A ReplayAgent extends Agent holds a recorded conversation and streams it back over an AgentSocketServer:

  • Messages stream live through the durable MessageLog, in recorded order, with timestamps
  • State changes re-enact — the original agent's stage at each step arrives as a live state patch, so you watch intake → verifying → investigating → resolving → resolved happen again
  • An LLM annotates as it plays — on every agent message, the sample sends the conversation history (via MessageLog.toOpenAI()) to env.TELNYX.ai.openai.chat.createCompletion, the pre-authenticated inference binding. No API keys anywhere.
  • You can scrub — pause at message five, drag the timeline, see the chat, state trail, and commentary filtered to that exact moment

Playback is a durable schedule() tick chain inside the actor. That gives you pause/resume that survives actor restarts, playback speed that applies on the next tick, and a playhead that persists. It behaves like a media player because it's built like one — on durable state.

Why this is less work than it sounds

There is no extra instrumentation. No event schema. No analytics pipeline. No "integrate observability" project. If your agent runs on the Telnyx Agent SDK, the recording already exists — the sample is roughly two hundred lines showing how to read it back:

const history = toChatMessages(await this.messages.toOpenAI());
const completion = await this.env.TELNYX.ai.openai.chat.createCompletion({
  model: this.env.MODEL ?? "zai-org/GLM-5.2",
  messages: [{ role: "system", content: COMMENTARY_PROMPT }, ...history],
});
Enter fullscreen mode Exit fullscreen mode

The commentary rides a separate event stream, so the replay stays a faithful recording. A 30-second timeout turns a slow model call into a commentary_error event instead of a stalled replay.

What you'd use it for

  • Post-call QA at scale — replay real resolutions with annotations instead of reading raw transcripts
  • Training — new support agents watch how real sessions actually progressed, state changes and all
  • Incident forensics — a prompt or model change made things worse? Replay the before/after conversations and compare
  • Compliance — prove exactly what was said, when, and what the agent's state was at each point

And because conversations can be keyed by phone number, "replay the session with this customer" is a URL, not a project.

Try it

git clone https://github.com/team-telnyx/telnyx-code-examples.git
cd telnyx-code-examples/agent-message-replay
npm install && npm run typecheck && npm test
Enter fullscreen mode Exit fullscreen mode

The README walks through deploying to Telnyx Edge Compute with the telnyx-edge CLI. The sample includes a flow-conformance test suite (real agent, real socket server, in-memory storage) and a live end-to-end script that verifies a deployed function in nine checks — attach and claims, ordered streaming, state re-enactment, ingest, and real-inference commentary.

A transcript is a record. A replay is understanding.

Top comments (0)