fix(CF-1170): Fix STT by correcting agent dispatch flow
Three fixes for voice agent not responding to speech: 1. Agent name: add --agent-name matrix-ai to CLI (was empty, dispatch couldnt match) 2. Move dispatch from on_invite to on_unknown call handler (dispatch when call starts, not on room join) 3. Use LiveKit room name from foci_preferred instead of raw Matrix room ID Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
36
bot.py
36
bot.py
@@ -97,22 +97,9 @@ class Bot:
|
|||||||
async def on_invite(self, room, event: InviteMemberEvent):
|
async def on_invite(self, room, event: InviteMemberEvent):
|
||||||
if event.state_key != BOT_USER:
|
if event.state_key != BOT_USER:
|
||||||
return
|
return
|
||||||
logger.info("Invited to %s", room.room_id)
|
logger.info("Invited to %s, joining room", room.room_id)
|
||||||
await self.client.join(room.room_id)
|
await self.client.join(room.room_id)
|
||||||
|
|
||||||
lk_room_name = room.room_id
|
|
||||||
try:
|
|
||||||
await self.lkapi.agent_dispatch.create_dispatch(
|
|
||||||
api.CreateAgentDispatchRequest(
|
|
||||||
agent_name=AGENT_NAME,
|
|
||||||
room=lk_room_name,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self.dispatched_rooms.add(room.room_id)
|
|
||||||
logger.info("Agent dispatched to %s", lk_room_name)
|
|
||||||
except Exception:
|
|
||||||
logger.exception("Dispatch failed for %s", room.room_id)
|
|
||||||
|
|
||||||
async def on_sync(self, response: SyncResponse):
|
async def on_sync(self, response: SyncResponse):
|
||||||
"""After each sync, trust all devices in our rooms."""
|
"""After each sync, trust all devices in our rooms."""
|
||||||
for user_id in list(self.client.device_store.users):
|
for user_id in list(self.client.device_store.users):
|
||||||
@@ -145,6 +132,27 @@ class Bot:
|
|||||||
"livekit_alias": room_id,
|
"livekit_alias": room_id,
|
||||||
}])
|
}])
|
||||||
|
|
||||||
|
# Extract LiveKit room name from foci and dispatch agent
|
||||||
|
lk_room_name = room_id # fallback
|
||||||
|
for f in foci:
|
||||||
|
if f.get("type") == "livekit" and f.get("livekit_alias"):
|
||||||
|
lk_room_name = f["livekit_alias"]
|
||||||
|
break
|
||||||
|
logger.info("LiveKit room name: %s (from foci_preferred)", lk_room_name)
|
||||||
|
|
||||||
|
if room_id not in self.dispatched_rooms:
|
||||||
|
try:
|
||||||
|
await self.lkapi.agent_dispatch.create_dispatch(
|
||||||
|
api.CreateAgentDispatchRequest(
|
||||||
|
agent_name=AGENT_NAME,
|
||||||
|
room=lk_room_name,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.dispatched_rooms.add(room_id)
|
||||||
|
logger.info("Agent dispatched to LiveKit room %s", lk_room_name)
|
||||||
|
except Exception:
|
||||||
|
logger.exception("Dispatch failed for %s", lk_room_name)
|
||||||
|
|
||||||
# Send our own call member state event
|
# Send our own call member state event
|
||||||
call_content = {
|
call_content = {
|
||||||
"application": "m.call",
|
"application": "m.call",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
services:
|
services:
|
||||||
agent:
|
agent:
|
||||||
build: .
|
build: .
|
||||||
command: python agent.py start
|
command: python agent.py start --agent-name matrix-ai
|
||||||
env_file: .env
|
env_file: .env
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
network_mode: host
|
network_mode: host
|
||||||
|
|||||||
Reference in New Issue
Block a user