I'm using livekit-agents version 1.2.15 and trying...
# ask-ai
l
I'm using livekit-agents version 1.2.15 and trying to implement function calling so the AI agent can execute custom functions (like sending emails for ticket raising). I tried using @llm.ai_callable() decorator but getting: AttributeError: module 'livekit.agents.llm' has no attribute 'ai_callable' What is the correct way to implement function calling in version 1.2.15? How do I register custom functions that the LLM can call during conversation?
Copy code
### Question 2: Alternative Approaches
If function calling isn't available in 1.2.15, what are the recommended alternatives for: - Triggering custom Python functions based on user intent/conversation context - Implementing ticket raising or email sending functionality - Having the agent execute backend actions during conversation Should I: 1. Parse the LLM responses and trigger functions manually? 2. Use a different callback mechanism? 3. Upgrade to a newer version? (If so, which version supports function calling?)
Copy code
### Question 3: Event Handling
In livekit-agents 1.2.15, what events can I listen to on the Agent or AgentSession? I need to detect when: - User sends a message - Agent generates a response - Conversation reaches certain states What's the proper event handling pattern for this version?
Copy code
### Question 4: Version Clarification
What version of livekit-agents introduced function calling / tool use capabilities? Is there documentation or migration guide for implementing custom function execution?
t
Thanks for reaching out, Computer. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thank you for reaching out! I’m happy to help with your questions about LiveKit Agents version 1.2.15. Let’s walk through them together: 1. Function Calling in Version 1.2.15 The
@llm.ai_callable()
decorator is still supported in this version to keep things smooth for you. That said, we recommend using the newer
@function_tool
decorator—it makes defining functions easier, supports automatic type inference, and fits better with the framework. Here’s a quick example using `@function_tool`:
Copy code
from livekit.agents.llm import function_tool

@function_tool(description="Send an email for ticket raising")
async def send_email(subject: str, body: str) -> str:
    # Your implementation here
    return "Email sent successfully"
If you’d like, I’m here to help you convert your existing functions to this new format—just let me know! 2. Alternatives for Triggering Custom Functions If function calling doesn’t quite fit your needs, no worries! Here are some other options you might find useful: • Manual Parsing: You can parse LLM responses yourself and trigger functions based on what you get. • Event-Based Control: Use events like
function_tools_executed
to manage function behavior dynamically. • Upgrade: Upgrading to a newer version can unlock enhanced function calling features—version 1.0 brought some great improvements! Feel free to ask if you want guidance on any of these approaches—I’m here to support you. 3. Event Handling in Version 1.2.15 You can listen for these helpful events on the `AgentSession`: • `user_input_transcribed`: To catch user messages as they come in. • `conversation_item_added`: To keep track of messages from both users and agents. • `agent_state_changed`: To monitor changes in agent state, like when it’s listening or thinking. • `function_tools_executed`: To know when functions have been run. Here’s a quick example:
Copy code
@session.on("conversation_item_added")
def on_message(event):
    print(f"New message: {event.item.text_content}")
4. Version Clarification Just to clarify, function calling has been around since before version 0.4.0 and got a big boost in version 1.0. We also have migration guides ready to help you smoothly transition to the newer
@function_tool
style. If you’d like assistance with upgrading or implementing any specific features, please don’t hesitate to reach out—I’m here to help every step of the way! Sources: livekit-agents/livekit/agents/inference/llm.py | ivr-nagivator/README.mdoc | Agents v0.x migration guide - Python | LiveKit Docs | External data and RAG | LiveKit Docs | complex-agents/testing/agent_test.py