I am building a voicebot self hosting livekit room...
# ask-ai
t
I am building a voicebot self hosting livekit rooms server as well as livekit agent server on my aws instances. I am evaluating the livekit agents as well its framework on the following aspects. Answer each of the following evaluation aspects in detail, sharing a sample example of code and a github link to it. 1. Does livekit allow replacement of text after LLM call and before TTS call? Eg - a. LLM output: “Phase II location” b. TTS input: “Phase two location” 2. Can we call apis with auth when doing a tool call? 3. Can we do sync and async tool calls? a. Sync - make a tool call, wait for it to exec and then continue with the agent flow b. Async - make a tool call, don’t wait to complete exec, continue with the flow 4. Does livekit agents allow fallback TTS/STT/LLM models? 5. Does it support idle message? Eg - a. If a user does not respond in x sec, it should ask “Are you still there?” 6. Does it have an end of call function? Can the agent end the call? 7. Can we do parallel tool calls?
t
Thanks for reaching out, Atul. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’ll answer each evaluation point you listed and include concise sample code + the referenced GitHub examples where applicable. I’ll assume by “LiveKit agents” you mean the LiveKit Agents framework used for voice agents (self-hosted agent workers + LiveKit Rooms). If you want examples specific to your AWS setup, tell me which language (Python/TypeScript) you prefer. 1) Text replacement between LLM output and TTS input • Yes. You can intercept and modify the text produced by the LLM before passing it to the TTS pipeline by overriding the TTS node (or inserting a transform hook). This is commonly used for pronunciation fixes (e.g., “Phase II” → “Phase two”). • Sample (conceptual Python):
Copy code
class MyAgent(Agent):
    async def tts_node(self, text_stream, model_settings):
        async def patched():
            async for chunk in text_stream:
                yield chunk.replace("Phase II", "Phase two")
        return await Agent.default.tts_node(self, patched(), model_settings)
• GitHub examples: ◦ Pronunciation/postprocess pattern: https://github.com/livekit/agents/blob/main/examples/voice_agents/structured_output.py ◦ Related example with text transforms: https://github.com/livekit/agents/blob/main/examples/voice_agents/restaurant_agent.py 2) Calling APIs with auth during tool calls • Yes. Tools can perform authenticated API calls using headers/tokens. Secure secrets are injected from environment variables or a secrets store and used in the tool implementation. • Sample (conceptual Python):
Copy code
@function_tool()
async def fetch_profile(ctx):
    import aiohttp, os
    headers = {"Authorization": f"Bearer {os.getenv('API_BEARER_TOKEN')}"}
    async with aiohttp.ClientSession() as s:
        async with s.get("https://api.example.com/user", headers=headers) as r:
            return await r.json()
• GitHub examples: ◦ Forwarding/tool-call examples: https://github.com/livekit/agents/blob/main/examples/voice_agents/forward_tool_call_frontend.py ◦ Secrets usage reference: builder/secrets docs example (see docs link in repo) 3) Sync and async tool calls • Yes — you can do both: ◦ Synchronous (await): Agent waits for the tool result before continuing. ◦ Asynchronous (fire-and-forget): Spawn background tasks (e.g.,
asyncio.create_task(...)
) and return immediately so the agent flow continues. • Samples: ◦ Sync:
Copy code
result = await slow_api_call()
• Async:
Copy code
asyncio.create_task(background_job(ctx))
    return "Background started"
• GitHub: ◦ Long-running / async examples: https://github.com/livekit/agents/blob/main/examples/voice_agents/long_running_function.py 4) Fallback TTS / STT / LLM models • Yes. The framework supports fallback adapters so you can define primary and fallback providers for STT, LLM, and TTS. On failure the adapter will attempt the next provider and mark unhealthy providers accordingly. • Sample (conceptual):
Copy code
session = AgentSession(
  stt=stt.FallbackAdapter([assemblyai.STT(), deepgram.STT()]),
  llm=llm.FallbackAdapter([openai.LLM(...), azure.LLM(...)]),
  tts=tts.FallbackAdapter([elevenlabs.TTS(), cartesia.TTS()])
)
• GitHub: ◦ Fallback example: https://github.com/livekit/agents/blob/main/examples/voice_agents/error_callback.py 5) Idle message (detect user not responding and prompt) • Yes. You can configure an inactivity timeout and handle user state change events to send an idle prompt (e.g., “Are you still there?”) after X seconds of silence. • Sample (conceptual):
Copy code
session = AgentSession(user_away_timeout=15.0)

@session.on("user_state_changed")
async def on_user_state_change(ev):
    if ev.new_state == "away":
        await session.generate_reply("Are you still there?")
• GitHub: ◦ Inactive-user handling: https://github.com/livekit/agents/blob/main/examples/voice_agents/inactive_user.py 6) End-of-call (can the agent end the call?) • Yes. The agent can end the call by deleting the room (or using the room management API) after finishing playback. Use
wait_for_playout()
to ensure final speech finishes before triggering hangup. • Sample (conceptual):
Copy code
await session.generate_reply("Thanks, goodbye!")
await session.wait_for_playout()
await ctx.api.room.delete_room(api.DeleteRoomRequest(room=ctx.room.name))
• GitHub: ◦ Hangup example (telephony agent): https://github.com/livekit-examples/python-agents-examples/blob/main/telephony/agent.py 7) Parallel tool calls • Yes. Tools can be invoked in parallel/concurrently. The agent/LLM flow can await multiple tool results or treat some as background tasks. When the LLM requests multiple tools, calls typically run concurrently and results are returned as they resolve. • Sample pattern:
Copy code
t1 = asyncio.create_task(call_tool_a())
t2 = asyncio.create_task(call_tool_b())
res_a, res_b = await asyncio.gather(t1, t2)
• GitHub: ◦ Tool call ordering / parallel examples: https://github.com/livekit/agents/blob/main/examples/voice_agents/tool_call_ordering.py If you’d like, I can: • Produce a single runnable example agent that demonstrates text replacement, an authenticated tool call, sync/async tool patterns, fallback providers, idle prompts, hangup behavior, and parallel tool calls. • Or provide the TypeScript equivalents if you prefer Node.js for your AWS hosts. Which would you prefer — a Python runnable example or a TypeScript one for your AWS environment?