How to create a time tool for an AI agent?
An AI agent can plan, draft and reason, but it cannot know the current time and date. Its sense of “now” comes from the text it was trained on, so when you ask for today's date it may tell you to check for yourself. Anything that depends on time stays unreliable until the agent is given a way to look.
A tool is that way: an ordinary function the agent is allowed to call. This note builds the smallest useful tool there is — one function that returns the current date and time — and tests it before any agent is involved. The whole tool is nine lines of Python.
The tool
This is tool01_time.py as it stands:
from datetime import datetime
def get_current_time():
"""
Returns the current date and time as a string.
"""
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
result = get_current_time()
print(result)
What each part does
datetimecomes with Python, so there is nothing to install.get_current_time()takes no arguments. That is deliberate: a tool with no arguments is the easiest kind for a model to call correctly.- The docstring is not decoration. When the function is offered to an agent, this sentence becomes the description the model reads before deciding whether to call it. “Returns the current date and time as a string” says both what comes back and when the tool is worth calling.
strftime— short for string format time — turns the datetime into text, andstrftime("%Y-%m-%d %H:%M:%S")fixes the format, for example2026-11-08 14:32:07. A fixed format matters, because the model will quote the value to the user and may split it into date and time.- The last two lines call the function and print the result, so the tool can be checked from a terminal before any agent is involved.
Test it on its own
Run the file:
python tool01_time.py
You should see a single line, for instance 2026-11-08 14:32:07.
This is the clock of the computer that runs the script. If the script sits on a
server in another region, you get the server's local time, not yours.
Why this is a good first tool
- No arguments, so there is nothing for the model to get wrong.
- Read-only: it cannot change a file, send a message or spend money.
- Easy to verify: compare the answer with the clock on your own screen.
- Immediately useful: it repairs every date-sensitive answer the agent gives.
Further reading
- datetime — Python documentation —
now()andstrftime().