Could you please provide the code and examples on ...
# ask-ai
d
Could you please provide the code and examples on how to configure the recording option on the livekit agent ai
t
Thanks for reaching out, ahbe. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding to your request for code and examples to configure the recording option on a LiveKit Agent AI. Below I’ll show the common ways to control recording and give runnable examples and notes for each approach. High-level options • Disable recording for an individual agent session (session-level). • Enable automatic recording/egress for calls (auto-egress / dispatch rules). • Enable project-level observability (affects defaults; sessions can still opt out). • Perform manual egress after a session ends (start egress jobs). 1) Disable recording at session level (recommended when you must not store audio/transcripts) • Use
record=False
when starting a session to prevent audio, transcripts, traces, and logs from being uploaded. Python example:
Copy code
# Assuming you have an existing `session` and `agent` objects
await session.start(
    agent=agent,
    room=ctx.room,
    record=False  # Disables audio/transcripts/traces/logs for this session
)
Notes: • Use this for PCI-compliant or other sensitive workflows where recording must be blocked. • This setting applies only to the specific session. 2) Enable automatic recording (Auto-Egress) via dispatch rules (records to cloud storage) • Configure your SIP dispatch rule or room configuration to include an AutoEgress configuration that writes encoded files (MP4/other) to S3 or another supported destination. Python-style pseudocode example (structure shown for clarity):
Copy code
from livekit import api
from livekit.agents import SIPDispatchRuleIndividual, CreateSIPDispatchRuleRequest
from livekit.egress import AutoEgressConfiguration, EncodedFileOutput, EncodedFileType_MP4, S3Upload, RoomConfiguration

dispatch_rule_request = CreateSIPDispatchRuleRequest(
    trunk_ids=[inbound_trunk.sip_trunk_id],
    rule=SIPDispatchRuleIndividual(room_prefix="call"),
    room_config=RoomConfiguration(
        egress=AutoEgressConfiguration(
            file_outputs=[
                EncodedFileOutput(
                    file_type=EncodedFileType_MP4,
                    filepath="recordings/${room_name}_${time}",
                    s3=S3Upload(
                        bucket="my-bucket",
                        access_key="YOUR_AWS_KEY",
                        secret="YOUR_AWS_SECRET",
                        region="us-east-1"
                    )
                )
            ]
        )
    )
)

# Then create the dispatch rule via the API client
api.create_sip_dispatch_rule(dispatch_rule_request)
Notes: • Auto-Egress records sessions automatically (useful for call recording). • Ensure credentials and permissions for S3 (or other egress storage) are configured. 3) Enable Agent Observability at project level (dashboard setting) • Turn on Agent Observability in Project Settings → Data and Privacy in the LiveKit Cloud Dashboard to allow recording/observability by default. • Once enabled at project level, individual sessions can still opt out using
record=False
. 4) Manual egress after a session (start egress job) • If you prefer to record selectively after the session ends, use room/track composite egress APIs to start recording jobs (e.g.,
StartRoomCompositeEgress
or
StartTrackCompositeEgress
) that save outputs to your storage. Example concept (call egress API after session ends): 1. Session completes. 2. Call the Egress API with the room name and desired output configuration (file type, storage destination). 3. Monitor the egress job until completion and retrieve the file location. Environment / credentials checklist • LIVEKIT_API_KEY, LIVEKIT_API_SECRET, LIVEKIT_URL for LiveKit access. • If using S3/GCS: AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY (or equivalent GCS credentials). • Ensure IAM/bucket permissions allow uploads from your egress jobs. Which example do you want next? • I can provide a full, runnable sample app (Python or Node) that: ◦ a) starts an agent session with recording disabled, or ◦ b) configures Auto-Egress dispatch rules and uploads to S3, or ◦ c) shows starting a room composite egress after the call ends. Which language and use case should I expand into a complete example for you? Sources: Handling payments with PCI compliance | LiveKit | examples/frontdesk | livekit/livekit_composite | DeepWiki | Streamline troubleshooting with Agent Observability