wide-dress-57902
08/19/2025, 11:33 PMtall-airline-16756
08/19/2025, 11:33 PMtall-airline-16756
08/19/2025, 11:34 PMasync def entrypoint(ctx: JobContext):
try:
await ctx.connect()
# Your agent logic here
except Exception as e:
logger.error(f"Error in job: {e}")
await ctx.shutdown("error occurred")
1. Keep the job lifecycle smooth by calling ctx.connect()
and managing shutdowns carefully.
2. Use logging to catch and understand issues early before they become bigger problems.
Also, the error message usually includes a stack trace (exc_info=t.exception()
) which is super helpful for pinpointing what went wrong. If you want, I’m here to help you dig deeper or clarify anything—just let me know!
Sources: livekit-agents/livekit/agents/__init__.pywide-dress-57902
08/19/2025, 11:42 PMtall-airline-16756
08/19/2025, 11:44 PMdecorator.py
module. Instead, decorators pop up in different parts of the system, each serving its own special purpose. Here are some handy examples to give you a feel for how they’re used:
• Function Tools: The @function_tool
decorator is your go-to in LiveKit Agents when you want to define tools that LLMs can access. Check this out:
from livekit.agents import function_tool
class MyAgent(Agent):
@function_tool()
async def lookup_weather(self, context: RunContext, location: str) -> dict:
return {"weather": "sunny", "temperature_f": 70}
• Event Handling: You’ll see decorators like @emitter.on
used to register event listeners.
• RPC Method Registration: The @room.local_participant.register_rpc_method
decorator helps define those handy RPC methods.
• Storybook Decorators: These are great for testing and development within the components library.
If you’re hunting for a particular decorator or want to dive deeper into how something works, just give me a shout—I’m here to help!
Sources: Tool definition and use | LiveKit Docs | Agents v0.x migration guide | LiveKit Docs | livekit-rtc/livekit/rtc/event_emitter.py | docs/storybook/.storybook/lk-decorators/MockParticipantContext.tsx | mcp_client/agent_tools.py