How can I make my agent stop hallucinating dates and know the current date?

I am using a realtime openai model and in order for it to know the date I did this :

current_date = datetime.datetime.now(ZoneInfo(“America/Toronto”)).strftime(

"%A %d %B %Y"

)

garage_context = ChatContext()

garage_context.add_message(

    role="system",

    content=f"La date d'aujourd'hui est la suivante : {current_date}",

)

But it doesn’t seem to work

@Keynar, The issue is that creating a ChatContext() locally and adding a message doesn’t seed the session. The context has to be passed to the Agent constructor
[ Chat context | LiveKit Documentation ], otherwise the session never sees it.

For a static daily date, the cleanest fix is putting it directly in the Agent’s instructions:

  from datetime import datetime
  from zoneinfo import ZoneInfo
  from livekit.agents import Agent

  current_date = datetime.now(ZoneInfo("America/Toronto")).strftime("%A %d %B %Y")

  class GarageAgent(Agent):
      def __init__(self):
          super().__init__(
              instructions=f"""You are a helpful assistant.
  La date d'aujourd'hui est : {current_date}.""",
          )

  For long sessions (across midnight, or where you need fresh time-of-day), a function_tool is more robust because the model fetches the date only when
  needed and never serves a stale value:

  from livekit.agents import function_tool

  class GarageAgent(Agent):
      @function_tool()
      async def get_current_date(self) -> str:
          """Returns today's date in Toronto local time."""
          return datetime.now(ZoneInfo("America/Toronto")).strftime("%A %d %B %Y")

The model will call this whenever the user asks about the date. Function Tools

Thanks man that’s awesome, thank you for your answer !