dispatch = await lkapi.agent_dispatch.create_dispa...
# ask-ai
t
dispatch = await lkapi.agent_dispatch.create_dispatch( api.CreateAgentDispatchRequest( agent_name=agent_name, room=room_name, metadata=json.dumps(metadata, ensure_ascii=False) ) ) lkapi.agent_dispatch.create_dispatch 를하면 방이 생성이 되는게 아니야?
t
Thanks for reaching out, 유용현. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
맞습니다 — `lkapi.agent_dispatch.create_dispatch`를 호출하면 지정한 방(room)이 아직 존재하지 않을 때 자동으로 새 방이 생성됩니다. 요점: • `create_dispatch`는 에이전트를 방에 할당하는 API입니다. • 지정한 `room`이 없으면 호출 시 해당 방이 자동으로 생성됩니다. 원하시면 호출 예시나 호출 후 방 생성 여부를 확인하는 방법(예: 방 목록 조회 또는 생성 시 반환값 확인)에 대해 추가로 안내해드릴게요. Sources: Agent dispatch | LiveKit docs
t
lk room list 를 해도 안보이던데
t
알겠습니다 — `lk room list`에 방이 보이지 않는 문제에 대해 답변드릴게요. 요점: `create_dispatch`로 방이 생성될 수는 있지만, 방이 비어 있거나 Agent만 잠깐 들어왔다 나가면 LiveKit의 빈방 타임아웃 때문에 곧 사라져 `lk room list`에 표시되지 않을 수 있습니다. 빠르게 확인해볼 것들: • `lk room participants list <room_name>`로 해당 방의 참여자(Agent가 접속했는지)를 확인해 보시겠어요? • 방이 생성 직후 곧 삭제될 수 있으니,
create_dispatch
호출 직후에 바로 `lk room list`나 participants 조회를 실행해 보세요. • 테스트용으로 더미 클라이언트(간단한 참가자)를 방에 접속시켜 방이 유지되는지 확인해 보세요. • CLI가 올바른 프로젝트/인증 정보를 가리키는지 확인(
--api-key
,
--api-secret
,
--url
또는 환경변수/ livekit.toml 설정). 원하시면 사용하신
create_dispatch
호출 코드와(또는 Agent 로그) 공유해 주세요. 바로 보고 어떤 원인인지 더 정확히 진단해 드리겠습니다. Sources: Agent dispatch | LiveKit docs | Connecting to LiveKit | LiveKit docs | Analytics API | LiveKit docs | Managing rooms | LiveKit docs
t
async def make_survey_call(item): """Create a dispatch and add a SIP participant to call the phone number with survey question""" # Create a unique room name for each call using the prefix and row index room_name = f"{room_name_prefix}{item["tel"]}" metadata = item metadata["room_name"] = room_name metadata["call_id"] = "C-" + str(uuid.uuid4()) metadata["cbt_state"] = "call" lkapi = api.LiveKitAPI() logger.info(f"Creating dispatch for agent {agent_name} in room {room_name}") dispatch = await lkapi.agent_dispatch.create_dispatch( api.CreateAgentDispatchRequest( agent_name=agent_name, room=room_name, metadata=json.dumps(metadata, ensure_ascii=False) ) ) print(f"Created dispatch: {dispatch}") print(f"Dialing {item['tel']} to room {room_name}") # 여기에 5초 대기를 추가합니다. print("Waiting 5 seconds before dialing...") await asyncio.sleep(5) logger.info(f"Created dispatch: {dispatch}") logger.info(f"Dialing {item['tel']} to room {room_name}") sip_participant = await lkapi.sip.create_sip_participant( api.CreateSIPParticipantRequest( room_name=room_name, sip_trunk_id=outbound_trunk_id, sip_call_to=convert_to_international_format(item['tel']), participant_identity="phone_user", ) ) logger.info(f"Created SIP participant: {sip_participant}") await lkapi.aclose() return True 디스페치를 한 후에 agent가 방에 들어간거 확인후에 sip 참여자를 참여시키려고하거든?
t
맞습니다 — 의도는 올바릅니다.
create_dispatch
호출 직후 `sleep(5)`로 기다리는 것은 불안정합니다. 에이전트가 실제로 방에 들어갔는지 확인한 후 SIP 참여자를 추가하는 두 가지 신뢰 가능한 방법을 권합니다. 1) 폴링으로 확인 (간단하고 서버사이드에서 바로 사용 가능) • `room.list_participants`로 주기적으로 참여자 목록을 조회해 에이전트의 `identity`(또는
kind == "AGENT"
)가 보이면 다음 단계로 진행합니다. • 타임아웃을 두어 무한 대기를 방지하세요. 예시 흐름: 1.
create_dispatch
2. 반복해서
lkapi.room.list_participants(api.ListParticipantsRequest(room=room_name))
3. 에이전트 확인 →
create_sip_participant
4. 타임아웃 시 실패 처리 및 로깅 2) 이벤트 기반(권장, 확장성 좋음) • LiveKit의
participant_joined
웹훅을 받아 에이전트가 합류했을 때 SIP 호출을 트리거합니다. • 폴링을 피하고 실시간으로 동작합니다. 웹훅 엔드포인트가 필요합니다. 다음 정보를 알려주시면 바로 적용 가능한 코드 예시(폴링 또는 웹훅 처리)를 드리겠습니다: • 에이전트의 실제
identity
값 또는 에이전트가 사용하는 식별자 • 폴링 허용 최대 대기 시간(초) 또는 웹훅 사용 가능 여부 원하시면 지금 사용하신 코드에
wait_for_agent_in_room
같은 폴링 함수 통합 예시를 바로 제공해 드릴게요. Sources: Webhooks | LiveKit docs | livekit/livekit_composite | DeepWiki | Managing participants | LiveKit docs
t
wait_for_agent_in_room
이런 함수가 실제 있는거야?
t
`wait_for_agent_in_room`은 LiveKit의 내장 함수가 아니라 고객님이 직접 구현해야 하는 커스텀 헬퍼입니다. 짧게 요약: • LiveKit에 해당 이름의 빌트인 함수는 없습니다. • 동일한 동작은 서버 API로 `room.list_participants`를 주기적으로 호출해 에이전트가 참가했는지 확인하는 방식으로 구현할 수 있습니다. • 또는 웹훅의
participant_joined
이벤트를 사용해 이벤트 기반으로 처리할 수 있습니다. 원하시면 바로 사용 가능한 폴링 기반의
wait_for_agent_in_room
예시 코드를 제공해드릴게요. 폴링 타임아웃(초) 값을 알려주세요.
t
sleep이 이상하 다는거지???
t
네 — 요약하면 맞습니다: `sleep`으로 고정 대기하는 것은 불안정합니다. 왜 그렇냐면: • 에이전트가 방에 들어오는 시간은 네트워크/서버 상황에 따라 달라집니다. 고정된 5초가 항상 충분하지 않을 수 있고, 반대로 불필요하게 오래 기다릴 수도 있습니다. • 고정 지연은 레이스 컨디션(에이전트가 아직 연결되기 전 SIP 호출 시작)을 완전히 방지하지 못합니다. 대신 권장 방법 (둘 중 하나 선택): • 폴링: `room.list_participants`를 주기적으로 호출해서 에이전트(identity 또는 kind == "AGENT")가 보이면 SIP 호출 실행. 타임아웃을 두세요. • 이벤트 기반(더 권장): LiveKit 웹훅의
participant_joined
이벤트를 받아 에이전트가 합류할 때 SIP 호출 트리거. 원하시면 지금 바로 사용할 수 있는 폴링 기반
wait_for_agent_in_room
구현 예시(타임아웃 포함) 또는 웹훅 처리 예시를 제공해 드릴게요. 어느 쪽을 원하시나요?
t
둘다 줘봐
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!
t
원하시면 지금 바로 사용할 수 있는 폴링 기반
wait_for_agent_in_room
구현 예시(타임아웃 포함) 또는 웹훅 처리 예시를 제공해 드릴게요. 어느 쪽을 원하시나요? 두가지 방법 다줘봐
wait_for_agent_in_room
예시를 줘봐