```Context Python livekit-agents version: what's t...
# ask-ai
e
Copy code
Context
Python livekit-agents version: what's the correct API to run a silent LLM call from a tool (not TTS), given an llm.ChatContext?
My runtime reports: has_chat=True, has_complete=False on session.llm.chat, and calling session.llm.chat(ctx=analysis_ctx) errors with "LLM.chat() takes 1 positional argument but 2 were given".
Questions
1) For livekit-agents <please confirm latest version number>, what is the supported call shape?
session.llm.chat.complete(ctx)
session.llm.chat().complete(ctx)
session.llm.complete(ctx)
session.llm.generate(ctx)
something else?
2) Is session.llm.chat a property returning a Chat interface, a method with no args, or a callable? What's the canonical way to detect this at runtime?
Please provide a minimal snippet to get a string response from ChatContext.
3) If chat is a property, should we never call chat(...) but only chat.complete(ctx)?
If chat is a method returning an object, is the correct form session.llm.chat().complete(ctx)?
4) Any constraints on calling the LLM from inside a tool (background task) versus via Agent.llm_node?
t
Thanks for reaching out, Hamza. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thank you for your questions about using the LiveKit Python library for silent LLM calls! I’m happy to walk you through the details: 1. Supported Call Shape: The right way to make the call is using
session.llm.chat(chat_ctx=ctx)
. Just a heads-up, there isn’t a
complete
method in this library. 2. Nature of `session.llm.chat`: This is a method, not a property or a callable object. To check this at runtime, you can use
callable(session.llm.chat)
, which should return
True
. 3. Calling `chat`: Since
chat
is a method, you’ll want to call it directly with the right arguments, like
session.llm.chat(chat_ctx=ctx)
. Avoid calling
chat()
without arguments or treating it like a property. 4. Constraints on Calling LLM from Tools: You can call the LLM inside a tool by accessing it via
self._activity.llm
. Just make sure both the activity and LLM are available before you make the call. To keep calls silent, you can consume the
LLMStream
manually without sending the response to TTS. Here’s a simple example to help you get a string response from a `ChatContext`:
Copy code
from livekit.agents.llm import ChatContext, ChatMessage

# Create a ChatContext
ctx = ChatContext.empty()
ctx.insert(ChatMessage(role="user", content="Your query here"))

# Call the LLM
llm_stream = session.llm.chat(chat_ctx=ctx)
response = ""
async for chunk in llm_stream:
    if chunk.delta and chunk.delta.content:
        response += chunk.delta.content

print(response)
If anything isn’t clear or you’d like me to help further, please don’t hesitate to ask. I’m here to help! Sources: examples/voice_agents/multi_agent.py