I am building an agent that will use a custom LLM....
# ask-ai
b
I am building an agent that will use a custom LLM. Can I send a custom (not generated) voice message to the remote participant when executing a tool? Something like “Just one second”
t
Thanks for reaching out, Martín. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! You can send a custom voice message to a remote participant in two easy ways: • Agent Speaks: This uses the agent's Text-to-Speech (TTS) system to create and send the message straight to everyone in the room. For example, you might use
session.say("Just one second")
right within your tool. • Frontend Plays: Here, you use Remote Procedure Calls (RPC) to tell the frontend to play a specific audio file or a synthesized voice message. Just a heads up, this means you'll need some custom logic on the frontend to handle the RPC and play the audio. If you want, I’m happy to walk you through the details of either option—just let me know! Sources: Tool definition and use | LiveKit Docs | agents/src/voice/agent_activity.ts | livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti... | avatars/hedra/education_avatar/agent.py | Remote method calls (RPC) | LiveKit Docs
b
Do I have access to the session on an LLMStream object?
t
Hey there! Just a quick heads-up: the
LLMStream
object doesn’t give you direct access to the session in LiveKit. It’s mainly there to handle streaming responses from the LLM and keep things running smoothly with the LLM provider. If you want to work with the LiveKit session itself, the best way is to use the
RunContext
parameter in your tool functions. That’s the one that gives you clear access to the current session, so you can manage state or interact with rooms easily. Feel free to reach out if you want me to explain anything more or help out with anything else! Sources: livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti... | plugins/google/src/llm.ts | Tool definition and use | LiveKit Docs
b
Ok, but how does that work with my custom LLM?
t
Hey there! You can easily connect your custom LLM with LiveKit by using the
AgentSession
class and pointing it to the right plugin or OpenAI-compatible endpoint. Here are some handy examples to get you started: • Ollama: Just use the OpenAI plugin with a custom base URL for your local Ollama server:
Copy code
from livekit.agents import AgentSession
from livekit.plugins import openai

session = AgentSession(
    llm=openai.LLM.with_ollama(
        model="llama3.1",
        base_url="http://localhost:11434/v1",
    ),
)
• DeepSeek: Here’s how to use the OpenAI plugin with DeepSeek:
Copy code
from livekit.plugins import openai

llm = openai.LLM.with_deepseek(
    model="deepseek-chat",
    temperature=0.7
)

session = AgentSession(llm=llm)
• Baseten: You can also directly work with Baseten models like this:
Copy code
from livekit.plugins import baseten

session = AgentSession(
    llm=baseten.LLM(model="meta-llama/Llama-4-Maverick-17B-128E-Instruct"),
)
• AWS Bedrock: And if you want to use Amazon Bedrock for LLMs, here’s how:
Copy code
from livekit.plugins import aws

session = AgentSession(
    llm=aws.LLM(model="anthropic.claude-3-5-sonnet-20240620-v1:0"),
)
To keep track of your session and shared state, just use the
RunContext
parameter inside your tool functions. This makes managing state and interacting with the room super smooth. If you want me to walk you through any specific setup or have questions, just let me know—I’m here to help! Sources: Baseten LLM integration guide | LiveKit Docs | Amazon Bedrock LLM integration guide | LiveKit Docs | rpc/rpc_agent.py | Large language model (LLM) integrations | LiveKit Docs | Ollama integration guide | LiveKit Docs
b
Can I create a function tool with variadics? *args **kwargs?
t
Hey there! Just a quick heads-up: function tools in LiveKit do support variadic arguments (
*args
and
**kwargs
) behind the scenes to make things run smoothly. But this is more of a behind-the-scenes detail and not really meant for user-defined tools to handle truly dynamic or varying numbers of arguments like you might expect in regular Python. When you define your tools, the
@function_tool
decorator creates a formal JSON schema based on your function's type hints and docstring. This helps ensure the LLM sends arguments that fit the structure you’ve set, and the framework takes care of mapping those to your tool’s parameters using
*args
and
**kwargs
under the hood. If you want, I’m here to help clarify anything or assist you with setting up your tool’s parameters—just let me know! Sources: livekit-agents/livekit/agents/voice/agent_activity.py
b
I want to create a single tool that can be called with variadics, is that possible?
t
Hey there! So, you can’t directly define a function tool with Python-style variadic arguments like
*args
or
**kwargs
, but don’t worry—you can still get that same kind of flexibility using raw function tools with the
raw_arguments
parameter. Here’s a simple way to do it: 1. Define a raw schema: Set up a JSON schema that lets you handle dynamic inputs, for example by using
additionalProperties
to allow open-ended dictionaries. 2. Use `raw_arguments`: Create your function tool to accept
raw_arguments: dict[str, object]
, which will include all the arguments the LLM passes in. Check out this example:
Copy code
from livekit.agents import function_tool\n\n@function_tool(raw_schema={\n    \"type\": \"function\",\n    \"parameters\": {\n        \"type\": \"object\",\n        \"additionalProperties\": { \"type\": \"object\" }\n    }\n})\nasync def dynamic_tool(raw_arguments: dict[str, object]):\n    # Process dynamic arguments\n    return raw_arguments
This way, you can handle a flexible set of arguments on the fly. If you want me to walk you through it more or share some extra examples, just let me know—I’m here to help! Sources: livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/llm.py | Tool definition and use | LiveKit Docs