Skip to main content

GetDOBTask

Collect and validate a date of birth from the user with spoken date handling.

Available in
Beta
|
Python

Overview

Use GetDOBTask to collect a user's date of birth with support for various spoken and written date formats. The task validates the date and optionally collects a time of birth.

GetDOBTask handles the following:

  • Normalization of spoken dates in formats like "January fifteenth, nineteen ninety" or "01 15 1990."
  • Conversion of spoken ordinals and numbers to their numeric form.
  • Handling of two-digit years (for example, "90" becomes 1990).
  • Validation that the date is not in the future.
  • Optional collection of time of birth.

The task returns a GetDOBResult data class with two fields: date_of_birth (datetime.date) and time_of_birth (datetime.time | None).

Basic usage

For a basic example, see the following code snippet:

from livekit.agents.beta.workflows import GetDOBTask
# ... within your agent ...
dob_result = await GetDOBTask(chat_ctx=self.chat_ctx)
print(f"Date of birth: {dob_result.date_of_birth}")

Usage with time of birth

Enable time collection for use cases like birth records or astrology applications:

from livekit.agents.beta.workflows import GetDOBTask
from livekit.agents import function_tool, RunContext
@function_tool()
async def collect_birth_info(context: RunContext) -> str:
"""Collect the user's date and time of birth"""
dob_result = await GetDOBTask(
include_time=True,
chat_ctx=context.session.chat_ctx,
)
result = f"Date of birth: {dob_result.date_of_birth}"
if dob_result.time_of_birth:
result += f", Time: {dob_result.time_of_birth}"
return result

Parameters

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

include_timeboolDefault: False

Whether to also ask for and collect the user's time of birth. The time is optional for the user even when enabled.

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 date 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.