Skip to main content

GetNameTask

Collect and validate a user's name from noisy voice transcription or text input.

Available in
Beta
|
Python

Overview

Use GetNameTask to collect a user's name with configurable parts. The task handles first, middle, and last names independently, with built-in support for noisy voice transcription.

GetNameTask handles the following:

  • Configurable collection of first, middle, and last name parts.
  • Normalization of spoken name patterns, including letter-by-letter spelling and phonetic alphabet input.
  • Conversion of words like "dash" and "apostrophe" into symbols (-, ').
  • Optional spelling verification where the agent spells back each name part letter by letter.
  • Culturally diverse name patterns and special characters.

The task returns a GetNameResult data class with three optional fields: first_name, middle_name, and last_name. Only the fields you configure for collection are populated.

Basic usage

For a basic example, see the following code snippet:

from livekit.agents.beta.workflows import GetNameTask
# ... within your agent ...
name_result = await GetNameTask(
first_name=True,
last_name=True,
chat_ctx=self.chat_ctx,
)
print(f"Collected name: {name_result.first_name} {name_result.last_name}")

Usage with spelling verification

Enable spelling verification to have the agent spell back the name letter by letter before confirming:

from livekit.agents.beta.workflows import GetNameTask
from livekit.agents import function_tool, RunContext
@function_tool()
async def collect_patient_name(context: RunContext) -> str:
"""Collect the patient's full name with spelling verification"""
name_result = await GetNameTask(
first_name=True,
last_name=True,
verify_spelling=True,
chat_ctx=context.session.chat_ctx,
extra_instructions="This is for a medical record, so accuracy is critical.",
)
return f"Patient name recorded: {name_result.first_name} {name_result.last_name}"

Parameters

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

first_nameboolDefault: True

Whether to collect the user's first name.

last_nameboolDefault: False

Whether to collect the user's last name.

middle_nameboolDefault: False

Whether to collect the user's middle name.

name_formatstring

Custom format string for the name parts. Uses {first_name}, {middle_name}, and {last_name} placeholders. Defaults to the enabled parts joined by spaces.

verify_spellingboolDefault: False

Whether to verify the spelling of the name by reading it back letter by letter.

extra_instructionsstringDefault: ""

Additional instructions to append to the task's default instructions.

chat_ctxChatContext

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.

require_confirmationbool

Whether to read the name back to the user to confirm it before finalizing the task. For audio sessions this defaults to True, for text it defaults to False.

toolslist

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