Audio] Array (Realtek Audio [-39.56 dBFS] [#######...
# ask-ai
m
Audio] Array (Realtek Audio [-39.56 dBFS] [#############----------2025-08-07 132957,303 - INFO livekit.agents - STT metrics {"room": "fake_room", "user_id": "personal_user", "audio_duration": 5.05} [Audio] Array (Realtek Audio [-38.68 dBFS] [#############----------[Audio] Array (Realtek Audio [-40.17 dBFS] [#############----------[Audio] Array (Realtek Audio [-40.17 dBFS] [#############----------[Audio] Array (Realtek Audio [-48.80 dBFS] [#########--------------[Audio] Array (Realtek Audio [-47.32 dBFS] [##########-------------[Audio] Array (Realtek Audio [-43.14 dBFS] [############-----------[Audio] Array (Realtek Audio [-40.24 dBFS] [#############-----------------] [Text Enter your message: hello 2025-08-07 133002,023 - WARNING livekit.agents - failed to generate LLM completion, retrying in 0.1s {"room": "fake_room", "user_id": "personal_user", "llm": "livekit.plugins.groq.services.LLM", "attempt": 1} Traceback (most recent call last): File "C:\Users\dell\anaconda3\envs\publicaai\Lib\site-packages\httpx\_transports\default.py", line 101, in map_httpcore_exceptions
Copy code
from dotenv import load_dotenv
import os
import logging
from prompts import AGENT_INSTRUCTION, SESSION_INSTRUCTION


from livekit import agents
from livekit.agents import (
    AgentSession,
    Agent,
    RoomInputOptions,
    RoomOutputOptions,  
    cli,
    metrics,
    get_job_context,
)
from livekit.plugins import silero, deepgram, groq
from tools import get_weather, search_web, send_email
from livekit.agents.voice import MetricsCollectedEvent, RunContext

load_dotenv()
logger = logging.getLogger(__name__)


# Define your assistant agent with tools
class PersonalAssistant(Agent):
    def __init__(self) -> None:
        super().__init__(
            instructions=AGENT_INSTRUCTION,
            tools=[
                get_weather,
                search_web,
                send_email
            ],
        )


# Prewarm VAD model
def prewarm(proc: agents.JobProcess):
    proc.userdata["vad"] = silero.VAD.load()


# Entrypoint function
async def entrypoint(ctx: agents.JobContext):
    await ctx.connect()
    <http://logger.info|logger.info>("Connected to personal assistant room")

    ctx.log_context_fields = {
        "room": ctx.room.name,
        "user_id": "personal_user"
    }

    # Load models
    vad = ctx.proc.userdata["vad"]
    stt = deepgram.STT(model="nova-2", language="en-US")
    tts = deepgram.TTS()  # ✅ This is required for session.say()

    llm = groq.LLM(model="llama-3.3-70b-versatile")

    # Create the agent session
    session = AgentSession(
        vad=vad,
        stt=stt,
        tts=tts,
        llm=llm,
    )

    agent = PersonalAssistant()

    # Setup metrics collection (optional)
    usage_collector = metrics.UsageCollector()

    @session.on("metrics_collected")
    def on_metrics(ev: MetricsCollectedEvent):
        metrics.log_metrics(ev.metrics)
        usage_collector.collect(ev.metrics)

    async def log_usage():
        summary = usage_collector.get_summary()
        <http://logger.info|logger.info>(f"Session usage summary: {summary}")

    ctx.add_shutdown_callback(log_usage)

    # Wait for user to connect
    await ctx.wait_for_participant()
    <http://logger.info|logger.info>("User connected to the room")

    try:
        await session.start(
            room=ctx.room,
            agent=agent,
            room_input_options=RoomInputOptions(
                audio_enabled=True,
                text_enabled=True,
            ),
            room_output_options=RoomOutputOptions(
                audio_enabled=True,
                transcription_enabled=True,
            )
        )
        <http://logger.info|logger.info>("Assistant session started successfully")
    except Exception as e:
        logger.error(f"Failed to start session: {e}", exc_info=True)
        raise

    # ✅ Greeting
    await session.say(
        "Welcome! I'm here to help. Please ask me anything.",
        allow_interruptions=False
    )


# Run the app
if __name__ == "__main__":
    agents.cli.run_app(
        agents.WorkerOptions(
            entrypoint_fnc=entrypoint,
            prewarm_fnc=prewarm,
        )
    )
what could e te problem, you can provide a simple code tat will work witht the llm tts an stt tat ai am using
t
Thanks for reaching out, Anigilaje. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The error "failed to generate LLM completion, retrying in 0.1s" typically occurs due to transient issues like network problems, API errors, or failed responses from the LLM provider. Here are steps to resolve it: • Ensure stable network connectivity and verify API keys for your LLM provider. • Use a fallback mechanism to switch between multiple LLM providers if one fails. For example:
Copy code
from livekit.agents import LLM
from livekit.agents.llm import FallbackAdapter

# Example with two LLM providers
openai_llm = OpenAILLM(api_key="your-openai-key", model="gpt-4")
anthropic_llm = AnthropicLLM(api_key="your-anthropic-key", model="claude-3")

fallback_llm = FallbackAdapter(
    llm=[openai_llm, anthropic_llm],
    attempt_timeout=5.0,
    retry_interval=0.5,
    max_retry_per_llm=3  # Optional: retries per LLM instance
)

# Use the fallback adapter in your application
async def main():
    async with fallback_llm.chat(chat_ctx=your_chat_context) as stream:
        async for chunk in stream:
            print(chunk.delta.content)
• Monitor logs for specific error messages to identify the root cause. • Adjust retry intervals and timeout values based on your application’s requirements. These steps should help you resolve the issue and ensure a more robust experience. Sources: livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/llm.py | LLM Integrations | livekit/livekit_composite | DeepWiki | ResponseStatusDetails | LiveKit Agents
m
{"message": "User connected to the room", "level": "INFO", "name": "__main__", "room": "sbx-ptrecs-Ucb4c5DwyfgwYRqpcrvD8K", "user_id": "personal_user", "timestamp": "2025-08-07T203454.700627+00:00"} {"message": "pre-connect audio handler registered after room connection, start RoomIO before ctx.connect() to ensure seamless audio buffer.", "level": "WARNING", "name": "livekit.agents", "room": "sbx-ptrecs-Ucb4c5DwyfgwYRqpcrvD8K", "user_id": "personal_user", "track_id": "TR_AMcBxVETQMVvLL", "timestamp": "2025-08-07T203454.706342+00:00"} {"message": "Task exception was never retrieved\nfuture: <Task finished name='Task-86' coro=<ConnectionPool.prewarm.<locals>._prewarm_impl() done, defined at C\\Users\\dell\\anaconda3\\envs\\publicaai\\Lib\\site packages\\livekit\\agents\\utils\\connection pool.py163> exception=TypeError('TTS._connect_ws() takes 1 positional argument but 2 were given')>", "level": "ERROR", "name": "asyncio", "exc_info": "Traceback (most recent call last):\n File \"C:\\Users\\dell\\anaconda3\\envs\\publicaai\\Lib\\site-packages\\livekit\\agents\\utils\\connection_pool.py\", line 165, in _prewarm_impl\n conn = await self._connect(timeout=self._connect_timeout)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"C:\\Users\\dell\\anaconda3\\envs\\publicaai\\Lib\\site-packages\\livekit\\agents\\utils\\connection_pool.py\", line 61, in _connect\n connection = await self._connect_cb(timeout)\n ~~~~~~~~~~~~~~~~^^^^^^^^^\nTypeError: TTS._connect_ws() takes 1 positional argument but 2 were given", "room": "sbx-ptrecs-Ucb4c5DwyfgwYRqpcrvD8K", "user_id": "personal_user", "timestamp": "2025-08-07T203454.714313+00:00"} {"message": "Assistant session started successfully", "level": "INFO", "name": "__main__", "room": "sbx-ptrecs-Ucb4c5DwyfgwYRqpcrvD8K", "user_id": "personal_user", "timestamp": "2025-08-07T203454.718232+00:00"} {"message": "Error in _tts_inference_task", "level": "ERROR", "name": "livekit.agents", "exc_info": "Traceback (most recent call last):\n File \"C:\\Users\\dell\\anaconda3\\envs\\publicaai\\Lib\\site-packages\\livekit\\agents\\tts\\tts.py\", line 517, in __anext__\n val = await self._event_aiter.__anext__()\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nStopAsyncIteration\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"C:\\Users\\dell\\anaconda3\\envs\\publicaai\\Lib\\site-packages\\livekit\\agents\\utils\\log.py\", line 16, in async_fn_logs\n return await fn(*args, **kwargs)\n ^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"C:\\Users\\dell\\anaconda3\\envs\\publicaai\\Lib\\site-packages\\opentelemetry\\util\\_decorator.py\", line 71, in async_wrapper\n return await func(*args, **kwargs) # type: ignore\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"C:\\Users\\dell\\anaconda3\\envs\\publicaai\\Lib\\site-packages\\livekit\\agents\\voice\\generation.py\", line 212, in _tts_inf from dotenv import load_dotenv import os import logging from prompts import AGENT_INSTRUCTION, SESSION_INSTRUCTION from livekit import agents from livekit.agents import ( AgentSession, Agent, RoomInputOptions, RoomOutputOptions, cli, metrics, get_job_context, ) from livekit.plugins import silero, deepgram, groq from tools import get_weather, search_web, send_email from livekit.agents.voice import MetricsCollectedEvent, RunContext load_dotenv() logger = logging.getLogger(name) # Define your assistant agent with tools class PersonalAssistant(Agent): def __init__(self) -> None: super().__init__( instructions=AGENT_INSTRUCTION, tools=[ get_weather, search_web, send_email ], ) # Prewarm VAD model def prewarm(proc: agents.JobProcess): proc.userdata["vad"] = silero.VAD.load() # Entrypoint function async def entrypoint(ctx: agents.JobContext): await ctx.connect() logger.info("Connected to personal assistant room") ctx.log_context_fields = { "room": ctx.room.name, "user_id": "personal_user" } # Load models vad = ctx.proc.userdata["vad"] stt = deepgram.STT(model="nova-2", language="en-US") tts = deepgram.TTS() # This is required for session.say() llm = groq.LLM(model="llama-3.3-70b-versatile") # Create the agent session session = AgentSession( vad=vad, stt=stt, tts=tts, llm=llm, ) agent = PersonalAssistant() # Setup metrics collection (optional) usage_collector = metrics.UsageCollector() @session.on("metrics_collected") def on_metrics(ev: MetricsCollectedEvent): metrics.log_metrics(ev.metrics) usage_collector.collect(ev.metrics) async def log_usage(): summary = usage_collector.get_summary() logger.info(f"Session usage summary: {summary}") ctx.add_shutdown_callback(log_usage) # Wait for user to connect await ctx.wait_for_participant() logger.info("User connected to the room") try: await session.start( room=ctx.room, agent=agent, room_input_options=RoomInputOptions( audio_enabled=True, text_enabled=True, ), room_output_options=RoomOutputOptions( audio_enabled=True, transcription_enabled=True, ) ) logger.info("Assistant session started successfully") except Exception as e: logger.error(f"Failed to start session: {e}", exc_info=True) raise # Greeting await session.say( "Welcome! I'm here to help. Please ask me anything.", allow_interruptions=False ) # Run the app if name == "__main__": agents.cli.run_app( agents.WorkerOptions( entrypoint_fnc=entrypoint, prewarm_fnc=prewarm, ) )
t
Hey there! That error message, "TTS._connect_ws() takes 1 positional argument but 2 were given," usually pops up when the number of arguments passed to the
_connect_ws
method doesn’t quite match what it expects. This method is meant to take just
self
and
timeout
as parameters. Here’s a friendly little checklist to help you sort it out: • Double-check that your
_connect_ws
method in the TTS setup looks like this:
Copy code
async def _connect_ws(self, timeout: float) -> aiohttp.ClientWebSocketResponse:
    return await asyncio.wait_for(
        self._ensure_session().ws_connect(
            RESEMBLE_WEBSOCKET_URL,
            headers={"Authorization": f"Bearer {self._api_key}"},
        ),
        timeout,
    )
• See if there’s any custom code that’s overriding
_connect_ws
and accidentally adding an extra parameter. • Make sure you’re working with the right version of the library where the method signature matches what you expect. • Take a peek at any middleware or wrapper code that could be tweaking the arguments behind the scenes. Following these steps should get you back on track and help nix that argument mismatch error. If you hit any snags, feel free to reach out—I’m here to help! Sources: livekit-plugins/livekit-plugins-lmnt/livekit/plugins/lmnt/tts.py
m
i am sing agent 1.22 and another deepgram veriosn. hwo doi upgrade my deegram : livekit-agents==1.2.2 livekit-plugins-deepgram==1.0.11
t
Hey there! If you want to upgrade
livekit-plugins-deepgram
to the latest version, here’s a quick and easy way to do it: 1. Just run this command to upgrade the package:
Copy code
pip install --upgrade livekit-plugins-deepgram
1. If you're looking to install a specific version, no worries! Use this command instead:
Copy code
pip install livekit-plugins-deepgram==1.2.2
1. Once that’s done, you can double-check the version you have installed by running:
Copy code
pip show livekit-plugins-deepgram
Oh, and just a heads-up—make sure your pip is up to date by running
pip install --upgrade pip
. Also, if you’re working in a virtual environment, don’t forget to activate it before running these commands. Happy coding!
m
{"message": "The room connection was not established within 10 seconds after calling job_entry. This may indicate that job_ctx.connect() was not called. ", "level": "WARNING", "name": "livekit.agents", "timestamp": "2025-08-07T205212.009233+00:00"}
t
Hey there! That warning, "The room connection was not established within 10 seconds after calling job_entry," usually pops up when
job_ctx.connect()
isn’t called properly in your job entrypoint. No worries, here’s how you can fix it: 1. Make sure you’re calling
job_ctx.connect()
to set up the room connection like this:
Copy code
async def job_entry(job_ctx):
    await job_ctx.connect()
    # Your job logic here
    await job_ctx.shutdown("Job completed successfully")
1. Also, don’t forget to call
job_ctx.shutdown()
to close the connection gracefully:
Copy code
async def job_entry(job_ctx):
    try:
        await job_ctx.connect()
        # Your job logic here
    finally:
        await job_ctx.shutdown("Job completed successfully")
1. And lastly, double-check your deployment setup to make sure there aren’t any resource limits or network hiccups messing with the connection. Following these steps should clear up that warning. If you’re still running into trouble, feel free to share more about your setup—I’m here to help!
s
Hey @most-vr-18651, I'm getting this issue too in production. It's strange because it works fine locally but when I try to run it in production, I get timeout errors when my agent is trying to call the LLM - did you figure out what was causing this?
t
Timeout errors when calling the LLM in production but not locally can be a bit tricky, and they often happen because of a few common reasons: • Network Conditions: Sometimes, production environments have higher latency or experience packet loss. It might help to tweak your timeout settings to better handle this. • Timeout Configuration: Try increasing the connection and read/write timeout values in your LLM client setup. Here's a quick example:
Copy code
llm = OpenAI(
    model="gpt-4",
    api_key="your-api-key",
    base_url="<LLM_API_BASE_URL>",
    timeout=httpx.Timeout(
        connect=30.0,  # Gave the connection timeout a little more breathing room
        read=10.0,     # Increased read timeout
        write=10.0     # Increased write timeout
    )
)
Retry Mechanisms: Adding a fallback adapter with retries can be a lifesaver for those occasional hiccups. • LLM Provider Limits: Double-check that your workload stays within the provider’s rate limits to avoid any throttling surprises. • Connection Pooling: You might want to adjust connection pooling limits to better handle the higher concurrency that production often brings. Hopefully, these tips help smooth things out with those timeout errors. If you want to chat more or need a hand with anything else, just let me know—I’m here to help! Sources: livekit-plugins/livekit-plugins-baseten/livekit/plugins/baseten/llm.py
m
@straight-painting-40361 Not yet