aloof-scooter-47164
12/08/2025, 5:55 PMtall-airline-16756
12/08/2025, 5:55 PMtall-airline-16756
12/08/2025, 5:55 PMperformRpc (or equivalent) and receive the resolved value when the handler finishes.
If you’d like, tell me which SDK you’re using (JavaScript, Python, Swift, Kotlin, Go) and I’ll show a short async example for that SDK.
Sources: Remote method calls | LiveKit docsaloof-scooter-47164
12/08/2025, 5:56 PMtall-airline-16756
12/08/2025, 5:56 PMfrom livekit import Room, RpcInvocationData
room = Room(...)
@room.local_participant.register_rpc_method("greet")
async def handle_greet(data: RpcInvocationData):
# async work: database call, HTTP request, etc.
user = data.caller_identity
payload = data.payload
# await some async operation, e.g. await fetch_user_info(user)
await some_async_operation(payload)
return f"Hello, {user}!"
Calling an RPC from a client is also async and returns the handler's resolved value (use await when calling).
If you want, share a short use case (e.g., calling an external API inside the handler) and I’ll provide a concrete snippet.aloof-scooter-47164
12/08/2025, 7:40 PMtall-airline-16756
12/08/2025, 7:40 PMperform_rpc, for example:
response = await room.local_participant.perform_rpc(
destination_identity=participant_identity,
method="slow_operation",
payload="...",
response_timeout=30.0, # wait up to 30 seconds
)
Best options for slow operations:
• Raise response_timeout to match expected duration.
• Have the RPC start the long task and return immediately (e.g., "task started"), then notify completion via events or polling.
• If using speech-generation flows, consider allow_interruptions=False where relevant.
Would you like a concrete example for starting a background task and notifying completion?
Sources: Remote method calls | LiveKit docs | Agent speech and audio | LiveKit docsaloof-scooter-47164
12/08/2025, 7:46 PMtall-airline-16756
12/08/2025, 7:46 PMresponse_timeout when calling perform_rpc so it comfortably exceeds the tool's worst-case runtime.
response = await room.local_participant.perform_rpc(
destination_identity=participant_identity,
method="run_tool",
payload=payload,
response_timeout=120.0, # e.g., wait up to 2 minutes
)
2) If the tool can be very slow/unpredictable, keep the RPC handler responsive while still returning the final result by running the long task inside the handler but with careful resource/timeout management:
• Ensure the handler actually awaits the long-running async call so the final result is returned before the timeout.
• Consider increasing response_timeout enough for the full operation.
• Make the handler robust to errors and return clear failure responses (so callers don't hang waiting).
If blocking the caller for the full duration is unacceptable, use a hybrid approach:
• RPC returns immediately with a task ID (acknowledge).
• Worker runs the long tool and, when done, delivers the result via a LiveKit event/message or a follow-up RPC the caller can await/poll.
Which approach do you prefer? I can provide a concrete Python snippet for a handler that awaits a long async tool call (with error handling) or an example of the task-ID + event notification pattern.