high-orange-33312
09/07/2025, 4:54 PMtall-airline-16756
09/07/2025, 4:54 PMtall-airline-16756
09/07/2025, 4:55 PMassume_role_arn field in the S3 configuration works only if this feature is turned on for your LiveKit Cloud account. If it’s not enabled, uploads using this method won’t go through.
• Security Enforcement: For your safety, sensitive info like the secret key can’t be included in egress requests. Instead, it’s best to use IAM roles or set up credentials on the server side.
• S3-Compatible Storage: LiveKit plays nicely with S3-compatible providers like MinIO or Oracle Cloud. Just a heads-up—if you’re using a non-AWS provider, make sure to set force_path_style to true in your config.
Double-check that your account has the right features enabled and your setup follows these guidelines. If you run into any hiccups or want help with specific settings or error messages, just give me a shout—I’m here to help!
Sources: pkg/config/storage.go | Egress output types | LiveKit Docs | livekit/livekit_egress.pb.gohigh-orange-33312
09/07/2025, 4:58 PMfrom dotenv import load_dotenv
from prompts import SESSION_INSTRUCTION, AGENT_INSTRUCTION
from datetime import datetime
import json
import os
import io
import boto3
from livekit import agents, api
from livekit.agents import AgentSession, Agent, RoomInputOptions, JobContext
from livekit.plugins import (
openai,
noise_cancellation,
)
# Load environment variables
load_dotenv(".env.local", override=True)
# --- Define your custom assistant ---
class Assistant(Agent):
def __init__(self) -> None:
super().__init__(instructions=AGENT_INSTRUCTION)
# --- Entrypoint for LiveKit Agent ---
async def entrypoint(ctx: JobContext):
# --- Agent session setup ---
session = AgentSession(
llm=openai.realtime.RealtimeModel(
voice="coral"
)
)
# --- Shutdown tasks: upload transcript and notify frontend ---
async def shutdown_tasks():
# Convert session history to JSON bytes
transcript_data = json.dumps(
session.history.to_dict(),
indent=2,
ensure_ascii=False
).encode("utf-8")
# Setup S3 client
s3 = boto3.client(
"s3",
aws_access_key_id=os.getenv("S3_ACCESS_KEY"),
aws_secret_access_key=os.getenv("S3_SECRET_KEY"),
region_name=os.getenv("S3_REGION"),
)
# Generate S3 key
current_date = datetime.now().strftime("%Y%m%d_%H%M%S")
s3_key = f"AIAssistant/transcript_{ctx.room.name}_{current_date}.json"
# Upload transcript directly from memory
s3.upload_fileobj(io.BytesIO(transcript_data), os.getenv("S3_BUCKET"), s3_key)
print(f"Transcript uploaded to S3: s3://{os.getenv('S3_BUCKET')}/{s3_key}")
# Generate presigned URL
presigned_url = s3.generate_presigned_url(
"get_object",
Params={"Bucket": os.getenv("S3_BUCKET"), "Key": s3_key},
ExpiresIn=3600, # URL valid for 1 hour
)
# Notify frontend via LiveKit data channel
ctx.room.local_participant.publish_data(
f"TRANSCRIPT_READY:{presigned_url}".encode("utf-8"),
reliable=True,
)
print(f"Frontend notified with transcript URL: {presigned_url}")
# Add shutdown callback
ctx.add_shutdown_callback(shutdown_tasks)
# Start the agent session
await session.start(
room=ctx.room,
agent=Assistant(),
room_input_options=RoomInputOptions(
noise_cancellation=noise_cancellation.BVC(),
),
)
# Generate initial instructions/reply
await session.generate_reply(
instructions=SESSION_INSTRUCTION
)
# --- Run locally if executed as main ---
if __name__ == "__main__":
agents.cli.run_app(agents.WorkerOptions(entrypoint_fnc=entrypoint))tall-airline-16756
09/07/2025, 4:59 PMboto3 to upload transcripts to S3, which is great, but LiveKit Cloud has some specific requirements and restrictions for S3 uploads that are good to keep in mind:
• LiveKit Cloud supports S3 uploads using access keys and secrets, but usually, this is handled through LiveKit’s egress system rather than directly with boto3.
• Including sensitive credentials like aws_secret_access_key directly in your code might cause issues with LiveKit’s security validation.
• For a safer and smoother experience, it’s best to use IAM roles (like assume_role_arn, if your account has it enabled) or manage secrets through your environment.
If you want to dig deeper, it’s a good idea to check whether your LiveKit Cloud account has the right features enabled (such as IAM role assumption) and make sure your setup matches LiveKit’s egress system. Feel free to reach out if you’d like a hand tweaking your code to fit LiveKit’s supported methods—I’m here to help!
Sources: egress/redact_test.go | Egress API | LiveKit Docs | cmd/lk/examples/web-egress.json | RoomComposite Egress | LiveKit Docs | Web Egress | LiveKit Docshigh-orange-33312
09/07/2025, 5:00 PMtall-airline-16756
09/07/2025, 5:01 PMboto3 or google-cloud-storage.
3. Custom Logic: Add some custom logic in your agent to handle storing and uploading the transcription as part of shutting down the session.
Since the egress service focuses on media exports, uploading transcriptions will need a bit of custom post-processing. If you’d like, I’m here to help you set this up or tweak your agent code—just let me know!
Sources: Egress & Media Processing | livekit/livekit_composite | DeepWiki | Egress & Storage | livekit/livekit_composite | DeepWiki | Recording agent sessions | LiveKit Docshigh-orange-33312
09/07/2025, 5:06 PMtall-airline-16756
09/07/2025, 5:06 PMhigh-orange-33312
09/07/2025, 5:06 PMtall-airline-16756
09/07/2025, 5:06 PM