nutritious-oyster-4341
08/21/2025, 8:36 PMtall-airline-16756
08/21/2025, 8:36 PMtall-airline-16756
08/21/2025, 8:37 PMnutritious-oyster-4341
08/21/2025, 8:39 PMtall-airline-16756
08/21/2025, 8:40 PM@llm.ai_callable() decorator. This function will take care of the user input, reach out to your external endpoint, and return the response.
2. Next, plug this function into your agent by passing it as the function context (fnc_ctx) when you set up your agent.
3. Make sure your function’s description clearly explains what it does, so the LLM knows to call it for every user message.
Here’s a quick example to get you going:
import aiohttp
from livekit.agents import llm
class AssistantFnc(llm.FunctionContext):
@llm.ai_callable()
async def process_user_message(self, user_input: str):
"""Process user message by calling external endpoint and generating reply."""
url = "https://your-api-endpoint.com/process"
async with aiohttp.ClientSession() as session:
async with session.post(url, json={"message": user_input}) as response:
if response.status == 200:
api_data = await response.json()
return api_data['result']
else:
return f"Error: {response.status}"
Then, just pass this function context to your agent when you initialize it:
fnc_ctx = AssistantFnc()
agent = YourAgentClass(..., fnc_ctx=fnc_ctx)
With this setup, your function will take charge and replace the usual responses, making its output the final reply to your users. If you have any questions or want to tweak it further, just let me know!
Sources: Function calling with Voice Agents | LiveKit Docs | Function calling with Voice Agents | LiveKit Docs | tool_calling/call_function_tool.py | Agent speech and audio | LiveKit Docs | Tool definition and use | LiveKit Docsnutritious-oyster-4341
08/21/2025, 9:17 PMtall-airline-16756
08/21/2025, 9:17 PMctx in AssistantFnc! It’s your gateway to the room context, letting you interact with the local participant, make RPC calls, and tap into other room-related features.
Here’s a quick example of how you might use ctx to perform an RPC call:
class AssistantFnc(llm.FunctionContext):
@llm.ai_callable()
async def get_user_location(self, high_accuracy: bool = False):
"""Retrieve the user's current geolocation as lat/lng."""
try:
return await ctx.room.local_participant.perform_rpc(
destination_identity=participant.identity,
method="getUserLocation",
payload=json.dumps({"highAccuracy": high_accuracy}),
response_timeout=10.0 if high_accuracy else 5.0,
)
except Exception:
return "Unable to retrieve user location"
This way, you can easily forward function calls to frontend apps or grab data that’s only available on the client side. If you have any questions or want to explore more, just let me know!
Sources: Function calling with Voice Agents | LiveKit Docsnutritious-oyster-4341
08/21/2025, 9:35 PMAny for fnc_ctxtall-airline-16756
08/21/2025, 9:36 PMAny type for fnc_ctx? For example:
• Is it when you’re accessing agent.fncCtx?
• Or maybe when you’re creating a function context?
• Also, are you using TypeScript? If yes, is your TypeScript setup using strict type checking?
Once I know a bit more, I’d be happy to guide you through fixing this!
Sources: RealtimeSession | LiveKit Agents | MultimodalAgent | LiveKit Agents | VoicePipelineAgent | LiveKit Agents | LLMStream | LiveKit Agents | agents/src/llm/function_context.tsnutritious-oyster-4341
08/21/2025, 9:41 PMtall-airline-16756
08/21/2025, 9:42 PMllm_node method to tailor how the LLM behaves—whether that’s tweaking the chat context, managing tool calls, or even plugging in your own LLM provider.
• Create a Custom LLM: Feel free to build your own LLM by extending the base LLM class. LiveKit has handy examples with OpenAI, Anthropic, and AWS Bedrock integrations that you can check out for inspiration.
• Use Fallback and Multiple LLMs: The FallbackAdapter is great if you want to run multiple LLMs and have automatic fallback options to keep things smooth.
• Agent Configuration: When you set up an agent, you can easily specify your custom LLM using the llm parameter.
These options give you lots of flexibility to shape how the LLM works in your LiveKit setup. If you want, I’m here to help you get started with any of these—just let me know!
Sources: Voice pipeline nodes | LiveKit Docs | livekit-plugins/livekit-plugins-google/livekit/plugins/google/llm.py