damp-toothbrush-11775
11/18/2025, 5:04 PMtall-airline-16756
11/18/2025, 5:04 PMtall-airline-16756
11/18/2025, 5:05 PMasyncio. For example, asyncio.gather() allows you to process multiple calls in parallel, and you can use a semaphore to control how many calls run concurrently, keeping things efficient.
• Multiple Campaigns: Each campaign can operate its own batch of concurrent calls. So, Campaign A might handle 10 calls while Campaign B manages 5, all running side by side without any hiccups.
• Agent Sessions: Every outbound call is treated as its own agent session. This way, each call is managed independently within the LiveKit system, giving you clear control.
• Recommended Architecture: Here’s a solid approach to consider:
1. Run a single worker using asyncio to juggle multiple calls at once.
2. Scale up horizontally by adding more worker replicas to boost your system’s capacity.
3. Set up an outbound-call scheduler or queue to organize call distribution and handle retries smoothly.
If you'd like, I’m happy to walk you through detailed implementation examples or dive deeper into any of these areas. Just let me know how I can assist you further!
Sources: telephony/survey_caller/make_survey_calls.py | Troubleshooting Guide | livekit/livekit_composite | DeepWikidamp-toothbrush-11775
11/19/2025, 8:08 AMtall-airline-16756
11/19/2025, 8:09 AMasyncio and Semaphores: To keep everything running nicely without overload, we use asyncio.Semaphore to limit how many calls happen at once. Here’s a simple example to guide you:
semaphore = asyncio.Semaphore(10) # Limit to 10 concurrent calls
async def controlled_make_call(phone_number, metadata):
async with semaphore:
return await make_call(phone_number, metadata)
async def process_calls_concurrently(call_list):
tasks = [controlled_make_call(item['phone_number'], item['metadata']) for item in call_list]
await asyncio.gather(*tasks)
• Creating Agent Sessions: Every outbound call gets its own agent session. You can use create_dispatch to set up the session and create_sip_participant to connect the call seamlessly. Here’s how:
dispatch = await lkapi.agent_dispatch.create_dispatch(
api.CreateAgentDispatchRequest(
agent_name="voice-agent",
room=room_name,
metadata=json.dumps(metadata)
)
)
sip_participant = await lkapi.sip.create_sip_participant(
api.CreateSIPParticipantRequest(
room_name=room_name,
sip_trunk_id="your_trunk_id",
sip_call_to=phone_number,
participant_identity=f"user_{phone_number}"
)
)
• Running Multiple Campaigns: Keep your campaigns nicely organized by assigning unique identifiers and metadata. This way, each campaign can run its own set of concurrent calls, managed either by a shared or separate worker process.
• Scaling Workers: Start simple with one worker managing multiple calls using asyncio. When you need more power, you can easily scale horizontally by running multiple worker replicas, each handling different campaign subsets.
• Full Workflow Example: To give you a clearer picture, here’s a sample architecture you might find helpful:
1. Scheduler: Fetch unprocessed numbers from PostgreSQL.
2. Outbound Call: Launch calls using asyncio and LiveKit’s API.
3. Call Status: Keep track of call progress and update your database once calls finish.
4. Callback: Dispatch new calls as previous ones wrap up.
async def main():
calls = fetch_calls_from_db()
async with ConcurrentOutboundCaller(max_concurrent=10) as caller:
results = await caller.make_concurrent_calls(calls)
update_call_status_in_db(results)
If you’d like, I’m here to help with more details or walk you through any specific part of this implementation. Just let me know!
Sources: Making outbound calls | LiveKit docs | README.md | telephony/survey_caller/make_survey_calls.py | livekit-plugins/livekit-plugins-ultravox/livekit/plugins/ultravox/realtime/... | App templates | LiveKit docs