Hello everyone, I tried to implement inference ser...
# ask-ai
b
Hello everyone, I tried to implement inference service in my project, but it was not working. Please help me.
Copy code
session = AgentSession[UserData](
  userdata=userdata,
  vad=ctx.proc.userdata["vad"],
  stt="assemblyai/universal-streaming",
  llm="openai/gpt-4.1-mini",
  tts="cartesia/sonic-2:6f84f4b8-58a2-430c-8c79-688dad597532",
  turn_detection=MultilingualModel()
)
t
Thanks for reaching out, Dragon. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To help you get started with implementing inference services using the
AgentSession
in your project, let's make sure you specify the models correctly and set up error handling just right. Here's a friendly example to guide you:
Copy code
session = AgentSession(
    stt="assemblyai/universal-streaming",
    llm="openai/gpt-4.1-mini", 
    tts="cartesia/sonic-2:6f84f4b8-58a2-430c-8c79-688dad597532",
    turn_detection=MultilingualModel(),
    conn_options=SessionConnectOptions(
        max_unrecoverable_errors=5  # Feel free to adjust this based on your needs
    )
)
If you happen to run into any issues, here are some helpful troubleshooting tips: • Try to keep the agent and AI services close network-wise to help reduce any latency. • Keep an eye on the
max_unrecoverable_errors
parameter—it defaults to 3 consecutive errors before the session closes, so adjusting it might help. • If you see a "Room connection was not established within 10 seconds" error, double-check that you’re calling
await job_ctx.connect()
in your job entrypoint. • Use the MetricsCollected event to monitor how your agent is performing and spot any issues early on. Please don’t hesitate to reach out if you have any questions or need a bit more guidance—I’m here to help! Sources: Getting Help & Troubleshooting | livekit/livekit_composite | DeepWiki | examples/src/realtime_agent.ts | Introducing LiveKit Inference: A unified model interface for voice AI | livekit-agents/livekit/agents/voice/agent_session.py
b
2025-10-07 131721,513 - ERROR livekit.agents - Error in _stt_task Traceback (most recent call last): File "/root/warpme/myvenv/lib/python3.9/site-packages/livekit/agents/utils/log.py", line 16, in async_fn_logs return await fn(*args, **kwargs) File "/root/warpme/myvenv/lib/python3.9/site-packages/livekit/agents/voice/audio_recognition.py", line 460, in _stt_task async for ev in node: File "/root/warpme/myvenv/lib/python3.9/site-packages/livekit/agents/voice/agent.py", line 333, in stt_node if not activity.stt.capabilities.streaming: AttributeError: 'str' object has no attribute 'capabilities' {"pid": 2165888, "job_id": "AJ_bhAsvQyefeBz"}
t
The error AttributeError: 'str' object has no attribute 'capabilities' usually happens when a string is passed instead of an STT instance. To help you get past this, please make sure you’re initializing your STT providers correctly before using them. Here’s a simple example to guide you:
Copy code
from livekit.plugins import deepgram, cartesia

# Correctly initialize STT instances
stt_instance = deepgram.STT(model="nova-3")

# Use the instance in your session or adapter
session = AgentSession(
    stt=stt_instance,
    llm="openai/gpt-4.1-mini",
    tts="cartesia/sonic-2:6f84f4b8-58a2-430c-8c79-688dad597532"
)
If you’re selecting STT providers dynamically, just double-check that the configuration creates the STT object itself, rather than passing a string. Please feel free to reach out if you’d like me to walk you through it or if you have any other questions—I’m here to help! Sources: AI Service Plugin System | livekit/livekit_composite | DeepWiki | livekit-agents/livekit/agents/voice/audio_recognition.py | Speech-to-text (STT) models | LiveKit Docs
b
2025-10-07 132017,367 - ERROR livekit.agents - Error in _stt_task Traceback (most recent call last): File "/root/warpme/myvenv/lib/python3.9/site-packages/livekit/agents/utils/log.py", line 16, in async_fn_logs return await fn(*args, **kwargs) File "/root/warpme/myvenv/lib/python3.9/site-packages/livekit/agents/voice/audio_recognition.py", line 460, in _stt_task async for ev in node: File "/root/warpme/myvenv/lib/python3.9/site-packages/livekit/agents/voice/agent.py", line 333, in stt_node if not activity.stt.capabilities.streaming: AttributeError: 'str' object has no attribute 'capabilities' {"pid": 2166790, "job_id": "AJ_hGopwHr7NRYL"}
t
Could you please share a bit about how you're setting up the STT provider in your code? For example, are you passing a string directly, or are you initializing the STT instance with a specific provider like Deepgram or Cartesia? Understanding this will really help us pinpoint the issue together.
b
stt="assemblyai/universal-streaming",
t
The issue happens because the STT parameter is being passed as a string (like "assemblyai/universal-streaming") instead of a properly initialized STT instance. No worries though! To fix this, you just need to use the right STT class to create the provider instance. Here’s a simple way to do it:
Copy code
from livekit.agents.inference import stt as inference_stt

# Properly initialize the STT instance
stt_instance = inference_stt.STT.from_model_string("assemblyai/universal-streaming")

# Use the instance in your session
session = AgentSession(
    stt=stt_instance,
    llm="openai/gpt-4.1-mini",
    tts="cartesia/sonic-2:6f84f4b8-58a2-430c-8c79-688dad597532"
)
By doing this, the STT instance will have all the necessary attributes, like capabilities, which helps avoid that error. If you run into any other questions or need more help, just let me know—I’m here for you!