Hey Innovators , I have a few questions regarding ...
# ask-ai
c
Hey Innovators , I have a few questions regarding LiveKit: 1. Does it support building dynamic scripts through a UI? 2. Can we handle parameters dynamically for example, selecting which model to use or passing custom values at runtime? 3. Most importantly, is it possible to implement outbound call automation such as: ◦ Automatically calling numbers fetched from my database. ◦ Using lead qualification logic to assess call outcomes. ◦ Updating the database to mark leads as qualified or not qualified based on the results.
t
Thanks for reaching out, Uzair. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thank you for reaching out with your questions about LiveKit! I’m happy to walk you through the details: 1. Dynamic Scripts through a UI: While LiveKit doesn’t come with a built-in visual or no-code UI builder for creating dynamic scripts, it does offer great flexibility. You can build your own custom UIs using its frontend SDKs and declarative components. For instance, you could design a teleprompter-like interface with editable text areas that update in real time. It’s a powerful way to tailor the experience to your needs! 2. Dynamic Parameters: LiveKit is designed to handle dynamic parameters smoothly. This means you can select models or pass custom values during runtime—things like model selection, temperature, and custom prompts can all be adjusted on the fly. This makes your workflows flexible and adaptable, which is fantastic for many use cases. 3. Outbound Call Automation: LiveKit supports outbound call automation with some really useful features, including:If you’d like a practical example, you can check out the Outbound Caller Python Example—it’s a great resource to see everything in action. ◦ Calling numbers pulled directly from a database using SIP trunk integration. ◦ Qualifying leads through AI-driven conversations and tool calls. ◦ Updating your databases after calls via custom code or external integrations. Please feel free to reach out if you want more details or need a hand with implementation. I’m here to help! Sources: Chrome Developer Extension | livekit/livekit_composite | DeepWiki | Handling events | LiveKit docs | LiveKit SDKs Overview | LiveKit Docs | complex-agents/teleprompter/teleprompter-frontend/components/teleprompter.t... | Tool definition and use | LiveKit docs
c
Hi, I want to use ViciDial to qualify leads, and my main requirement is to have a highly intelligent bot. For this, I need multi-agent support. Does LiveKit allow that, and can I integrate my knowledge base to enable smoother conversations? Additionally, I have a few specific questions: 1. Barge-in functionality: Is it possible to stop TTS when the user starts speaking while the response is still being generated? 2. State management: If we have a detailed, multi-step script that AI cannot fully remember, is there a mechanism to manage parameters, such as lead qualification criteria, and update them in real-time to ensure all information is captured?
t
Thank you for reaching out with your questions about LiveKit's capabilities! I'm happy to walk you through the details: 1. Multi-Agent Support and Knowledge Base Integration: LiveKit is designed to support multi-agent systems where specialized agents can seamlessly collaborate and transfer conversations without losing context. Plus, it integrates smoothly with external knowledge bases using Retrieval-Augmented Generation (RAG) and tools like LlamaIndex, so agents can access helpful information right when they need it during conversations. 2. Barge-in Functionality: LiveKit also supports barge-in functionality, which means the Text-to-Speech (TTS) will pause as soon as the user starts speaking. This happens through automatic interruption detection using Voice Activity Detection (VAD) or interim speech-to-text transcripts. Developers even have the option to trigger interruptions programmatically if necessary. 3. State Management and Real-Time Parameter Updates: For managing complex workflows, LiveKit offers strong state management with persistent data containers (like UserData) and distributed state synchronization. This lets you update parameters—such as lead qualification criteria—in real-time during execution, so your workflows stay flexible and capture all the important info. Please feel free to reach out if you'd like more details or need any help with implementation. I'm here to support you every step of the way! Sources: README.md | LiveKit Docs | complex-agents/medical_office_triage/README.md | Agent Session & Client Integration | livekit/livekit_composite | DeepWiki | Tool definition and use | LiveKit docs
c
Can I implement this type of multi-agent architecture in LiveKit, or is it recommended to do so? I previously built a custom two-agent state manager (FastAPI + Redis) because the LLM could not reliably track steps — it would forget the current step, skip parts of the script, get confused by unexpected answers, and loop when extracted values didn’t match the expected format. My backend state machine fixed this, but the extraction/validation logic is still hardcoded and varies across campaigns. I want to move to a more intelligent two-agent system: Agent 1 – Conversational LLM • Handles messy or unexpected answers • Re-asks questions • Follows script steps Agent 2 – Decision + Validation LLM • Reads conversation history and lead state • Determines next step • Validates user input • Applies hangup/transfer rules • Fills structured lead fields (JSON) Before I fully implement this myself, I want to know what LiveKit already supports. Questions for the LiveKit team: 1. Agentic tool-calling ◦ Does LiveKit support function/tool calling with argument validation, tool-result feedback, and schema-consistent JSON outputs, similar to agentic AI / OpenAI function calling? 2. Custom tools ◦ Can I register my own tools (e.g.,
validate_phone
,
update_lead_state
,
advance_step
)? 3. Built-in state tracking ◦ Does LiveKit provide per-session memory, step indexing, script progression, or key/value state storage, or is external state management always required? 4. Dynamic schemas ◦ Can LiveKit accept a dynamic JSON schema (fields, steps, rules) per outreach and enforce it during extraction? 5. Validation loops ◦ Does LiveKit include built-in validation, retry logic, and protection from infinite loops, or should this remain in my backend? Summary: My custom state manager works, but extraction and step validation are fragile and campaign-specific. Before I finish building a full two-agent system, I want to know which parts LiveKit already provides: tool calling, custom tools, state management, schema enforcement, step tracking, validation, and action dispatch (hangup/transfer).
t
Thank you for your questions about LiveKit's capabilities for building a two-agent system! I’m happy to walk you through the details: 1. Agentic Tool-Calling: LiveKit supports function and tool calling with argument validation, tool-result feedback, and schema-consistent JSON outputs. It uses strict JSON schema validation and provides structured outputs, much like OpenAI's function calling. This helps keep everything clear and reliable. 2. Custom Tools: You have the flexibility to register custom tools such as
validate_phone
,
update_lead_state
, or
advance_step
. These tools can be defined programmatically, added dynamically at runtime, or even forwarded to the frontend through RPC for execution. This allows you to tailor the system exactly to your needs. 3. Built-in State Tracking: LiveKit offers per-session memory, step indexing, script progression, and key/value state storage using participant attributes, room metadata, and agent-specific state management patterns. These features are designed to support multi-step workflows and keep state persistent across interactions, making your processes smoother. 4. Dynamic Schemas: LiveKit can handle dynamic JSON schemas for fields, steps, and rules per outreach. It enforces these schemas during extraction with strict validation and grammar-based constraints, ensuring outputs always match the defined structure. This helps maintain consistency and accuracy. 5. Validation Loops: LiveKit includes retry logic for webhooks and API calls, though it doesn’t have built-in infinite loop protection. For advanced validation, retry limits, and loop prevention, it’s best to implement these safeguards in your backend. I’m here if you want guidance on how to set that up! Overall, LiveKit offers robust support for multi-agent architectures, customizable tools, and dynamic workflows. Please don’t hesitate to reach out if you’d like help with specific implementation details or code examples—I’m here to support you every step of the way! Sources: Tool definition and use | LiveKit docs | Tool definition and use | LiveKit docs | common/chat.cpp | agents/src/voice/generation.ts | examples/voice_agents/README.md
c
I saw this example repository: LiveKit Outbound Caller Python With the pre-configured setup provided, am I able to make outbound calls either from my bot to a client or to a testing number?
t
Absolutely! The LiveKit Outbound Caller Python example is designed to help you make outbound calls to clients or testing numbers with ease. It leverages the
CreateSIPParticipant
API to place calls through a configured outbound SIP trunk. You can start calls by dispatching the agent with a specific phone number using the
lk
CLI command like this:
Copy code
lk dispatch create \
  --new-room \
  --agent-name outbound-caller \
  --metadata '{"phone_number": "+1234567890", "transfer_to": "+9876543210"}'
To make sure everything runs smoothly, please check that: • You have an outbound SIP trunk properly configured. • The
SIP_OUTBOUND_TRUNK_ID
is set up in your environment configuration. • Important environment variables such as
LIVEKIT_URL
,
LIVEKIT_API_KEY
, and
LIVEKIT_API_SECRET
are correctly defined. Also, this example supports STT, LLM, and TTS models for interactive voice responses, which can be really handy. If you'd like, I’m here to help you with setting up the environment or configuring the SIP trunk—just let me know! Sources: requirements.txt | Agents telephony integration | LiveKit docs | Agents telephony integration | LiveKit Docs | Create and configure a Plivo SIP trunk | LiveKit docs
c
or can i am able to make automation to do this on required or given numbers?
t
Absolutely, LiveKit can help you automate outbound calls to a list of numbers you provide. By using the
CreateSIPParticipant
API, you can easily initiate calls programmatically. For instance, you might loop through a list of numbers (like from a CSV file) and trigger calls dynamically like this:
Copy code
await lkapi.sip.create_sip_participant(
    api.CreateSIPParticipantRequest(
        room_name="call-room-1",
        sip_trunk_id="ST_xxxx",  # From trunk creation
        sip_call_to="+15105550100",  # Recipient number
        participant_identity="caller1"
    )
)
To get this automation up and running, here’s what you’d typically do: • Set up an outbound SIP trunk with your provider (such as Twilio or Plivo). • Make sure to configure the
SIP_OUTBOUND_TRUNK_ID
in your environment settings. • Write a script to go through your list of numbers and start calls programmatically. Plus, you can combine this with LiveKit's AI Agents framework to create dynamic call interactions, which is pretty exciting! If you’d like, I’m here to help you with setting up the automation or configuring your SIP trunk—just let me know! Sources: livekit/livekit_sip.pb.go | Agents telephony integration | LiveKit docs | README.md | packages/sip--make-a-call/README.md | test/lktest-sip-outbound/README.md
c
where from i will got these LIVEKIT_URL=<your LiveKit server URL> LIVEKIT_API_KEY=<your API Key>
t
To help you get your
LIVEKIT_URL
,
LIVEKIT_API_KEY
, and
LIVEKIT_API_SECRET
, here’s a simple step-by-step guide: 1. Sign up or log in to LiveKit Cloud: Head over to LiveKit Cloud and log in to your account. 2. Create a project: Once you’re logged in, go ahead and create a new project to set up your workspace. 3. Generate API Key and Secret: Navigate to your project’s Settings page, where you’ll find the option to generate your
LIVEKIT_API_KEY
and
LIVEKIT_API_SECRET
. 4. Find your LiveKit URL: ◦ If you’re using LiveKit Cloud, your
LIVEKIT_URL
will look like this:
wss://<subdomain>.livekit.cloud
. You can find the subdomain right at the top of your project dashboard. ◦ If you’re self-hosting, just use the URL of your LiveKit server. 1. Configure environment variables: Pop these values into an environment file (like
.env.local
):
Copy code
LIVEKIT_API_KEY=your_api_key
LIVEKIT_API_SECRET=your_api_secret
LIVEKIT_URL=wss://your-subdomain.livekit.cloud
If you have any questions or need a hand with any part of this setup, just let me know—I’m here to help! Sources: .env.example | Mini tutorial: setting up a LiveKit Cloud project | .env.example | examples/rpc/README.md
c
where from i will get it SIP_OUTBOUND_TRUNK_ID=<your SIP outbound trunk ID>
t
To help you find the
SIP_OUTBOUND_TRUNK_ID
, here are some simple steps you can follow: 1. Using the LiveKit CLI: Just run this command to see all your outbound SIP trunks:
lk sip outbound list
2. Through the LiveKit Cloud Dashboard: ◦ Log in to your LiveKit Cloud dashboard. ◦ Head over to Telephony → Configuration. ◦ Under the Outbound section, you’ll find a list of outbound trunks along with their IDs. 1. Using API Endpoints: You can call the
ListSIPOutboundTrunk
API to get all outbound trunks or the
GetSIPOutboundTrunk
API for details on a specific trunk. 2. Programmatically via SDKs: If you prefer coding, methods like
listSipOutboundTrunk()
in the Kotlin SDK or
list_sip_outbound_trunk
in the Ruby SDK will get you the trunk ID. If you’d like, I’m here to walk you through any of these options—just let me know how I can assist! Sources: Agents telephony integration | LiveKit Docs | SIP outbound trunk | LiveKit docs | SIP APIs | LiveKit docs | lib/livekit/sip_service_client.rb | packages/sip--make-a-call/README.md
c
is live kit provide any temp number or i have to purchase Two options: Option 1: Use LiveKit's built-in numbers (if they provide them) • Purchase a number through LiveKit Option 2: Use external provider (Twilio/Telnyx) • Connect your existing Twilio number to LiveKit
t
I'm happy to share that LiveKit offers built-in phone number management, making it easy for you to search for, purchase, and manage phone numbers right from the platform. Here’s how you can get started: • Search for numbers: You can use the LiveKit CLI or API to find available numbers by country code or area code. • Purchase numbers: Easily acquire numbers through LiveKit to use in your voice and SMS applications. • Manage numbers: You have the flexibility to list, update, or release numbers whenever you need. These numbers can be linked with SIP trunks for both inbound and outbound calling. And if you prefer, you’re welcome to connect an external provider like Twilio or Telnyx to use their numbers with LiveKit. Please feel free to reach out if you’d like a hand setting this up—I’m here to help! Sources: phonenumberclient.go | SIP outbound trunk | LiveKit docs | cmd/lk/phone_number.go | livekit/livekit_phone_number.pb.go
c
how can i test it locally i have microsip configured currently i call asterisk server but now i want the other way around
t
Let's walk through testing LiveKit SIP integration locally and setting it up so MicroSIP can receive calls from LiveKit. Here’s a simple step-by-step guide to help you get started: 1. Set up MicroSIP: ◦ First, make sure MicroSIP is running and listening on
127.0.0.1:5060
. ◦ Then, configure an account in MicroSIP with these details: ▪︎ Username:
user
▪︎ Password:
pass
▪︎ Domain:
127.0.0.1
1. *Create an Outbound SIP Trunk in LiveKit:*`{ "outbound_address": "127.0.0.1:5060", "outbound_number": "+1234567890", "outbound_username": "user", "outbound_password": "pass" }` ◦ You can use the LiveKit CLI or API to create a trunk that points to MicroSIP. Here’s an example configuration: 1. *Initiate a Call:*`livekit-cli create-sip-participant \ --room-name "test-room" \ --sip-trunk-id "your-trunk-id" \ --sip-call-to "+1234567890"` ◦ Next, use the
CreateSIPParticipant
API or CLI command to start a call from LiveKit to MicroSIP: Once you do this, MicroSIP should ring, and when you answer, the audio will connect. If you run into any bumps or have questions along the way, please don’t hesitate to reach out—I’m here to help you through it! Sources: Making outbound calls | LiveKit docs | packages/sip--make-a-call/README.md | pkg/sip/outbound.go
c
give me step by step guidence to do this one thing that i clearify i am using liovekit cloud dashboardb
t
I'd love to help you get LiveKit Cloud set up to make outbound SIP calls to MicroSIP. Here’s a simple step-by-step guide to walk you through the process: 1. Set up MicroSIP: ◦ First, open MicroSIP and set up an account with these details: ▪︎ Username:
user
▪︎ Password:
pass
▪︎ Domain:
127.0.0.1
(or your machine’s LAN IP) ▪︎ SIP Port:
5060
◦ Make sure MicroSIP is running and ready to receive calls—the status indicator should be green. 1. Create an Outbound SIP Trunk in LiveKit Cloud: ◦ Log in to your LiveKit Cloud dashboard. ◦ Go to Telephony → Configuration. ◦ Under the Outbound section, create a new SIP trunk using these details: ▪︎ Outbound Address:
127.0.0.1:5060
▪︎ Username:
user
▪︎ Password:
pass
▪︎ Outbound Number:
+1234567890
(you can use any test number here). 1. Initiate a Call: ◦ You can start a call using the LiveKit CLI or API with this command:
Copy code
livekit-cli create-sip-participant \
  --room-name "test-room" \
  --sip-trunk-id "your-trunk-id" \
  --sip-call-to "+1234567890"
◦ Or, if you prefer, use the LiveKit Cloud dashboard to create a new room and add a SIP participant by entering the trunk ID and phone number. 1. Test the Call: ◦ You should see MicroSIP ring when the call comes through. ◦ Simply answer the call in MicroSIP to connect. If you get stuck or want me to walk you through any part of this, just let me know—I’m here to help!
c
sip is on service is unvailable
t
I'm sorry to hear you're encountering the "SIP service is unavailable" error. This usually points to a configuration hiccup or a temporary service downtime. Let's walk through some steps together to get this sorted out: 1. Check SIP Configuration: Please double-check that your SIP trunk is set up with the correct authentication details (username and password) and the right outbound address. Sometimes a small typo can cause issues. 2. Verify Trunk Setup: Take a look in the LiveKit Cloud dashboard under Telephony → Configuration to make sure your outbound trunk is properly created. 3. Region Pinning: If you're using region-specific endpoints, confirm that the format
{sip_subdomain}.{region_name}.sip.livekit.cloud
is correctly configured on your SIP provider’s side. 4. Authentication: Check that your SIP provider allows calls from any IP address (like
0.0.0.0/0
) if credential-based authentication isn’t an option. 5. Retry: Sometimes this error pops up due to temporary unavailability, so trying again after a short wait might do the trick. If you’re still running into trouble after these steps, please don’t hesitate to reach out. I’m here to help you review your SIP configuration in the LiveKit Cloud dashboard or assist you further. We’ll get this working together! Sources: SIP outbound trunk | LiveKit docs | SIP inbound trunk | LiveKit docs | SIP cloud and region pinning | LiveKit docs | livekit/sip.go
c
for complex script i just give directly to llm or put as a context memory and system promp separate ?
t
When working with complex scripts in LiveKit, a great approach is to provide them as a system prompt. This helps the LLM stick to the script reliably without overwhelming its context memory. Here’s a friendly tip: • Place the script inside the system prompt to gently guide the LLM’s behavior and responses. • Try to avoid depending too much on context memory for following the script, as that can sometimes cause inconsistencies. • Make sure to include the script right at the start as part of the system message, rather than adding it dynamically during your session. If you’d like, I’m here to help you craft your system prompt or walk you through setting this up smoothly. Just let me know! Sources: tools/server/server.cpp | Realtime model plugins | LiveKit Docs | delay-handling/README.mdoc | livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti...
c
whaty i need is this You are Zoee, a friendly and professional lead-qualification agent from ABC Medical Insurance. Your goal is to engage callers about Medicare 2026 enrollment and check their eligibility for additional benefits. You have THREE function tools available to you for call handling: check_lead_qualification, avr_transfer, and avr_hangup. --- CALL OPENING --- At the start of every call, greet the caller warmly: Hi, this is Zoee from ABC Medical Insurance. The annual enrollment for Medicare 2026 has started, and I'm calling to check your eligibility for additional benefits like food cards and flex cards. Are you available for a quick 2-minute chat? --- IF CALLER IS NOT AVAILABLE OR BUSY --- • Offer to reschedule • If they agree: ask for the best callback time. After they give a time: - Say goodbye (NEVER say "I am hanging up now") - Then call avr_hangup(reason="not_interested") • If they refuse reschedule: - Say "No problem. If you change your mind, let us know. Goodbye." - Then call avr_hangup(reason="not_interested") --- IF CALLER CHANGES MIND AFTER SAYING BUSY --- • Immediately continue as if they said YES (I change my mind). • Restart from the section "IF CALLER SAYS YES". • DO NOT repeat questions already answered earlier in the call. --- IF CALLER SAYS YES --- Repeat the purpose (The annual enrollment for Medicare 2026 has started, and I'm calling to check your eligibility for additional benefits like food cards and flex cards.) Collect information step-by-step (ONE question at a time): Step 1: Ask for their name - If they refuse to provide name, say "No worries, we can proceed without it." - Store name if provided Step 2: Ask for their age - If they refuse to provide age, say "We respect your privacy, but to check your eligibility for additional benefits, we do need your age." - Store age when provided Step 3: Ask for their location (state or country) - Say: "And where are you located?" or "What state are you calling from?" - If they refuse, say "We need your location to verify eligibility for your area." - Store location when provided Step 4: QUALIFICATION CHECK (MANDATORY) Once you have BOTH age AND location, you MUST call: check_lead_qualification(age=<number>, location="<string>", caller_name="<name or Unknown>") WAIT for the tool response before proceeding. Step 5: Handle Qualification Result A) IF tool returns "QUALIFICATION_SUCCESS": - Say: "Great news! You're eligible for Medicare 2026 benefits." - Continue collecting additional information: • Ask for their address - If they refuse: "We respect your privacy, but to process your benefits, we do need your address." • Ask for number of family members - After collecting all info: - Confirm details - Say: "Great, I'm transferring your call to an agent who will assist you further. Thank you for your time." - Then call avr_transfer(caller_name, caller_age, transfer_extension="1001") B) IF tool returns "QUALIFICATION_FAILED": - Empathetically explain they don't meet the current eligibility requirements - Be specific but kind (e.g., "Unfortunately, this program is currently available for ages 20 to 80" or "This program is currently only available in the US and UK") - Thank them for their time - Say goodbye naturally - Then call avr_hangup(reason="not_qualified") C) IF tool returns "SYSTEM_ERROR": - Say: "I apologize, we're experiencing technical difficulties. Would you like us to call you back?" - Then call avr_hangup(reason="system_error") --- IF CALLER ALREADY HAS BENEFITS --- • Tell them you can help enhance/expand benefits. • Still need to verify eligibility - collect: - name (if not already collected) - age (if not already collected) - location (if not already collected) • Call check_lead_qualification tool • If QUALIFIED: - Ask for address - Ask for household size - Confirm details - Say: "Great, I'm transferring your call to an agent who will assist you further." - Then call avr_transfer(caller_name, caller_age, transfer_extension="1001") • If NOT QUALIFIED: - Follow the QUALIFICATION_FAILED process above --- IMPORTANT: TOOL USAGE RULES --- • DO NOT skip the check_lead_qualification tool • The tool requires BOTH age AND location - collect both before calling • DO NOT ask for address or family members BEFORE qualification is confirmed • NEVER proceed to transfer without successful qualification • If caller provides age and location in the same sentence, you can call the tool immediately • Store all collected information throughout the conversation --- ABSOLUTE RULES --- • Before calling avr_hangup: - ALWAYS say goodbye naturally first - NEVER say "I am hanging up now" • Before calling avr_transfer: - ALWAYS say: "Great, I'm transferring your call now." • If caller is not available, always offer to reschedule • Ask ONE question at a time (unless caller volunteers multiple answers) • Keep responses short, caring, natural, empathetic • ALWAYS use caller's name when known • NEVER repeat any question if answer is already collected • Store and remember all collected fields • WAIT for tool responses before making decisions --- FUNCTION SUMMARY --- check_lead_qualification(age, location, caller_name) - Validates eligibility (age 20-80, US/UK only) avr_hangup(reason) - Ends the call avr_transfer(caller_name, caller_age, transfer_extension) - Transfers to human agent
t
To help you implement this detailed script in LiveKit, you can set it up as a system prompt for the LLM. This way, the agent will consistently follow the flow and rules you’ve outlined. Here’s a friendly step-by-step to guide you: 1. Define the System Prompt: Use your script as the system prompt, including all parts like the call opening, tool usage rules, and absolute rules to steer the LLM’s behavior. 2. Configure Tools: Register the tools (
check_lead_qualification
,
avr_transfer
,
avr_hangup
) in LiveKit. Make sure they’re accessible to the agent and return the expected results. 3. Set Up the Agent: Create an agent in LiveKit and assign the system prompt. Confirm the agent can use the tools and is ready for real-time interactions. 4. Test the Flow: Run some test calls to check that the agent follows the script properly, uses the tools as intended, and gracefully handles situations like system errors or unqualified leads. If you’d like, I’m here to assist you with setting up the system prompt, registering the tools, or configuring the agent in LiveKit. Just let me know!
It looks like the error is happening because the API key you provided for the LLM (like OpenAI or Cerebras) might be incorrect or invalid. No worries—let’s work through this together: 1. Verify API Key: Please take a moment to double-check the API key you’ve set for the LLM in your environment variables or configuration file. Make sure it exactly matches the key given by your LLM provider (such as OpenAI or Cerebras). 2. Set the Correct API Key: If needed, update the environment variable with the right key:`export OPENAI_API_KEY="your_correct_api_key"`or for Cerebras:
export CEREBRAS_API_KEY="your_correct_api_key"
3. Restart the Agent: Once you’ve updated the API key, please restart your LiveKit agent so the changes can take effect. 4. Test the Connection: Try running a quick test to see if the LLM is able to generate completions without any errors. If you’re still running into issues, it might be helpful to check that your API key has the right permissions and is active. Feel free to reach out anytime—I’m here to help you get this sorted!
c
from livekit.agents import Agent, function_tool # from livekit.plugins import openai, cartesia, silero class LeadQualificationAgent(Agent): """Lead qualification agent for Medicare 2026 enrollment""" def __init__(self): llm = openai.LLM.with_cerebras(model="llama-3.3-70b") stt = deepgram.STT() tts = deepgram.TTS() vad = silero.VAD.load() instructions = """ You are Zoee, a friendly and professional lead-qualification agent from ABC Medical Insurance. Your goal is to engage callers about Medicare 2026 enrollment and check their eligibility for additional benefits. You have THREE function tools available to you for call handling: check_lead_qualification, avr_transfer, and avr_hangup. --- CALL OPENING --- At the start of every call, greet the caller warmly: Hi, this is Zoee from ABC Medical Insurance. The annual enrollment for Medicare 2026 has started, and I'm calling to check your eligibility for additional benefits like food cards and flex cards. Are you available for a quick 2-minute chat? --- IF CALLER IS NOT AVAILABLE OR BUSY --- • Offer to reschedule • If they agree: ask for the best callback time. After they give a time: - Say goodbye (NEVER say "I am hanging up now") - Then call avr_hangup(reason="not_interested") • If they refuse reschedule: - Say "No problem. If you change your mind, let us know. Goodbye." - Then call avr_hangup(reason="not_interested") --- IF CALLER CHANGES MIND AFTER SAYING BUSY --- • Immediately continue as if they said YES (I change my mind). • Restart from the section "IF CALLER SAYS YES". • DO NOT repeat questions already answered earlier in the call. --- IF CALLER SAYS YES --- Repeat the purpose (The annual enrollment for Medicare 2026 has started, and I'm calling to check your eligibility for additional benefits like food cards and flex cards.) Collect information step-by-step (ONE question at a time): Step 1: Ask for their name - If they refuse to provide name, say "No worries, we can proceed without it." - Store name if provided Step 2: Ask for their age - If they refuse to provide age, say "We respect your privacy, but to check your eligibility for additional benefits, we do need your age." - Store age when provided Step 3: Ask for their location (state or country) - Say: "And where are you located?" or "What state are you calling from?" - If they refuse, say "We need your location to verify eligibility for your area." - Store location when provided Step 4: QUALIFICATION CHECK (MANDATORY) Once you have BOTH age AND location, you MUST call: check_lead_qualification(age=<number>, location="<string>", caller_name="<name or Unknown>") WAIT for the tool response before proceeding. Step 5: Handle Qualification Result A) IF tool returns "QUALIFICATION_SUCCESS": - Say: "Great news! You're eligible for Medicare 2026 benefits." - Continue collecting additional information: • Ask for their address - If they refuse: "We respect your privacy, but to process your benefits, we do need your address." • Ask for number of family members - After collecting all info: - Confirm details - Say: "Great, I'm transferring your call to an agent who will assist you further. Thank you for your time." - Then call avr_transfer(caller_name, caller_age, transfer_extension="1001") B) IF tool returns "QUALIFICATION_FAILED": - Empathetically explain they don't meet the current eligibility requirements - Be specific but kind (e.g., "Unfortunately, this program is currently available for ages 20 to 80" or "This program is currently only available in the US and UK") - Thank them for their time - Say goodbye naturally - Then call avr_hangup(reason="not_qualified") C) IF tool returns "SYSTEM_ERROR": - Say: "I apologize, we're experiencing technical difficulties. Would you like us to call you back?" - Then call avr_hangup(reason="system_error") --- IF CALLER ALREADY HAS BENEFITS --- • Tell them you can help enhance/expand benefits. • Still need to verify eligibility - collect: - name (if not already collected) - age (if not already collected) - location (if not already collected) • Call check_lead_qualification tool • If QUALIFIED: - Ask for address - Ask for household size - Confirm details - Say: "Great, I'm transferring your call to an agent who will assist you further." - Then call avr_transfer(caller_name, caller_age, transfer_extension="1001") • If NOT QUALIFIED: - Follow the QUALIFICATION_FAILED process above --- IMPORTANT: TOOL USAGE RULES --- • DO NOT skip the check_lead_qualification tool • The tool requires BOTH age AND location - collect both before calling • DO NOT ask for address or family members BEFORE qualification is confirmed • NEVER proceed to transfer without successful qualification • If caller provides age and location in the same sentence, you can call the tool immediately • Store all collected information throughout the conversation --- ABSOLUTE RULES --- • Before calling avr_hangup: - ALWAYS say goodbye naturally first - NEVER say "I am hanging up now" • Before calling avr_transfer: - ALWAYS say: "Great, I'm transferring your call now." • If caller is not available, always offer to reschedule • Ask ONE question at a time (unless caller volunteers multiple answers) • Keep responses short, caring, natural, empathetic • ALWAYS use caller's name when known • NEVER repeat any question if answer is already collected • Store and remember all collected fields • WAIT for tool responses before making decisions --- FUNCTION SUMMARY --- check_lead_qualification(age, location, caller_name) - Validates eligibility (age 20-80, US/UK only) avr_hangup(reason) - Ends the call avr_transfer(caller_name, caller_age, transfer_extension) - Transfers to human agent """ super().__init__( instructions=instructions, stt=stt, llm=llm, tts=tts, vad=vad ) async def on_enter(self): """Called when entering this agent""" print("Current Agent: 🏥 Medicare Lead Qualification Agent 🏥") await self.session.say("Hi, this is Zoee from ABC Medical Insurance. The annual enrollment for Medicare 2026 has started, and I'm calling to check your eligibility for additional benefits like food cards and flex cards. Are you available for a quick 2 minute chat?") @function_tool async def check_lead_qualification(self, age: int, location: str, caller_name: str = "Unknown"): """Validates eligibility for Medicare 2026 benefits Args: age: Caller's age (must be between 20-80) location: Caller's location (must be US or UK) caller_name: Caller's name """ print(f"\n🔍 Checking qualification for {caller_name} (Age: {age}, Location: {location})") # US States list us_states = [ "alabama", "alaska", "arizona", "arkansas", "california", "colorado", "connecticut", "delaware", "florida", "georgia", "hawaii", "idaho", "illinois", "indiana", "iowa", "kansas", "kentucky", "louisiana", "maine", "maryland", "massachusetts", "michigan", "minnesota", "mississippi", "missouri", "montana", "nebraska", "nevada", "new hampshire", "new jersey", "new mexico", "new york", "north carolina", "north dakota", "ohio", "oklahoma", "oregon", "pennsylvania", "rhode island", "south carolina", "south dakota", "tennessee", "texas", "utah", "vermont", "virginia", "washington", "west virginia", "wisconsin", "wyoming" ] # Qualification criteria: age 20-80, US/UK only location_normalized = location.lower().strip() # Check if location is US state or contains US/UK keywords is_valid_location = ( location_normalized in us_states or any(keyword in location_normalized for keyword in ["us", "usa", "united states", "uk", "united kingdom", "america"]) ) is_valid_age = 20 <= age <= 80 if is_valid_age and is_valid_location: print(f"✅ QUALIFIED: {caller_name} meets eligibility criteria") return "QUALIFICATION_SUCCESS" else: reason = [] if not is_valid_age: reason.append(f"age {age} outside range 20-80") if not is_valid_location: reason.append(f"location '{location}' not US/UK") print(f"❌ NOT QUALIFIED: {', '.join(reason)}") return "QUALIFICATION_FAILED" @function_tool async def avr_hangup(self, reason: str): """Ends the call Args: reason: Reason for hanging up (not_interested, not_qualified, system_error) """ print(f"\n📞 HANGUP - Reason: {reason}") print("=" * 50) raise KeyboardInterrupt("Call ended") @function_tool async def avr_transfer(self, caller_name: str, caller_age: int, transfer_extension: str): """Transfers the call to a human agent Args: caller_name: Name of the caller caller_age: Age of the caller transfer_extension: Extension to transfer to """ print(f"\n📞 TRANSFER TO HUMAN AGENT") print(f" Caller: {caller_name} (Age: {caller_age})") print(f" Extension: {transfer_extension}") print("=" * 50) raise KeyboardInterrupt("Call transferred") print("✅ Lead Qualification Agent ready") it stuck in tool what do you recommend to achive this type of lead qualification bot
t
To help you create this lead qualification bot and tackle the issue of the tool getting stuck, here are some friendly recommendations to keep things running smoothly: 1. Debug Tool Execution: Make sure the tools (
check_lead_qualification
,
avr_hangup
,
avr_transfer
) are properly registered and can be called without issues. Adding some logging can really help confirm that the tool is being invoked and returning what you expect. 2. Asynchronous Execution: Double-check that all tools are awaited correctly using
await
. For instance, using
await self.check_lead_qualification(...)
ensures asynchronous calls are handled smoothly. 3. Tool Timeout Handling: It’s a great idea to implement a timeout for tool execution to avoid the system hanging. You might want to try
asyncio.wait_for
to set a max time each tool can run. 4. Test Tool Responses: Try simulating different tool responses so the agent can gracefully manage all possible outcomes like
QUALIFICATION_SUCCESS
,
QUALIFICATION_FAILED
, and
SYSTEM_ERROR
. 5. Validate Tool Logic: Take a moment to review the logic inside
check_lead_qualification
to make sure all edge cases are covered, including invalid inputs or unexpected data. 6. Agent Configuration: Confirm that the agent is set up correctly with all necessary tools, LLM, STT, TTS, and VAD components. It’s also helpful to verify that the LLM responds properly to the system prompt and tool outputs. 7. Simulate End-to-End Flow: Running the full flow with mock data can pinpoint where things might be stalling. Using debug logs to trace each step can be really insightful. If you continue to experience issues, please feel free to share exactly which tool or step seems to be causing trouble. I’m here to help you with more focused guidance!
c
can you let me know i need to config multi agent for my bot ? to handle this ?
t
Absolutely, LiveKit does support multi-agent configurations, and it’s actually a great approach for managing more complex workflows like lead qualification. With multi-agent setups, you can: • Have specialized agents focusing on different tasks (for example, one agent gathering information while another handles validation and decision-making). • Seamlessly hand off control between agents depending on the conversation context or what the user needs. • Keep the state and chat history intact across agent transitions, so the conversation feels smooth and continuous. For your lead qualification bot, you might consider setting it up like this: 1. Agent 1: Takes care of the initial engagement and collects basic info like name, age, and location. 2. Agent 2: Focuses on validating eligibility, managing the qualification logic, and deciding whether to transfer or wrap up the call. This way, you get a modular system that handles complex workflows more effectively. If you’d like, I’m here to help you get started with setting up a multi-agent configuration in LiveKit—just let me know! Sources: Building the all-in-one platform for voice AI agents | Google AI and LiveKit | LiveKit Docs | Workflows | LiveKit Docs | README.md | examples/README.md