numerous-whale-53652
09/15/2025, 9:51 AMtall-airline-16756
09/15/2025, 9:51 AMtall-airline-16756
09/15/2025, 9:51 AMGetEmailTask in LiveKit, which is thoughtfully designed to handle email collection, including validation and user confirmation.
Here’s a simple way to get started:
1. In your agent, use the GetEmailTask to kick off the email collection process. For example:
from livekit.agents.beta.workflows import GetEmailTask
email_result = await GetEmailTask(chat_ctx=self.chat_ctx)
print(f"Collected email: {email_result.email_address}")
This task will patiently wait for the user to provide and confirm their email address.
On the front end, just make sure the user’s input (whether speech or text) is sent over to LiveKit. For text input, you can use the sendText method on the room’s local participant. Here’s a quick example:
// JavaScript Example
const text = "My email is john@example.com";
await room.localParticipant.sendText(text, "lk.chat");
If you have any questions or need a hand with the setup, please don’t hesitate to reach out—I’m here to help!
Sources: Workflows | LiveKit Docs | examples/frontdesk/test_agent.py | Docs::Agentsnumerous-whale-53652
09/15/2025, 12:41 PMtall-airline-16756
09/15/2025, 12:42 PMRuntimeError: cannot schedule new speech, the speech scheduling is draining/pausing. This happens when the agent's speech scheduling system is in a draining or paused state, which usually occurs during transitions like handoffs or when the agent is being paused or shut down.
Here are some steps that can help you resolve this:
1. Try to avoid scheduling speech actions (such as say() or generate_reply()) while the agent is draining or paused. It’s best to initiate speech actions only when the agent is fully active.
2. If you need a tool to respond during draining, it’s safer to use the agent’s built-in tool response mechanism, which is designed to handle this smoothly.
3. When managing the agent’s lifecycle programmatically, please wait for the current activity to finish draining before starting any new speech actions.
4. Also, avoid scheduling additional speech after a handoff has started, since the system pauses speech scheduling to complete the handoff properly.
If any of this feels unclear or if you’d like some help implementing these steps, please don’t hesitate to reach out. I’m here to support you!
Sources: livekit-agents/livekit/agents/voice/speech_handle.pynumerous-whale-53652
09/15/2025, 12:45 PMtall-airline-16756
09/15/2025, 12:45 PMfrom livekit.agents.beta.workflows import GetEmailTask
from livekit.agents.voice.agent_tools import function_tool
class EmailCollectionAgent:
@function_tool
async def collect_user_email(self, context):
try:
# Use GetEmailTask to collect the email from the user
email_result = await GetEmailTask(chat_ctx=self.chat_ctx)
email_address = email_result.email_address
# Return a confirmation message
return f"Thank you! Collected email: {email_address}"
except RuntimeError as e:
# Handle speech scheduling errors or other runtime issues
if "speech scheduling is draining/pausing" in str(e):
return "Unable to collect email at the moment due to agent state. Please try again later."
else:
raise e
except Exception as e:
# Handle any other exceptions
return f"An error occurred: {str(e)}"
This tool thoughtfully uses the GetEmailTask to collect and validate the user's email address. It also includes careful error handling for speech scheduling issues and other unexpected exceptions.
If you'd like, I'm here to help with any further customization or to add additional features to make this tool fit your needs perfectly. Just let me know!numerous-whale-53652
09/15/2025, 12:46 PMtall-airline-16756
09/15/2025, 12:46 PM@function_tool decorator to define tools either within an agent class or as standalone functions. By default, the function's name and docstring become the tool's name and description. Here's a simple example to get you started:
from livekit.agents import function_tool, Agent, RunContext
class MyAgent(Agent):
@function_tool()
async def lookup_weather(self, context: RunContext, location: str) -> dict:
"""Look up weather information for a given location."""
return {"weather": "sunny", "temperature_f": 70}
• Node.js: You can define tools directly in the agent configuration using llm.tool(). Here's an example that might help:
const getWeather = llm.tool({
description: 'Called when the user asks about the weather.',
parameters: z.object({
location: z.string().describe('The location to get the weather for'),
}),
execute: async ({ location }, { ctx }) => {
return `The weather in ${location} is sunny today.`;
},
});
const agent = new voice.Agent({
instructions: 'You are a helpful assistant.',
tools: { getWeather },
});
Both of these approaches give you access to the agent's state via RunContext and support dynamic updates to your tools. If you'd like me to walk you through this further or provide more examples, just let me know—I'm here to help!
Sources: Tool definition and use | LiveKit Docs | Agents 0.x migration guide | LiveKit Docs | Agents v0.x migration guide - Node.js | LiveKit Docsnumerous-whale-53652
09/15/2025, 1:50 PMtall-airline-16756
09/15/2025, 1:51 PM<input id="email" type="email" name="email" placeholder="Enter your email address" required />
Once they submit their email, you can store it in your application’s state and then connect them to the LiveKit room. This can also tie in smoothly with your authentication flow.
1. Voice Agent Workflow: Another great option is to use the GetEmailTask from LiveKit’s Agents SDK, which prompts the user via voice and even handles validating and confirming the email address for you.
If you'd like, I can provide a detailed code example for either method or assist you further—just let me know! I’m here to help.
Sources: Building the all-in-one platform for voice AI agents | client/components/login-form.tsx | livekit-agents/livekit/agents/beta/workflows/email_address.py | flows/declarative_flow.py