Skip to main content

GetEmailTask

Collect and validate an email address from the user with noisy voice transcription handling.

Available in
Beta
|
Python

Overview

Use GetEmailTask to reliably collect and validate an email address from the user.

GetEmailTask handles the following:

  • Noisy voice transcription and normalizes spoken email patterns.
  • Conversion of words like "dot," "underscore," "dash," "plus" into symbols (., _, -, +).
  • Recognition of patterns where users spell out words (for example, "john j o h n").

The task returns a GetEmailResult data class with one field: email_address.

Basic usage

For a basic example, see the following code snippet:

from livekit.agents.beta.workflows import GetEmailTask
# ... within your agent ...
email_result = await GetEmailTask(chat_ctx=self.chat_ctx)
print(f"Collected email: {email_result.email_address}")

Custom implementation

By default GetEmailTask calls its decline_email_capture() tool when the user doesn't provide an email address. The following example customizes the task to instead collect alternative contact information:

from livekit.agents.beta.workflows import GetEmailTask
from livekit.agents import function_tool, RunContext
@function_tool()
async def get_alternate_contact_info(context: RunContext, contact_method: str, contact_value: str) -> None:
"""Collect alternative contact information when email isn't available"""
# Store the alternative contact info
context.session.userdata.alternate_contact_method = contact_method
context.session.userdata.alternate_contact_value = contact_value
await context.session.generate_reply(
instructions=f"Acknowledge that you've recorded their {contact_method}: {contact_value}. Let them know this will be used for communication instead of email."
)
# Customize GetEmailTask with extra instructions and tools
# ... within your agent ...
@function_tool()
async def collect_contact_info(context: RunContext) -> str:
"""Collect email or alternative contact information"""
email_result = await GetEmailTask(
chat_ctx=context.session.chat_ctx,
extra_instructions="If the user cannot provide an email, call get_alternate_contact_info() instead of decline_email_capture().",
tools=[get_alternate_contact_info]
)
return f"Collected email: {email_result.email_address}"

Parameters

For a full list of parameters, see the GetEmailTask reference.

extra_instructionsstringOptional

Additional instructions to append to the task's default instructions. Use this to customize behavior for specific use cases.

chat_ctxChatContextOptional

The conversation history the task-specific LLM sees. If you omit it, the task runs with an empty context, with no memory of what was said earlier in the session. Pass the primary agent's chat context so the task can refer to prior turns and, when used inside a task group, so exchanges are summarized back into the main context.

toolslistOptional

Additional tools available to the task. Use this to add or substitute function tools.