c
hi
t
Thanks for reaching out, Arun. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hi — nice to meet you. How can I help today? If you’re troubleshooting something, please share: • Product area (SDK, dashboard, rooms, recording, billing, etc.) • Any error messages, room or participant IDs, and steps to reproduce (if applicable)
c
from dotenv import load_dotenv load_dotenv() from utils import DEFAULT_SYSTEM_PROMPT from utils import get_tts_from_config, get_greeting_from_config import json from livekit.agents import Agent, JobContext, WorkerOptions, cli from livekit.agents.voice import AgentSession from livekit.plugins import deepgram, groq, silero class WebAgent(Agent): def __init__(self, job_meta_str): self.job_meta_str = job_meta_str meta = json.loads(self.job_meta_str) if job_meta_str else {} agent_info = meta.get("web-agent", {}) instructions = agent_info.get("system_prompt", DEFAULT_SYSTEM_PROMPT) tts_config = agent_info.get("tts", {}) tts_instance = get_tts_from_config(tts_config) super().__init__( instructions=instructions, stt=deepgram.STT(), llm=groq.LLM(model="llama-3.1-8b-instant"), tts=tts_instance, vad=silero.VAD.load() ) async def entrypoint(ctx: JobContext): agent = WebAgent(getattr(ctx.job, "metadata", "{}")) session = AgentSession() await session.start(agent=agent, room=ctx.room) await session.say(get_greeting_from_config(getattr(ctx.job, "metadata", "{}"))) def run(): cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint, agent_name="web-agent", port=8081)) if name == "__main__": run() i need end call rpeoert liek trnacripe strint end time durtdiosn etcs ssesion
t
You're asking how to produce an end-call report (transcript, end time, duration, session info) from your WebAgent. I’ll help you add a concise solution integrated into your existing code. A quick clarification so I deliver exactly what you need: • Do you want the report printed to stdout, saved to a file (JSON), or sent somewhere (webhook/S3)? • Are you using the Python LiveKit Agents SDK (yes/no)? If yes, use these steps (minimal change to your code): 1) Track start time when the session starts. 2) Collect transcript pieces from transcription and conversation events during the session. 3) On session close / shutdown, record end time, compute duration, and build a JSON report. 4) Optionally call
ctx.make_session_report()
for a full SDK report and include it. Example patch (drop into your file; preserves your structure):
Copy code
from datetime import datetime
import json
# (keep your existing imports)

# inside entrypoint
async def entrypoint(ctx: JobContext):
    agent = WebAgent(getattr(ctx.job, "metadata", "{}"))
    session = AgentSession()

    start_time = datetime.utcnow()
    transcript_items = []

    @session.on("user_input_transcribed")
    def on_user_transcribed(event):
        transcript_items.append({
            "role": "user",
            "text": getattr(event, "transcript", ""),
            "is_final": getattr(event, "is_final", False),
            "ts": datetime.utcnow().isoformat()
        })

    @session.on("conversation_item_added")
    def on_conversation_item(event):
        transcript_items.append({
            "role": getattr(event.item, "role", "agent"),
            "text": getattr(event.item, "text_content", ""),
            "ts": datetime.utcnow().isoformat()
        })

    @session.on("close")
    def on_close(event):
        end_time = datetime.utcnow()
        duration_seconds = (end_time - start_time).total_seconds()

        report = {
            "session_id": getattr(ctx.job, "sid", None),
            "room_name": getattr(ctx.room, "name", None),
            "start_time": start_time.isoformat(),
            "end_time": end_time.isoformat(),
            "duration_seconds": duration_seconds,
            "participant_identity": getattr(ctx.room.local_participant, "identity", None),
            "transcript": transcript_items,
            "error": getattr(event, "error", None)
        }

        print(json.dumps(report, indent=2))
        # optional: save to file
        # with open(f"report_{report['session_id']}.json","w") as f:
        #     json.dump(report, f, indent=2)

    async def on_session_end():
        # optional: include SDK session report if available
        try:
            sdk_report = ctx.make_session_report()
            report_full = {"sdk_report": sdk_report.to_dict()}
            print(json.dumps(report_full, indent=2))
        except Exception:
            pass

    ctx.add_shutdown_callback(on_session_end)

    await session.start(agent=agent, room=ctx.room)
    await session.say(get_greeting_from_config(getattr(ctx.job, "metadata", "{}")))
If you want: • report saved to S3 or a webhook, tell me which and I’ll add the snippet; or • to include recording file paths / egress details from
ctx.make_session_report()
, confirm you want the SDK report included and I’ll show how to extract those fields. Which output method do you prefer (stdout / file / webhook / S3)? Sources: Observability data hooks | LiveKit docs | Events and error handling | LiveKit docs | Text and transcriptions | LiveKit docs