Session Replay
AgentOS session replay allows you to record every action an agent takes during a conversation — LLM calls, tool invocations, memory operations — and replay them later for debugging, cost analysis, and performance optimization.Overview
Implemented insrc/session-replay.ts:1, session replay provides:
- Action-level recording - Capture LLM calls, tool executions, and results
- Duration tracking - Measure time spent on each operation
- Iteration counting - Track agent reasoning loops
- Cost analysis - Aggregate token usage and costs
- Search and filtering - Find sessions by agent, tool, or time range
Recording Actions
Actions are automatically recorded by the agent loop, but you can also record manually:Action Types
Fromsrc/session-replay.ts:9:
llm_call- LLM inference requeststool_call- Tool invocationtool_result- Tool execution resultmemory_op- Memory store/recall operations
Retrieving Session Replay
Get Full Replay
src/session-replay.ts:92).
Get Summary with Statistics
src/session-replay.ts:165-207, the summary aggregates:
- Total duration
- Max iteration (reasoning loops)
- Token usage from LLM calls
- Cost from LLM calls
- Unique tools used
Searching Sessions
Search by Agent
Search by Tool Usage
src/session-replay.ts:134-138, only sessions with tool_call actions matching the toolId are returned.
Search by Time Range
Combined Search
Real-World Example: Debugging Slow Agent
Cost Analysis Across Sessions
Sequence Counter
Fromsrc/session-replay.ts:42-50, each session has a monotonically increasing counter:
HTTP API Endpoints
CLI Commands
From the README (workspace/source/README.md:362-364):
Limits
Fromsrc/session-replay.ts:113:
- Max search results: 200 sessions
- Default search limit: 50 sessions
Best Practices
Record critical operations
Record critical operations
Focus on LLM calls and tool executions. Memory operations are lightweight and optional.
Include duration measurements
Include duration measurements
Always measure and record
durationMs for performance analysis.Track iteration count
Track iteration count
Use the
iteration field to understand reasoning loop depth.Search before analyzing
Search before analyzing
Use
replay::search to find interesting sessions, then use replay::get for details.Monitor costs regularly
Monitor costs regularly
Use
replay::summary to track token usage and costs per session.Clean up old replays
Clean up old replays
Implement a retention policy to delete old replay data and manage storage.
Use Cases
Debugging
Replay failed sessions to understand what went wrong and where
Performance Optimization
Identify slow operations and reduce latency
Cost Analysis
Track token usage and costs across agents and time periods
Agent Training
Analyze successful sessions to improve prompts and workflows
Compliance & Auditing
Maintain audit trails of agent actions for security reviews
Tool Usage Analytics
Understand which tools agents use most frequently
Related Features
- Swarms - Record swarm coordination patterns
- Knowledge Graph - Track KG modifications in replay
- Security - Combine with audit logs for full traceability