How to store the transcription of an agent call to...
# ask-ai
s
How to store the transcription of an agent call to S3 egress at the end of a call?
t
Thanks for reaching out, Aldrin. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To store the transcription of an agent call to S3 egress at the end of a call, you can modify your agent code to capture the conversation history and save it when the call ends. Here's a general approach: 1. Add a shutdown callback function to your agent that executes when the room closes. For example:
Copy code
from datetime import datetime
import json

async def entrypoint(ctx: JobContext):
    # Add this code to save transcripts when the call ends
    async def write_transcript():
        current_date = datetime.now().strftime("%Y%m%d_%H%M%S")
        
        # Create a JSON file with the conversation history
        filename = f"/tmp/transcript_{ctx.room.name}_{current_date}.json"
        
        with open(filename, 'w') as f:
            json.dump(session.history.to_dict(), f, indent=2)
            
        print(f"Transcript for {ctx.room.name} saved to {filename}")
    
    # Register the callback to run when the room closes
    ctx.add_shutdown_callback(write_transcript)
    
    # Rest of your entrypoint code follows...
2. This code saves the conversation history to a JSON file when the call ends. You can then configure S3 egress to upload this file to your S3 bucket. For optimal results, it's recommended to delete the room when the call ends to ensure proper cleanup and avoid extra audio in recordings. Sources: Session recording and transcripts | LiveKit Docs