refined-hydrogen-81988
11/11/2025, 7:40 PMregister_rpc_method? is there a simple example without custom frontend?tall-airline-16756
11/11/2025, 7:40 PMtall-airline-16756
11/11/2025, 7:41 PMctx.room.local_participant.register_rpc_method("method_name", handler_function). This setup lets remote participants—like web clients or other agents—call your method to trigger actions or fetch data.
Here’s a straightforward example to help you along:
async def handle_diagnosis_request(data: rtc.RpcInvocationData):
try:
payload = json.loads(data.payload)
symptom = payload.get("symptom", "unknown")
response = {"diagnosis": f"Based on '{symptom}', try getting rest", "severity": "low"}
return json.dumps(response)
except Exception as e:
return json.dumps({"error": str(e)})
# Register the RPC method
ctx.room.local_participant.register_rpc_method("request_diagnosis", handle_diagnosis_request)
In this example, we register an RPC method called request_diagnosis, define a handler to process incoming requests, and return a JSON response. It’s a simple way to get your RPC up and running!
If you’d like to explore further, I recommend checking out the LiveKit RPC Documentation and Using RPC with Agents. They offer great insights and additional details to support you.
Sources: rpc/rpc_agent.py | agent/game_host.py | Remote method calls | LiveKit docs | Tool definition and use | LiveKit docs