adorable-engine-68435
10/25/2025, 4:29 PMtall-airline-16756
10/25/2025, 4:29 PMtall-airline-16756
10/25/2025, 4:30 PMagent_state_changed event to keep track of changes in the agent's state, like when they’re initializing, listening, thinking, or speaking.
• User State Change Events: The user_state_changed event is great for monitoring user activity states such as speaking, listening, or away.
• Participant Attributes: You can access the lk.agent.state attribute right in the frontend to keep everything synchronized and show the agent’s current state clearly.
• Custom RPC Notifications: If you want something more tailored, you can define and trigger custom Remote Procedure Calls (RPC) to notify agents or clients about specific state changes.
• Agent Presence Detection: Don’t forget the ParticipantConnected events — they help you detect when an agent joins the room, keeping you informed in real time.
All these options work together to give you smooth, real-time updates and effortless communication between agents and frontends. If you’d like, I’d be more than happy to walk you through any of these with more details or examples. Just let me know!
Sources: packages/react/src/hooks/useAgent.ts | Web and mobile frontends | LiveKit Docs | complex-agents/role-playing/agents/base_agent.py | agent-console/components/no-agent-notification.tsx | Events and error handling | LiveKit Docsadorable-engine-68435
10/25/2025, 4:37 PMtall-airline-16756
10/25/2025, 4:38 PMregister_rpc_method. Without this step, the agent won’t be able to process the notification.
• Destination Identity: Make sure that the destination_identity in the RPC call exactly matches the agent’s participant identity. This little detail can sometimes be the key!
• Agent Initialization: Confirm that your agent is fully connected and initialized in the room before sending any RPCs. If it’s not ready, the notifications might get missed.
• Payload Parsing: Double-check that the payload is correctly formatted and properly parsed within the agent’s handler. If you’re working with JSON, using json.loads can help process the payload smoothly.
• Error Handling: It’s a good idea to include error handling in your RPC handler to catch and log any issues during execution. This way, you’ll have more insight if something goes wrong.
• Logging: Adding logging can be really helpful to track whether the RPC is actually received and processed by the agent. It’s like having a little detective on your side!
• Frontend Implementation: Lastly, please verify that the frontend is using the correct method name and destination identity when calling performRpc. This ensures the call reaches the right place.
Take a look through these points, and hopefully, they’ll help pinpoint where things might be going off track. If you’d like, I’m here to assist further or provide specific examples to help with debugging. Just let me know!
Sources: agent/game_host.py | complex-agents/role-playing/role_playing_frontend/components/game-status.ts... | agent/main.pyadorable-engine-68435
10/25/2025, 4:39 PMtall-airline-16756
10/25/2025, 4:41 PMregister_rpc_method. Here's a simple example to guide you:
ctx.room.local_participant.register_rpc_method(
"agent.state_update", # Method name
handle_state_update # Handler function
)
• Payload Handling: Next, it’s important to properly extract and parse the payload within the handler. For example:
async def handle_state_update(rpc_data: RpcInvocationData):
payload = json.loads(rpc_data.payload)
# Process the payload based on its type
if payload.get("type") == "state_change":
await process_state_change(payload)
• State Integration: Then, update your agent’s internal state and chat context based on the payload. Here’s how you might do that:
async def process_state_change(update_data):
chat_ctx = self.chat_ctx.copy()
chat_ctx.add_message(role="system", content=f"State updated: {update_data.get('summary')}")
await self.update_chat_ctx(chat_ctx)
• Error Handling: It’s a great idea to add error handling to catch and manage any issues during execution.
• Logging: Implement logging so you can easily track when RPC messages are received and processed.
• Bidirectional Communication: If you like, you can also set up RPC methods for your agent to send updates back to clients, making communication even smoother.
Following these steps will really help your agent recognize and act on updates sent via RPC. If you’d like me to walk you through any part in more detail or provide additional examples, just let me know—I’m here to help!
Sources: rpc/rpc_agent.py | Bringing AI avatars to voice agents | Remote method calls (RPC) | LiveKit Docs