Custom Datetime Format

Customize the datetime format injected into the agent's system context.

datetime_format.py
"""
Custom Datetime Format
======================

Customize the datetime format injected into the agent's system context.
"""

from agno.agent import Agent
from agno.models.openai import OpenAIResponses

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
    model=OpenAIResponses(id="gpt-5-mini"),
    add_datetime_to_context=True,
    datetime_format="%Y-%m-%dT%H:%M:%SZ",  # ISO 8601 format in UTC (e.g., 2026-03-09T14:30:00Z)
    timezone_identifier="US/Eastern",
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    agent.print_response("What is the current time and timezone?", stream=True)

Use the matching timezone

Before running, change timezone_identifier="US/Eastern" to timezone_identifier="UTC" in the Agent constructor. The format contains a literal Z, which denotes UTC; it does not convert an Eastern timestamp. To keep Eastern time instead, use datetime_format="%Y-%m-%dT%H:%M:%S%z" to include its numeric offset.

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno openai

Export your OpenAI API key

export OPENAI_API_KEY="your_openai_api_key_here"

Run the example

Save the code above as datetime_format.py, then run:

python datetime_format.py

Full source: cookbook/02_agents/03_context_management/datetime_format.py