RPC calls not reaching Python agent handlers ...
# ask-ai
j
RPC calls not reaching Python agent handlers Environment: - livekit-agents: 1.2.2 - Python: 3.11 - Deployment: AWS ECS/Fargate - LiveKit Cloud instance What we've verified: 1. Agent and client use matching identity: agent-AJ_zETA6RL9J6EU 2. RPC handlers registered: ['ping', 'start_turn', 'end_turn', 'cancel_turn'] 3. Token has canPublish and canPublishData permissions 4. Agent dispatch created successfully 5. Both participants in same room 6. Timeout increased to 15 seconds 7. Payload size is only 57 bytes (well under 15KiB limit) 8. Agent stays connected (no disconnect logs) Evidence from logs: Client sends RPC: [PTT] Starting RPC call to agent-AJ_zETA6RL9J6EU with method: start_turn [PTT] RPC Details: { "destinationIdentity": "agent-AJ_zETA6RL9J6EU", "localParticipantIdentity": "0197205 1-048b-702d-97c0-bbfb753ab2d3", "method": "start_turn", "payloadSize": "57 bytes", "roomState": "connected" } Agent is ready: RPC handlers registered: ['ping', 'start_turn', 'end_turn', 'cancel_turn'] Agent ready to receive RPC calls on identity: agent-AJ_zETA6RL9J6EU PTT Agent entering main loop, waiting for RPC calls... But handler is NEVER invoked - no logs like "PING RPC CALLED" or "PTT RPC CALLED" appear. Questions: 1. Is there a known issue with RPC in Python agents version 1.2.2? 2. Are we missing a required import or initialization step? Our code: @ctx.room.local_participant.register_r pc_method("start_turn") async def start_turn(data: rtc.RpcInvocationData): logger.info("PTT RPC CALLED: start_turn") # Never logs 3. Could AgentDispatchClient interfere with RPC routing? 4. Is there a way to enable RPC protocol debugging to see where messages are dropped? 5. Do Python agents require additional configuration for RPC compared to the TypeScript SDK? This appears to be an infrastructure or SDK issue rather than a code problem, as everything is configured correctly but RPC invocations never reach the Python handlers.
t
Thanks for reaching out, Albert. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Here are answers and suggestions based on your questions: 1. Known Issues with RPC in Python Agents 1.2.2: There are no documented issues specific to RPC in version 1.2.2. However, network conditions, server compatibility, or payload size limits could potentially cause issues. 2. Required Initialization Steps: Ensure that your RPC methods are properly registered. For example:
Copy code
@ctx.room.local_participant.register_rpc_method("start_turn")
async def start_turn(data: rtc.RpcInvocationData):
    <http://logger.info|logger.info>("PTT RPC CALLED: start_turn")
Verify that the
RpcInvocationData
payload is correctly parsed and handled. 1. AgentDispatchClient Interference: The
AgentDispatchClient
does not interfere with RPC routing. It manages agent dispatches separately from RPC operations. 2. Enabling RPC Protocol Debugging: • Set the
LIVEKIT_EVALS_VERBOSE
environment variable to
1
for detailed logging. • Adjust the logging level to
DEBUG
in your agent code:
Copy code
import logging
logging.basicConfig(level=logging.DEBUG)
• Include detailed logging in your RPC handlers to capture incoming calls and responses. 1. Additional Configuration for Python Agents: Python agents do not require additional configuration for RPC compared to the TypeScript SDK. Ensure that all handlers are registered and that the agent is connected to the correct room. If the issue persists, enabling verbose logging and reviewing the logs for dropped messages or errors would be the next step. Let me know if you need further assistance! Sources: Remote method calls (RPC) | LiveKit Docs | livekit-rtc/livekit/rtc/_proto/ffi_pb2.py | examples/agent-dispatch/index.ts | README.md | Dispatching agents | LiveKit Docs
j
LiveKit Support Question: RPC Methods Not Being Invoked Despite Successful Registration (Audio Works Fine) Environment: - LiveKit Python SDK: 1.2.2 - LiveKit Client SDK: React Native 2.7.6 with livekit-client 2.15.3 - Platform: React Native (Expo dev client with --tunnel mode) - Server: Python agent deployed on AWS Fargate - LiveKit Cloud: progress-note s-axnubc06.livekit.cloud Issue: RPC methods registered on the Python agent are never invoked, despite audio streaming working perfectly in the same session. The agent successfully registers RPC handlers but they're never called when the client performs RPC. What Works: - Audio streaming between client and agent works perfectly - Agent connects to room successfully - RPC handlers are registered after session.start() - Client and agent both connect to the same room - Client identifies agent correctly by identity What Doesn't Work: - RPC calls from client never reach the agent - No RPC handler invocation logs appear on server - Client's performRpc() calls timeout without response Agent Code (Python): # After session.start() completes @ctx.room.local_participant.re gister_rpc_method("ping") async def ping(data: rtc.RpcInvocationData): logger.info("PING RPC CALLED!") # This never logs return {"pong": True} # Confirmed in logs: # "RPC handlers registered: ['ping', 'start_turn', 'end_turn', 'cancel_turn']" # "Local participant identity: agent-AJ_SYsttz4zeJMy" Client Code (React Native): const result = await localParticipant.performRpc({ destinationIdentity: "agent-AJ_SYsttz4zeJMy", // Matches agent identity method: "ping", payload: "{}", responseTimeout: 15000 }); // Times out - no response received Key Observations: 1. Audio/voice communication works flawlessly in the same session 2. Both participants are connected to the same room 3. Agent logs show handlers are registered with correct identity 4. Client logs show RPC calls being made to correct destination 5. Using Expo tunnel (npm run dev --tunnel) for development Questions: 1. Why would audio streaming work but RPC fail in the same session? 2. Are there known issues with RPC through Expo tunnel that don't affect audio? 3. Is there a specific order of operations or timing requirement for RPC registration that differs from audio setup? 4. Could DataChannel initialization be failing silently while audio tracks work normally? Debug Information Collected: - Set LIVEKIT_EVALS_VERBOSE=1 - no additional RPC logs appeared - Verified ctx.room.local_part icipant._rpc_handlers contains all methods - No errors in client or server logs - WebRTC connection established (audio proves this) Any guidance on why RPC specifically fails while audio works would be greatly appreciated!
t
Here are some insights and suggestions based on your questions: 1. Why would audio streaming work but RPC fail in the same session? - Audio tracks and DataChannels actually use separate transports. So, if the DataChannel (which handles RPC) runs into issues during initialization, it won’t impact the audio streaming. Sometimes, DataChannel initialization can fail quietly because of network conditions or configuration quirks. Keeping an eye on the
readyState
of the DataChannel can help spot these silent failures. 2. Are there known issues with RPC through Expo tunnel that don't affect audio? - There aren’t any well-known issues specifically affecting RPC over the Expo tunnel. That said, Expo’s tunnel mode might introduce some latency or connectivity hiccups that could mess with RPC calls. Audio streaming tends to be more resilient here since it uses a different transport. 3. Is there a specific order of operations or timing requirement for RPC registration? - Yes! RPC methods should be registered only after the session has started and the local participant is fully initialized. Make sure you call the agent’s
local_participant.register_rpc_method
after
session.start()
has finished. 4. Could DataChannel initialization be failing silently while audio tracks work normally? - Absolutely, this can happen. DataChannel might fail to initialize without any obvious errors, while audio keeps flowing smoothly. To troubleshoot, watch the
readyState
of the DataChannel — if it’s anything other than
open
, the channel hasn’t initialized properly. ### Debugging Suggestions: - Turn on verbose logging (
LIVEKIT_EVALS_VERBOSE=1
) and check that your agent logs show DataChannel state changes. - Double-check that your client and agent SDK versions and configurations match up. - Try running RPC outside of Expo tunnel mode to see if the tunnel is causing the problem. Feel free to reach out if you want to dive deeper or need more help with debugging! Sources: packages/livekit-rtc/README.md | livekit-android-test/src/test/java/io/livekit/android/rpc/RpcMockE2ETest.kt | android/src/main/java/io/livekit/reactnative/expo/LiveKitApplicationLifecyc... | package-lock.json | Bringing AI avatars to voice agents