English 繁體中文 简体中文

How to create a time tool for an AI agent?

Howard Pong Yuen Lam · AI Notes · November 8, 2026 · 3 min read

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

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

Further reading