Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions livekit-agents/livekit/agents/beta/workflows/dob.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ async def update_dob(year: int, month: int, day: int, ctx: RunContext) -> str |
async def _update_dob_impl(
self, year: int, month: int, day: int, ctx: RunContext
) -> str | None:
# Normalize two-digit years to the intended century, matching what the
# prompt already asks the model to do ("90" -> 1990, "05" -> 2005). A
# literal two-digit year is otherwise a valid date (e.g. 90 -> year 90 AD)
# that passes the future-date check and silently corrupts the result.
if 0 <= year < 100:
current_yy = date.today().year % 100
year += 2000 if year <= current_yy else 1900

try:
dob = date(year, month, day)
except ValueError as e:
Expand Down
32 changes: 32 additions & 0 deletions tests/test_dob.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from datetime import date

import pytest

from livekit.agents import beta

pytestmark = pytest.mark.unit


@pytest.mark.asyncio
async def test_dob_two_digit_year_normalized() -> None:
# The prompt asks the model to normalize two-digit years, but smaller/faster
# models often pass the spoken value through literally. The tool layer must not
# accept "90" as year 90 AD. https://github.com/livekit/agents/issues/6067
task = beta.workflows.GetDOBTask(require_confirmation=True)

await task._update_dob_impl(90, 5, 15, ctx=None) # type: ignore[arg-type]
assert task._current_dob == date(1990, 5, 15)

await task._update_dob_impl(5, 3, 1, ctx=None) # type: ignore[arg-type]
assert task._current_dob == date(2005, 3, 1)


@pytest.mark.asyncio
async def test_dob_four_digit_year_unchanged() -> None:
task = beta.workflows.GetDOBTask(require_confirmation=True)

await task._update_dob_impl(1962, 7, 4, ctx=None) # type: ignore[arg-type]
assert task._current_dob == date(1962, 7, 4)

await task._update_dob_impl(2001, 12, 31, ctx=None) # type: ignore[arg-type]
assert task._current_dob == date(2001, 12, 31)