While using agent transfer through function tool, ...
# ask-ai
c
While using agent transfer through function tool, my current agent is repeating the same line twice before actually switching to the required agent. what may be the issue here?
t
Thanks for reaching out, Subham. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Could you help me understand a bit more so we can get this sorted out together? • Are you doing agent-to-agent transfers or SIP transfers to numbers outside your system? • Is the message repeating during the announcement (like "Transferring you now...") or in the responses you hear from the new agent afterward? • Are you calling the
session.aclose()
method once the transfer happens? Sources: Workflows | LiveKit Docs | examples/warm-transfer/warm_transfer.py | tools/server/webui/src/Config.ts | complex-agents/medical_office_triage/README.md | examples/src/restaurant_agent.ts
c
i am trying to do agent-to-agent transfers, but basically through the same entry point, so the session is still the same right? The repeating message is during the announcement from the main agent. The new agent afterward doesn't provide an issue.
t
It sounds like the repeated announcements during agent-to-agent transfers might be happening because the transfer function is getting triggered more than once, or some event handlers are firing multiple times. Normally, LiveKit’s framework takes care of this by making sure there’s just one announcement during transfers, like in this example:
Copy code
@function_tool
async def transfer_to_support(self, context: RunContext_T) -> Agent:
    await self.session.say("I'll transfer you to our Patient Support team who can help with your medical services request.")
    return await self._transfer_to_agent("support", context)
Here are a few things you can check to fix this: • Make sure your transfer function isn’t being called more than once. • Look out for any event handlers that might be causing the announcement to play repeatedly. • Stick to the pattern of one announcement followed by the agent handoff, just like in the example above. If you want, I’d be happy to take a closer look at your implementation and help you sort it out! Sources: telephony/warm_handoff.py | Company directory phone assistant | LiveKit Docs
c
Copy code
@function_tool
    async def transfer_to_project_support(self, context: RunContext):
        """Transfer the call to the Project Support team."""
        logger.info("Transferring call to Project Support team")
        return "Transferred to Project Support team", ProjectAgent(chat_ctx=self.chat_ctx)

    @function_tool
    async def transfer_to_new_project_team(self, context: RunContext):
        """Transfer the call to the New Project team."""
        logger.info("Transferring call to New Project team")
        return "Transferred to New Project team", NewProjectAgent(chat_ctx=self.chat_ctx)
prompt for the same:
Copy code
Path 1: User indicates "New Project"
Agent: "That's wonderful! We're excited to help you build your dream home. I'm connecting you to our New Project Specialist who will guide you through the next steps. Please hold for a moment."
*(Agent transfers the call to the New Project Agent queue.)
t
Hey there! Looking at the code snippet and prompt you shared, it seems like the transfer functions are returning both a message and the new agent instance. The repeated announcement issue might pop up if the transfer logic is getting triggered more than once or if the returned message is being handled multiple times. Here are a few friendly tips to help fix this: • Make sure the transfer function runs just once per user action. For example, double-check that there aren’t any duplicate triggers (like multiple event handlers) causing it to fire repeatedly. • Take a look at how the returned message (like "Transferred to New Project team") is being managed. If it’s logged or announced separately, ensure it’s not processed more than once. • Think about simplifying the transfer logic by skipping the message string return if it’s not really needed. Instead, you can handle announcements clearly before the transfer, like this:
Copy code
@function_tool
async def transfer_to_new_project_team(self, context: RunContext):
    """Transfer the call to the New Project team."""
    await self.session.say("I'm connecting you to our New Project Specialist who will guide you through the next steps. Please hold for a moment.")
    logger.info("Transferring call to New Project team")
    return NewProjectAgent(chat_ctx=self.chat_ctx)
This way, the announcement happens clearly and only once before the transfer. If you want me to walk through this more or help with anything else, just let me know—I’m here to help!
c
best practices for calling to phone using SIP?
t
Here are some friendly tips for making outbound phone calls using SIP in LiveKit: • Use E.164 Format: It’s best to format phone numbers in E.164 format (like +1234567890) so everything works smoothly with your SIP providers. • Configure an Outbound SIP Trunk: Make sure to set up a trunk with your outbound number, authentication details, and SIP provider info. • Use the CreateSIPParticipant API: Kick off calls by providing the SIP trunk ID, destination number, room name, and participant identity. • Validate Trunk ID: Double-check that your trunk ID starts with
ST_
to avoid any hiccups. • Enable Synchronous Call Control: Use
wait_until_answered: true
so you know when the call connects before moving forward. • Monitor Call Status: Keep an eye on the
sip.callStatus
attribute to get real-time updates on how your call is doing. • Play a Dial Tone: Turn on
play_dialtone: true
to give callers that familiar dial tone while the call is ringing. • Set Timeouts: Use
ringing_timeout
and
max_call_duration
to manage how long calls ring and run, helping you save resources. • Enable Noise Cancellation: Switch on
krisp_enabled: true
for clearer, crisper audio quality. • Handle Errors Gracefully: It’s a good idea to plan for things like authentication hiccups, network glitches, or invalid inputs—so your app stays reliable. If you want to dive deeper, check out the Voice AI Telephony Guide. And hey, if you have any questions or need a hand, just let me know—I’m here to help! Sources: telephony/make_call/make_call.py | README.md | Making outbound calls | LiveKit Docs | Make outbound calls | LiveKit Docs | protobufs/livekit_sip.proto
c
I want to place a call to phone number, what is command?
t
If you want to place a call to a phone number using SIP in LiveKit, here’s a simple command you can use:
Copy code
lk sip participant create sip-participant.json
Inside
sip-participant.json
, you’ll have something like this: Sources: Agents telephony integration | LiveKit Docs | SIP outbound trunk | LiveKit Docs | complex-agents/ivr-agent/flask_livekit/extension.py | Make outbound calls | LiveKit Docs | Making outbound calls | LiveKit Docs
c
What is present in the sip-participant.json?
t
Hey there! The
sip-participant.json
file holds the key details you need to kick off a SIP call. Here’s a quick peek at what it looks like:
c
explain lk dispatch create
t
The
lk dispatch create
command in LiveKit helps you send an agent to a room, giving you control over when and how agents join. Here’s a quick rundown to make it easy: • Required Flags: ◦ `--room`: The name of the room you want to send the agent to. ◦ `--new-room`: Creates a unique room name automatically for you. ◦ `--agent-name`: The name of the agent you’re dispatching (this one’s required!). ◦ `--metadata`: Use this to pass custom info or instructions to the agent, like job-specific details. Here are some examples to get you started: 1. *Dispatching an agent to make an outbound call:*`lk dispatch create \ --new-room \ --agent-name outbound-caller \ --metadata '+15105550100'` 2. *Dispatching with structured metadata:*`lk dispatch create \ --new-room \ --agent-name outbound-caller \ --metadata '{"phone_number": "+1234567890", "transfer_to": "+9876543210"}'` 3. *Running multiple agents in the same room:*`lk dispatch create \ --agent-name agent_to_test \ --room my-room \ --metadata 'my_job_metadata' lk dispatch create \ --agent-name agent_evaluator \ --room my-room \ --metadata 'my_job_metadata'` Just a few extra tips: • If the room doesn’t exist yet, no worries—it’ll be created automatically. • The
--metadata
flag is super handy for passing things like phone numbers or transfer instructions to your agent. • Make sure you’re using LiveKit CLI version 2.3.0 or newer to have all the latest features. If you want to dive deeper, check out the Dispatching agents documentation. And hey, if you have any questions or need a hand, just let me know—I’m here to help! Sources: Dispatching agents | LiveKit Docs | autocomplete/fish_autocomplete | Making calls using SIP | LiveKit Docs | evaluating-agents/README.md
c
I am using
Copy code
lk dispatch create \
  --new-room \
  --agent-name outbound-caller \
  --metadata '+15105550100'
I am still not getting the call, i have a agent hosted on cloud
t
Hey there! If the
lk dispatch create
command isn’t working for your outbound call, no worries—here are some friendly troubleshooting tips to help you out: • Verify Agent Configuration: Double-check that the agent name (
outbound-caller
) exactly matches what’s set in your hosted agent’s code. • Check SIP Trunk ID: Make sure your SIP trunk is set up correctly and that the trunk ID is valid. You can use the
lk sip outbound list
command to confirm this. • Validate Environment Variables: Take a moment to ensure these variables are all set properly:
LIVEKIT_URL
,
LIVEKIT_API_KEY
,
LIVEKIT_API_SECRET
, and
OPENAI_API_KEY
. • Monitor Call Status: Keep an eye on the
sip.callStatus
attribute to see if the call is starting or if there are any hiccups. • Check Logs: Peek at the logs for any error messages when you run the command. Common trouble spots include invalid phone numbers, wrong trunk IDs, or authentication issues. If it’s still giving you trouble, just let me know the exact error message or what you’re seeing, and I’ll be happy to help you figure it out! Sources: SIP troubleshooting guide | LiveKit Docs | Agents telephony integration | LiveKit Docs | Making calls using SIP | LiveKit Docs | README.md
c
• Monitor Call Status: Keep an eye on the
sip.callStatus
attribute to see if the call is starting or if there are any hiccups. explain in detail?
t
Hey there! Just wanted to share a quick rundown of the
sip.callStatus
attribute in LiveKit—it tells you what's going on with a SIP call as it moves along. Here’s what each status means: • active: The call is connected and media is flowing smoothly. This means the participant is right there on the call with you. • automation: For outbound calls using DTMF (like dialing extensions or PINs), this shows the call is connected but those digits are still being sent. Once all digits are dialed, it switches to
active
. • dialing: The call is just getting started, and we’re waiting for the other person to pick up. • hangup: Someone ended the call. • ringing: The call is ringing on the other end. When they answer and media starts flowing, it changes to
active
. You can keep an eye on this status in the
participant.attributes
field to see how the call is going. For example, watching for the switch from
dialing
to
active
is a great way to know the call’s been picked up. If you want me to explain anything else or have questions, just let me know—I’m here to help! Sources: SIP participant | LiveKit Docs | Making calls using SIP | LiveKit Docs | telephony/sip_lifecycle.py
c
How to check it?
t
Hey there! You can keep an eye on the
sip.callStatus
attribute in LiveKit to see what's going on with a SIP call. Here’s a quick rundown of how you can do that: • Using Attribute Changes Event: You can listen to the
participant_attributes_changed
event in your LiveKit room to catch updates as they happen. Here’s a little example:
Copy code
def on_participant_attributes_changed_handler(changed_attributes: dict, participant: rtc.Participant):\n    if participant.kind == rtc.ParticipantKind.PARTICIPANT_KIND_SIP and 'sip.callStatus' in changed_attributes:\n        print(f\"SIP Call Status Updated: {changed_attributes['sip.callStatus']}\")
• Polling the Attribute: Another way is to keep checking the
sip.callStatus
in a loop. Here’s how you might do it:
Copy code
start_time = perf_counter()\nwhile perf_counter() - start_time < 30:\n    call_status = participant.attributes.get("sip.callStatus")\n    if call_status == "active":\n        print("User has picked up")\n        break\n    elif call_status == "hangup":\n        print("Call ended by user")\n        break\n    await asyncio.sleep(0.1)
• Via API CLI: You can also use the LiveKit CLI to create a SIP participant and watch the status. When the call is answered, the
sip.callStatus
will switch to
active
. If anything’s unclear or you want me to walk you through it, just let me know—I’m here to help! Sources: SIP participant | LiveKit Docs | Making outbound calls | LiveKit Docs | livekit/livekit_sip.pb.go | Making calls using SIP | LiveKit Docs | telephony/sip_lifecycle.py
c
• Via API CLI: You can also use the LiveKit CLI to create a SIP participant and watch the status. When the call is answered, the
sip.callStatus
will switch to
active
. i want to do this
t
Hey there! To keep an eye on the
sip.callStatus
using the LiveKit CLI, here’s a simple way to do it: 1. First, create a JSON file (let’s call it
sip-participant.json
) with this content:
c
lk dispatch create \ --new-room \ --agent-name my-agent \ --metadata 'XXXXXXXXXX Using project [qualif-test-sd] Dispatch created: id:"AD_aLWyRobEoVkq" agent_name:"my-agent" room:"room-rVLNW4vBqSZc" metadata:"XXXXXXXXXX" state{created at1756977678644962521} {"job_id": "AJ_zf79gc7VYifr", "dispatch_id": "", "room_name": "room-rVLNW4vBqSZc", "agent_name": "my-agent", "resuming": false} is the dispatch and metadata passed here? I am unable to place calls here.
t
Thanks for sharing the output! It looks like the dispatch was created successfully, and the metadata ("XXXXXXXXXX") was passed along. If the call isn’t going through, no worries—here are a few friendly troubleshooting tips to help you figure it out: • Double-check the Metadata: Make sure the metadata includes the correct phone number in E.164 format (like +1234567890). If it’s not formatted right, the agent might not pick it up properly. • Review Your Agent’s Logic: Take a look at how your agent handles the metadata—does it know to pull out the phone number and place the call? That step is key! • Keep an Eye on the Logs: Peek into your hosted agent’s logs to see if it’s receiving the metadata and trying to make the call. Any errors there can give you clues. • Try Simplifying the Metadata: Test by sending just the phone number as metadata (like '+1234567890') to rule out any formatting hiccups. • Check Your SIP Trunk Setup: Make sure your SIP trunk is set up correctly and working. You can use the
lk sip outbound list
command to verify the trunk ID. If you’re still stuck after these steps, feel free to share more about how your agent handles metadata and calls—I’m here to help you get it sorted!
c
Can you explain this?
Copy code
2025-09-04 15:34:54,611 - WARNING livekit.plugins.google - no candidates in the response: sdk_http_response=HttpResponse(
  headers=<dict len=11>
) candidates=[Candidate(
  content=Content(
    role='model'
  ),
  finish_reason=<FinishReason.STOP: 'STOP'>,
  index=0
)] create_time=None model_version='gemini-2.5-flash-lite' prompt_feedback=None response_id='RmS5aKXHHsiLqtsP6bqLoAE' usage_metadata=GenerateContentResponseUsageMetadata(
  prompt_token_count=1845,
  prompt_tokens_details=[
    ModalityTokenCount(
      modality=<MediaModality.TEXT: 'TEXT'>,
      token_count=1845
    ),
  ],
  total_token_count=1845
) automatic_function_calling_history=None parsed=None {"room": "room-Yn2C3X5nDFkj", "pid": 13876, "job_id": "AJ_Jb2GR4XwKaWH"}
t
Hey there! That warning message, "no candidates in the response," pops up when LiveKit gets a reply from an external service (like Google's Gemini API) but doesn’t find any valid candidate outputs. This usually happens when you’re working with language or speech models and the response should have some generated content, but instead, the service sends back an empty or invalid list. Here are some common reasons why this might happen: • Empty Model Response: The model might not have generated anything, maybe because of input filtering, safety rules, or an internal hiccup. • Invalid Input: Sometimes the prompt or settings might be off, so no candidates get created. • Rate Limiting or Quota Issues: If API limits are hit, responses can come back incomplete. • Network or Service Interruption: A partial or failed API response might still trigger the handler but without any candidate data. Here’s what you can try: • Double-check the input prompts or audio you’re sending to make sure they fit the API’s requirements. • Verify your API keys, network connections, and service quotas are all good to go. • Take a look at the full logs for any related errors (like "promptFeedback" issues) to get more clues. • Make sure the model name and settings (like voice or temperature) are correct and supported. Just so you know, this warning isn’t something to worry about—it’s mostly there to help diagnose when AI-generated responses don’t come through as expected. If you want, I’m here to help you figure it out! Sources: plugins/google/src/beta/realtime/realtime_api.ts | livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/llm.py
c
Do I need to add create_sip_participant logic into entry point for this?
t
Hey there! If you want to place a SIP call as part of your agent's workflow, you'll want to include the
create_sip_participant
logic right at the entry point or somewhere within the agent's process. This way, the SIP participant gets created and connected to the right room as soon as the agent is dispatched. Here’s a quick example of how you can add the
create_sip_participant
logic: