datetime_format.py
Run the Example
1
Set up your virtual environment
2
Install dependencies
3
Export your OpenAI API key
4
Run the example
Save the code above as
datetime_format.py, then run:Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Customize the datetime format injected into the agent’s system context.
"""
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)
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
Install dependencies
uv pip install -U agno openai
Export your OpenAI API key
export OPENAI_API_KEY="your_openai_api_key_here"
$Env:OPENAI_API_KEY="your_openai_api_key_here"
Run the example
datetime_format.py, then run:python datetime_format.py
Was this page helpful?