session-recording

command
v2.21.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Session Recording Example

This example demonstrates the session recording and replay capabilities of PromptKit.

Features Demonstrated

  1. Recording: Capture conversation events to a file-based EventStore
  2. Export: Save sessions to portable JSON format
  3. Replay: Deterministically replay sessions using ReplayProvider
  4. Playback: Timeline-based playback with SessionPlayer

Prerequisites

Set your API key:

export OPENAI_API_KEY=your-key

Running

From the example directory:

cd sdk/examples/session-recording
go run .

Or from the repo root:

go run ./sdk/examples/session-recording

Expected Output

=== Session Recording Demo ===

Step 1: Recording a live conversation...
   User: What is the capital of France?
   Assistant: The capital of France is Paris...
   User: What's the population of that city?
   Assistant: Paris has a population of approximately...
   User: Thanks! One more question: what river runs through it?
   Assistant: The Seine River runs through Paris...
   Session recorded: abc123

Step 2: Exporting session to JSON...
   Saved 6 events
   Exported to: /tmp/promptkit-recording-xxx/session.recording.json

Step 3: Replaying session with ReplayProvider...
   Loaded recording with 6 events
   Created ReplayProvider with 3 turns
   Turn 1: The capital of France is Paris...
   Turn 2: Paris has a population of approximately...
   Turn 3: The Seine River runs through Paris...

Step 4: Playing back with SessionPlayer...
   [  0.00s] message.created
   [  0.10s] provider.call.completed
   [  0.20s] message.created
   ...
   Played 6 events

=== Demo Complete ===

Code Walkthrough

Recording a Session
// Create an event store
store, _ := events.NewFileEventStore("./recordings")

// Open conversation with recording enabled
conv, _ := sdk.Open("./chat.pack.json", "chat", sdk.WithEventStore(store))

// Conversation is automatically recorded
resp, _ := conv.Send(ctx, "Hello!")
Exporting to Portable Format
// Get recorded events
evts, _ := store.GetSessionEvents(ctx, sessionID)

// Build SessionRecording
rec := &recording.SessionRecording{
    Metadata: recording.Metadata{SessionID: sessionID},
    Events:   convertEvents(evts),
}

// Save as JSON
rec.SaveTo("session.json", recording.FormatJSON)
Replaying with ReplayProvider
// Load recording
rec, _ := recording.Load("session.json")

// Create provider (implements providers.Provider interface)
provider, _ := replay.NewProvider(rec, &replay.Config{
    Timing:    replay.TimingInstant,  // No delays
    MatchMode: replay.MatchByTurn,    // Sequential
})

// Use like any provider
resp, _ := provider.Predict(ctx, providers.PredictionRequest{})
fmt.Println(resp.Content)
Timeline Playback
// Create player
player := events.NewSessionPlayer(evts)
player.SetSpeed(2.0)  // 2x speed

// Subscribe and play
ch := player.Subscribe()
go player.Play(ctx)

for evt := range ch {
    fmt.Printf("[%v] %s\n", evt.Offset, evt.Event.Type)
}

Use Cases

  • Testing: Replay recorded sessions for deterministic tests
  • Debugging: Inspect what happened during a conversation
  • Training Data: Export sessions for fine-tuning datasets
  • Demo/Presentation: Replay interactions without API calls

Documentation

Overview

Package main demonstrates session recording and replay.

This example shows:

  • Recording a conversation session to a file
  • Exporting the session to a portable format
  • Replaying the session deterministically

Run with:

export GEMINI_API_KEY=your-key  # or OPENAI_API_KEY
go run .

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL