fast-van-52630
12/02/2025, 7:40 PMtall-airline-16756
12/02/2025, 7:40 PMtall-airline-16756
12/02/2025, 7:41 PMload_threshold or adjust load_fnc to allow more concurrent jobs per agent if CPU/memory permits.
• Add short-term scaling headroom (extra servers) to handle bursts and observe if join latency improves.
• Instrument and collect metrics (dispatch latency, agent accept time, API response times) to correlate where the wait occurs.
• If dispatch API is a bottleneck, spread dispatch calls slightly (backoff) or parallelize dispatch endpoints.
If you share:
• agent server load_threshold and load_fnc settings,
• whether autoscaling is used and scale policy,
• a short snippet of dispatch error logs or latency numbers,
I can recommend precise config changes and the next diagnostic commands to run.
Sources: SIP dispatch rule | LiveKit docs | Agent dispatch | LiveKit docs | Agents telephony integration | LiveKit docs | Deploying to custom environments | LiveKit Docs | Introducing LiveKit Inference: A unified model interface for voice AIfast-van-52630
12/02/2025, 7:43 PMdef compute_load(worker: Worker) -> float:
return min(len(worker.active_jobs) / 25, 1.0)
if name == "__main__":
cli.run_app(WorkerOptions(
entrypoint_fnc=entrypoint,
prewarm_fnc=prewarm_process,
load_fnc=compute_load,
agent_name="xyz-outbound-agent",
load_threshold=0.8,
shutdown_process_timeout=5
))tall-airline-16756
12/02/2025, 7:44 PMdef compute_load(worker: Worker) -> float:
return min(len(worker.active_jobs) / 50, 1.0)
# and
load_threshold=0.9
This yields ~45 jobs/server → 120 × 45 = 5400 capacity.
1. Use actual resource metrics in load calculation
• Combine job count with CPU/memory so availability reflects real load:
import psutil
def compute_load(worker: Worker) -> float:
job_load = len(worker.active_jobs) / 50
cpu = psutil.cpu_percent() / 100.0
mem = psutil.virtual_memory().percent / 100.0
return min(max(job_load, cpu, mem), 1.0)
1. Add autoscaling headroom
• Scale up sooner (trigger at ~60% average load) and keep a 20–30% buffer so bursts don’t exhaust capacity.
1. Prewarm workers and avoid cold starts
• Ensure prewarm_fnc readies models/sessions and keep idle processes running during expected peaks.
1. Increase shutdown grace
• Raise shutdown_process_timeout from 5s to something longer (e.g., 120s) so active calls aren’t cut during drains/updates.
Quick diagnostics to confirm root cause
• During a spike, report: avg len(worker.active_jobs) per server, CPU/memory %, and dispatch API latency/errors.
• Check agent registration/connect/disconnect rates and any 429/5xx on dispatch calls.
• Verify whether job distribution is even across agents.
If you want, share the above runtime numbers (active_jobs avg, CPU%, dispatch latency) and I’ll recommend exact divisor/threshold values and autoscaling triggers for your fleet.
Sources: Agent server options | LiveKit docs | Deploying to custom environments | LiveKit Docs | Agent server | LiveKit docs | Deploy and scale agents on LiveKit Cloud | Deploy and scale agents on LiveKit Cloudfast-van-52630
12/02/2025, 7:46 PMtall-airline-16756
12/02/2025, 7:46 PMlen(worker.active_jobs)
• dispatch API latency histogram and error rates (timeouts, 429, 5xx)
• agent process start time (prewarm vs cold start latency)
• agent connect/disconnect rates
1. Short-term tweaks to reduce join latency
• Ensure prewarm_fnc keeps idle processes ready for immediate join.
• Confirm agents aren’t frequently restarting (check connect/disconnect).
• If you see transient spikes in dispatch latency, add a small buffer or short delay/backoff on SIP->dispatch calls to smooth bursts.
• If distribution is uneven, verify round-robin dispatch and ensure all agents register with the same agent_name and capabilities.
1. If you see cold-start or burst queuing, increase concurrency per agent temporarily
• If CPU/memory allow, raise divisor to 50 or raise load_threshold (e.g., 0.9) to reduce queuing for simultaneous picked-up calls.
1. Keep shutdown_process_timeout > 120s for voice sessions so drains don’t reduce available capacity.
Two quick clarifying questions
1. During peak periods, what is the measured peak concurrent picked-up jobs and the per-agent avg/p95 active_jobs?
2. Do picked-up calls arrive in tight bursts (many at once) or spread over time?
Share those numbers and I’ll recommend exact compute_load divisor, load_threshold, and autoscaling triggers to eliminate the join delays.fast-van-52630
12/02/2025, 7:50 PMtall-airline-16756
12/02/2025, 7:50 PMfast-van-52630
12/03/2025, 3:25 AMtall-airline-16756
12/03/2025, 3:26 AMlk agent list
• Detailed status (replicas/instances) for an agent:
lk agent status --id <agent_id>
2) Infer active vs idle via sessions (Analytics API)
• List active sessions (counts show current agent activity):
curl -H "Authorization: Bearer $TOKEN" \
"https://cloud-api.livekit.io/api/project/$PROJECT_ID/sessions?limit=100"
• Compare active session count to agent replicas to estimate idle capacity.
3) Self-hosted / programmatic: expose metrics
• Enable Prometheus metrics on agents (set prometheus_port) and export metrics like active jobs per worker.
• Track:
◦ active_jobs (per worker)
◦ agent registration/connect counts
◦ dispatch API latencies/errors
• Idle workers ≈ registered replicas − sum(active_jobs > 0); use a threshold for "idle" (e.g., active_jobs == 0).
4) Practical approach to compute idle count
• Registered workers: from lk agent list / agent status.
• Active workers: count workers where len(active_jobs) > 0 from metrics or session list.
• Idle workers = registered − active.
If you tell me whether you use the LiveKit CLI, Analytics API, or Prometheus, I’ll give the exact commands/metric names and a short script to compute registered vs idle automatically.
Sources: Agent deployment CLI reference | LiveKit docs | Analytics API | LiveKit docs | Deploying to custom environments | LiveKit Docs | Self-hosting the Ingress Service | LiveKit docs | Self-hosting the Egress Service | LiveKit docsfast-van-52630
12/03/2025, 3:34 AMtall-airline-16756
12/03/2025, 3:37 AMagent-AJ_2yLMV3xWYwJ9) at the same time — connect/disconnect, accept/reject, errors, process start times. 3) Dispatch API metrics — latency, 429s, 5xx during the event. 4) Server resource state at the time — CPU%, memory%, open file descriptors, goroutine counts. 5) Network checks — packet loss/RTT between SIP ⇄ LiveKit ⇄ agent. 6) Is the agent process in draining state or recently restarted? What is shutdown_process_timeout?
Quick immediate actions you can try
• Restart the specific agent process and watch for successful registration and acceptance of a test job.
• If agent logs show it’s refusing jobs due to load, temporarily increase per-agent capacity (divisor) or raise load_threshold.
• Increase shutdown_process_timeout (e.g., 120s) if it's currently low (5s).
• If dispatch latency or 5xx/429s appear, add short smoothing/backoff when SIP triggers dispatch bursts.
Send the requested logs/metrics (or paste excerpts) and I’ll point to the exact config changes or deeper traces to fix the restart failure.
Sources: client-sdk-js | livekit/livekit_composite | DeepWiki | Agents (Python) | livekit/livekit_composite | DeepWiki | Understanding "silence detected on local audio track" warning | Understanding the STATE_MISMATCH Disconnect Reason | Deploying to custom environments | LiveKit Docs