why do i get this error ImportError: cannot impor...
# ask-ai
p
why do i get this error ImportError: cannot import name 'AgentSession' from 'livekit.agents'
t
Thanks for reaching out, GODGIFT. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The error
ImportError: cannot import name 'AgentSession' from 'livekit.agents'
typically occurs if the module or class is not available in the version of the LiveKit library you are using. Based on the documentation,
AgentSession
should be importable directly from
livekit.agents
as shown below:
Copy code
from livekit.agents import AgentSession
Please ensure that: • You have installed the correct version of the LiveKit library that includes
AgentSession
. • There are no typos in your import statement. • Your environment is using the expected version of the library (e.g., check for virtual environment conflicts). If the issue persists, please let me know, and I can assist further. Sources: Building voice agents | LiveKit Docs
p
what version would you recommend i install? i installed the latest version
t
It seems that the recommended version for using
AgentSession
is not explicitly mentioned in the documentation. However, the installation command provided in the sources is:
Copy code
pip install "livekit-agents[openai,silero,deepgram,cartesia,turn-detector]~=1.0"
This suggests that version 1.0 or a compatible version should work. If you have installed the latest version and are still encountering issues, you might want to try this specific version range. Let me know if you need further assistance!
p
how do i enable text input for my agent both on the frontend and backend?
t
To enable text input for your agent, here are the steps for both the backend and frontend: Backend (Python) Text input is enabled by default in LiveKit Agents 1.0. The agent automatically receives text input from a text stream on the
lk.chat
topic. If you need to disable it, you can use the following code:
Copy code
# To disable text input
room_input_options = RoomInputOptions(text_enabled=False)
If you want to ensure it is enabled, no additional configuration is required as it is the default behavior. Frontend Integration On the frontend, you need to use text streams with the
lk.chat
topic. The agent will automatically process text messages sent on this topic. When a user sends a text message, the agent will interrupt its current speech (if any) to process the message and generate a new response. For JavaScript/TypeScript applications, you can use the
InputTextContent
interface. Here is an example structure:
Copy code
{
  text: "Your message here",
  type: "input_text"
}
Let me know if you need further clarification or assistance! Sources: Text and transcriptions | LiveKit Docs | Agents 0.x migration guide | LiveKit Docs | InputTextContent | LiveKit Agents
p
ERROR livekit.agents - Error in _bounce_eou_task Traceback (most recent call last): File "C:\Users\HomePC\krosai-platform-backend\.platform\Lib\site-packages\livekit\agents\utils\log.py", line 16, in async_fn_logs return await fn(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HomePC\krosai-platform-backend\.platform\Lib\site-packages\livekit\agents\voice\audio_recognition.py", line 296, in _bounce_eou_task if not turn_detector.supports_language(self._last_language): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'EOUPlugin' object has no attribute 'supports_language' I get this error when i interact with the agent
t
The error you are encountering,
AttributeError: 'EOUPlugin' object has no attribute 'supports_language'
, occurs because the
_bounce_eou_task
function is attempting to call a method
supports_language
on the
EOUPlugin
object, but this method is not implemented in your current setup. To resolve this issue, ensure that your
EOUPlugin
class either: • Inherits from
EOUModelBase
, which implements the
supports_language
method, or • Implements the
supports_language
method with the following signature:
Copy code
def supports_language(self, language: str | None) -> bool:
    return self.unlikely_threshold(language) is not None
This method is required by the
_TurnDetector
Protocol, which defines the expected interface for turn detection. Let me know if you need further assistance with implementing this fix! Sources: Tree View: | dse-workbench
p
how do i pass other metadata such as voice_id, welcome message or prompt to the agent?
t
You can pass metadata such as
voice_id
,
welcome_message
, or
prompt
to a LiveKit agent by including it in the job metadata during explicit agent dispatch. This metadata will then be accessible to the agent in the
JobContext
. Here is an example of how to include metadata during dispatch:
Copy code
import asyncio
from livekit import api

room_name = "my-room"
agent_name = "test-agent"

async def create_explicit_dispatch():
    lkapi = api.LiveKitAPI()
    dispatch = await lkapi.agent_dispatch.create_dispatch(
        api.CreateAgentDispatchRequest(
            agent_name=agent_name, 
            room=room_name, 
            metadata='{"user_id": "12345", "voice_id": "voice1", "welcome_message": "Hello!"}'
        )
    )
    print("created dispatch", dispatch)
In your agent's entrypoint function, you can access this metadata as follows:
Copy code
import json

async def entrypoint(ctx: JobContext):
    metadata = json.loads(ctx.job.metadata)
    voice_id = metadata["voice_id"]
    welcome_message = metadata["welcome_message"]
    # Use these values in your agent logic
This approach allows you to customize your agent's behavior with specific parameters for each dispatch. Let me know if you need further assistance! Sources: Agent dispatch | LiveKit Docs | Job lifecycle | LiveKit Docs
p
File "C:\Users\HomePC\krosai-platform-backend\krosai_platform\agents.py", line 49, in entrypoint metadata = json.loads(ctx.job.metadata) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.13_3.13.1008.0_x64__qbz5n2kfra8p0\Lib\json\__init__.py", line 346, in loads return _default_decoder.decode(s) ~~~~~~~~~~~~~~~~~~~~~~~^^^ File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.13_3.13.1008.0_x64__qbz5n2kfra8p0\Lib\json\decoder.py", line 345, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.13_3.13.1008.0_x64__qbz5n2kfra8p0\Lib\json\decoder.py", line 363, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) I get this error
t
The error
JSONDecodeError: Expecting value
occurs when the metadata you are trying to parse is either empty, malformed, or not valid JSON. In your case, it seems that
ctx.job.metadata
is not containing valid JSON data. To resolve this issue, please ensure the following: 1. When dispatching the agent, make sure you are passing valid JSON in the metadata field. For example:
Copy code
metadata='{"user_id": "12345", "voice_id": "voice1", "welcome_message": "Hello!"}'
1. Add error handling in your code to handle cases where metadata might be empty or invalid. Here is an example:
Copy code
import json

async def entrypoint(ctx: JobContext):
    try:
        metadata = json.loads(ctx.job.metadata) if ctx.job.metadata else {}
        voice_id = metadata.get("voice_id", "default_voice")
        welcome_message = metadata.get("welcome_message", "Welcome!")
        # Use these values in your agent logic
    except json.JSONDecodeError:
        # Handle invalid JSON
        metadata = {}
        voice_id = "default_voice"
        welcome_message = "Welcome!"
This will ensure that your code can handle cases where the metadata is not properly formatted or is missing. Let me know if you need further assistance! Sources: External data and RAG | LiveKit Docs | Job lifecycle | LiveKit Docs
Thank you for sharing your code! It looks like you have implemented a comprehensive setup for your LiveKit agent, including handling metadata, configuring STT, TTS, and LLM providers, and enabling text input. If you are encountering any specific issues or have questions about this implementation, please let me know, and I will be happy to assist further!
p
the metadata was dispatched but i am getting empty metadata from the agent
t
If the metadata is not being dispatched to the agent, here are a few steps to troubleshoot and resolve the issue: 1. Ensure Metadata is Passed During Dispatch: Verify that you are including the metadata in the
metadata
parameter when creating the agent dispatch. For example:
Copy code
dispatch = await lkapi.agent_dispatch.create_dispatch(
    api.CreateAgentDispatchRequest(
        agent_name="test-agent", 
        room="my-room", 
        metadata='{"voice_id": "voice1", "welcome_message": "Hello!"}'
    )
)
1. Validate Metadata Format: Ensure that the metadata is a valid JSON string. Invalid JSON will not be parsed correctly by the agent. 2. Check Agent Code: Confirm that your agent's
entrypoint
function is correctly accessing the metadata using
ctx.job.metadata
. For example:
Copy code
metadata = json.loads(ctx.job.metadata) if ctx.job.metadata else {}
voice_id = metadata.get("voice_id")
welcome_message = metadata.get("welcome_message", "Welcome!")
1. Debug Logging: Add logging to verify that the metadata is being received by the agent. For example:
Copy code
<http://logger.info|logger.info>(f"Received job metadata: {ctx.job.metadata}")
1. Verify Dispatch Success: Ensure that the dispatch request is successful and that the agent is being created in the specified room. If you have verified all of the above and the issue persists, please let me know, and I can assist further! Sources: Dispatching agents | LiveKit Docs | Agent dispatch | LiveKit Docs | room(_:didUpdateMetadata:) | Documentation
p
the metadata was dispatched but i am getting empty metadata from the agent
t
I'm sorry, but I don't have the information you need at the moment. If you would like a member of the LiveKit team to respond, please ask your question in one of the other channels.