microscopic-dress-75199
10/01/2025, 1:44 AMtall-airline-16756
10/01/2025, 1:44 AMtall-airline-16756
10/01/2025, 1:44 AMmicroscopic-dress-75199
10/01/2025, 1:46 AMtall-airline-16756
10/01/2025, 1:46 AMAgentTask 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 Docsmicroscopic-dress-75199
10/01/2025, 1:49 AMtall-airline-16756
10/01/2025, 1:49 AMmicroscopic-dress-75199
10/01/2025, 1:50 AMtall-airline-16756
10/01/2025, 1:50 AMmicroscopic-dress-75199
10/01/2025, 1:53 AMtall-airline-16756
10/01/2025, 1:54 AMGetEmailTask. 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:
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 Docsmicroscopic-dress-75199
10/01/2025, 1:55 AMtall-airline-16756
10/01/2025, 1:56 AMupdate_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.pymicroscopic-dress-75199
10/01/2025, 2:02 AMtall-airline-16756
10/01/2025, 2:03 AMGetEmailTask 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.yamlmicroscopic-dress-75199
10/01/2025, 2:04 AMtall-airline-16756
10/01/2025, 2:04 AMGetEmailTask 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 Docsmicroscopic-dress-75199
10/01/2025, 2:45 AMtall-airline-16756
10/01/2025, 2:46 AMmicroscopic-dress-75199
10/01/2025, 2:46 AMtall-airline-16756
10/01/2025, 2:47 AMpytest 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