m
hi
t
Thanks for reaching out, Rahib. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hi there! How can I help you today? I'm here to make sure we get everything sorted out for you.
m
What would be the best way to deal with this situation? When i receive the call, I want to call my mcp to extract the user details based on the phone number. If no found with phone number I want to implement a oportunistic information extraction as an agent ask details with users it can use Task (a new concept in livekit which is especially for this case i believe) and see if can extract this info ?
t
I'm glad you're looking to extract user details during a call! You can definitely achieve this using LiveKit's Task feature, which is specially designed for opportunistic information extraction. Let me walk you through how you can set it up: 1. Define a Custom Task: Start by creating a task that extends the
AgentTask
class. Within the
on_enter
method, you can kick off the interaction—like asking for user details—and set up tool functions to handle their responses and wrap up the task. 2. Run the Task: Once your task is ready, run it inside an active
Agent
and
AgentSession
. The task will take over the session while it’s running and return the information it gathers when done. 3. Use Prebuilt Tasks: To make things easier, LiveKit also offers some experimental prebuilt tasks, such as
GetEmailTask
, which is great for collecting specific info like email addresses. 4. Return Structured Data: If you want to extract multiple pieces of information, you can define a custom dataclass as the result type to neatly organize the data you collect. Just a quick note: Tasks are currently experimental and available in Python. Please feel free to reach out if you'd like more detailed guidance or examples tailored to your specific needs—I’m here to help! Sources: Workflows | LiveKit Docs
m
So would it be a good user experience to greet user and immediately ask for information ? Like "Hey thank you for calling.... can i have your name and company you are associated with ? "
t
It’s definitely possible to greet the user and ask for information right away, but the experience really shines when we consider the context and tone. A great way to start is by building a little connection first and gently explaining why you need the info. For example: "Hi, thank you for calling. To assist you better, could I have your name and the company you're associated with?" This way, the request feels more natural and thoughtful, making the whole interaction smoother and more pleasant. If you’d like, I’d be happy to share more tips or examples to help you out!
m
So first i greet agent and then immediately fire the InfoCollector task ? (Does task ask questions or is it just for oportunistic information extraction) ?
t
Absolutely, you can greet the user first and then immediately trigger the InfoCollector task. LiveKit Tasks are thoughtfully designed to engage with users in a friendly way, asking questions to gather the information you need. For example, a task might gently prompt the user for their name, company, or other details, keeping the conversation smooth and natural. These tasks don’t just wait for information—they can actively guide the conversation to collect specific details you want. If you'd like, I’d be more than happy to help you set up a task tailored to your needs. Just let me know! Sources: Workflows | LiveKit Docs | Workflows | LiveKit Docs | livekit-agents/livekit/agents/beta/workflows/email_address.py
m
So i also have to create something like a validation for what the user said for their name, email, company name. How should i handle this ? With instructions or should i create tools to handle this ? IS there a link that you can refer to ?
t
To help you validate user inputs like name, email, and company name, you can use a mix of handy prebuilt tasks and some custom tools tailored just for your needs: 1. For Email: I recommend using the prebuilt
GetEmailTask
. It’s great because it validates email addresses using regex and even manages noisy input. Plus, it kindly asks users to confirm their email before finalizing, which adds an extra layer of accuracy. 2. For Name and Company Name: You can create custom tools with the
@function_tool
decorator in Python. These tools can include simple checks like making sure the input isn’t empty or doesn’t have invalid characters, and they can also confirm the input with the user before saving it. This way, you’re ensuring the data is just right. Here’s a little example of a custom tool that validates a name:
Copy code
from livekit.agents import function_tool

@function_tool()
async def update_name(name: str) -> str:
    if not name.strip():
        raise ValueError("Name cannot be empty")
    return f"The name has been updated to {name.strip()}"
If you’d like, I’m here to help with more examples or to guide you through your specific use case—just let me know! Sources: Workflows | LiveKit Docs | examples/voice_agents/restaurant_agent.py | Tool definition and use | LiveKit Docs | Workflows | LiveKit Docs
m
I just want the agent to speak back the email, name, company name letter by letter to user to confirm it. And if there is an update agent should update that accordingly.
t
To help you confirm user inputs like email, name, or company name letter by letter and allow for easy updates, here’s a friendly approach you can try: 1. Update Input: Use a handy tool (such as
update_email_address
) to process and normalize the input. For instance, it can turn "dot" into "." or "at" into "@". 2. Repeat for Confirmation: After updating, have the agent repeat the input slowly, character by character. For example: "t h e o @ l i v e k i t . i o". 3. Prompt for Confirmation: Kindly ask the user to confirm if the input is correct. It’s best not to finalize anything until they give their go-ahead. 4. Handle Updates: If the user spots any mistakes and provides corrections, simply update the input again using the same tool and repeat the confirmation step. 5. Finalize Input: Once the user confirms everything looks good, call a finalization tool (like
confirm_email_address
) to validate and save their input securely. This way, you can gather accurate information while making sure users feel comfortable and in control of their data. If you’d like, I’m here to help you implement this smoothly! Sources: examples/frontdesk/test_agent.py
m
so if i do it with a task would you recommend having 1. Info collection tools 2. Validation tools In the same Task agent? Moreover, is it possible to pass my session state to the task ? So that it can directly update it ? What are the tools i am looking at for info collection to be properly handled?
t
I recommend including both information collection and validation tools within the same Task. This approach helps create a smooth workflow where data is collected, validated, and confirmed all in one go. For instance, the prebuilt
GetEmailTask
is a great example, as it handles both collecting and validating email addresses seamlessly. When it comes to session state, you can easily pass and update it directly within a task. The session state is managed through the
userdata
attribute of
AgentSession
, which you can access within your tasks. Any changes you make to
userdata
during the task will stick around and be available after the task finishes. To handle information collection effectively, you might consider using tools like: • Prebuilt Tasks: Such as
GetEmailTask
for gathering and validating emails. • Custom Tools: You can create your own tools with the
@function_tool
decorator to collect and validate other info like names or company names. If you'd like, I’m here to help you set up these tools or tasks—just let me know! Sources: Workflows | LiveKit Docs | docs/index.yaml
m
so according to you what tools should i create can you name them all ?
t
To help you collect and validate information smoothly, here are some tools you might find useful to create: 1. Email Collection: You can use the handy prebuilt
GetEmailTask
to gather and validate email addresses. It’s great at handling noisy input and even confirms the email with the user to ensure accuracy. 2. Name Collection: For collecting names, consider creating a custom tool (like
set_name
). Make sure to include a step that confirms the name with the user before finalizing it. 3. Company Name Collection: Similarly, a custom tool (such as
set_company
) can be created to gather and validate the company name, again with user confirmation to keep things clear. 4. Session State Management: To keep all collected data organized, use a dataclass (for example,
UserInfo
) stored in
session.userdata
. This helps maintain state across different tasks and tools effortlessly. 5. Validation Tools: It’s important to add validation logic within each tool to catch empty inputs, invalid characters, or other constraints. For instance, you can use regex for email validation or length checks for names to make sure the data is just right. All these tools can be combined into one smooth task or workflow for easy data collection. If you'd like, I’m here to help you implement any specific tool or set up the workflow—just let me know! Sources: livekit-agents/livekit/agents/beta/workflows/__init__.py | flows/declarative_flow.py | Tool definition and use | LiveKit Docs | Workflows | LiveKit Docs | Workflows | LiveKit Docs
m
how to write tests for Tasks ?
t
I'd love to better understand what kind of tests you're hoping to write for Tasks. Are you thinking about: • Unit tests to check the logic of individual tasks? • Integration tests to see how tasks perform within the entire agent workflow? • Or maybe there are specific scenarios you're aiming to test? Knowing this will really help me offer you the most helpful and tailored advice. I'm here to support you every step of the way!
m
Tasks the new concept that is there how do i write tests for that ? Tasks that runs inside agent sessions ?
t
I'd love to help you write tests for LiveKit Tasks running inside Agent Sessions! Here's a friendly step-by-step guide to get you started: 1. Set Up Testing Environment: Begin by using
pytest
and
pytest-asyncio
for handling asynchronous tests smoothly. It’s a great idea to mock or simulate components like LLMs and sessions so you can create a controlled and predictable testing environment. 2. Test Task Logic: For tasks that run inline, try executing the task within a function and then check the returned result. For instance, you can verify that the task finishes with the expected output — it’s like confirming your task is doing exactly what it should! 3. Test Agent Integration: Here, you can use
AgentSession
to mimic how a user interacts with the system. Run the session with some user inputs and then assert the sequence of events, like function calls, messages, and task completions. This way, you ensure everything flows nicely together. 4. Validate Multi-Agent Workflows: If your tasks involve handing off between agents, make sure to check that the right agent transitions happen and that the task results are correctly passed along. This keeps your workflow seamless and reliable. 5. Capture Session Events: Don’t forget to use the
capture_run
parameter to catch any pre-emptive behaviors, such as messages generated during agent initialization. This helps you test those important early moments in the session. If you’d like, I can also provide an example test case tailored to a specific task or workflow you’re working on. Just let me know! Sources: Testing and evaluation | LiveKit Docs | examples/frontdesk/test_agent.py | Agent Testing & Evaluation | livekit/livekit_composite | DeepWiki