worried-kite-20319
11/15/2025, 5:08 AMtall-airline-16756
11/15/2025, 5:09 AMtall-airline-16756
11/15/2025, 5:09 AMon_user_turn_completed. This keeps things flexible and responsive.
If you’d like, I’d be more than happy to walk you through detailed examples or help you implement any of these methods. Just let me know!
Sources: Agent dispatch | LiveKit Docs | External data and RAG | LiveKit Docs | telephony/survey_caller/survey_calling_agent.py | Building an Automated IVR Menu Caller | LiveKit Docsworried-kite-20319
11/15/2025, 5:14 AMtall-airline-16756
11/15/2025, 5:14 AMimport json
from livekit import JobContext, AgentSession, ChatContext, Assistant
async def entrypoint(ctx: JobContext):
# Parse job metadata
metadata = json.loads(ctx.job.metadata)
user_name = metadata["user_name"]
city = metadata["city"]
# Create initial chat context
initial_ctx = ChatContext()
initial_ctx.add_message(
role="assistant",
content=f"The user's name is {user_name} and they live in {city}."
)
# Start the agent session
session = AgentSession()
await session.start(
room=ctx.room,
agent=Assistant(chat_ctx=initial_ctx)
)
Here's what's happening in this example:
• The ctx.job.metadata holds the metadata provided at job startup, usually in JSON format.
• We parse this metadata to pull out user details like user_name and city.
• Then, we create an initial chat context and add a message that includes this extracted information.
• Finally, the agent session is started using the initialized context.
If anything feels unclear or you'd like me to share more examples, please don't hesitate to ask—I'm here to help!worried-kite-20319
11/15/2025, 5:19 AMtall-airline-16756
11/15/2025, 5:20 AMimport LiveKit
var room = Room()
var config = ConnectConfig()
config.metadata = "{\"user_id\": \"123\", \"user_name\": \"John Doe\"}" // JSON string
room.connect("wss://your-server-url", token: "your-token", config: config) { result in
// Handle connection result
}
In this example:
• The metadata field is set in the ConnectConfig object as a JSON string.
• This metadata is passed to the server when the client connects, and it can be accessed in the agent using ctx.job.metadata.
If you have any questions or need a hand with implementing this, please don’t hesitate to ask—I’m here to help!
Sources: Room metadata | LiveKit Docs | Participant attributes and metadata | LiveKit docs | cmd/lk/token.go | Sources/LiveKit/Protos/livekit_rtc.pb.swift | Agent dispatch | LiveKit Docs