nice-fish-21757
09/07/2025, 9:49 AMtall-airline-16756
09/07/2025, 9:49 AMtall-airline-16756
09/07/2025, 9:49 AMmetadata field, which is great for holding structured info like JSON.
• Participant and Room Metadata/Attributes: This lets you store and access user-defined data that's tied dynamically to participants or rooms.
• AgentSession Userdata: Use the userdata parameter in AgentSession if you want strongly-typed, mutable state that sticks around across sessions or handoffs.
• Process-Level User Data: For reusable components at the worker process level, you can use the JobProcess.userdata dictionary.
• Custom Logging Context: If you want to add custom fields to your logs for easier debugging and monitoring, ctx.log_context_fields is the way to go.
These options give you plenty of flexibility to manage your user-defined variables within a job context. If you'd like, I’m happy to share more details or examples for any of these—just let me know!
Sources: Workflows | LiveKit Docs | flows/declarative_flow.py | Job lifecycle | LiveKit Docs | examples/voice_agents/multi_agent.pynice-fish-21757
09/07/2025, 9:57 AMtall-airline-16756
09/07/2025, 9:58 AMlog_context_fields property on the JobContext object to add your own fields to every log entry. Here’s a simple example:
async def entrypoint(ctx: JobContext):
ctx.log_context_fields = {
"worker_id": ctx.worker_id,
"room_name": ctx.room.name,
}
• JavaScript SDK: Try out the setLogExtension function to dynamically tack on extra context to your logs. Like this:
setLogExtension((level, msg, context) => {
const enhancedContext = { ...context, timeStamp: Date.now() };
// Forward enhancedContext to your logging provider
});
With these, you can easily include things like user IDs, room names, or timestamps in your logs. If you want more examples or need help with a specific SDK or scenario, just give me a shout—I’m here to help!
Sources: examples/voice_agents/basic_agent.py | packages/livekit-rtc/src/proto/ffi_pb.ts | Sources/LiveKit/Extensions/Logger.swift | Runtime/Scripts/Proto/Ffi.cs | Job lifecycle | LiveKit Docs