AI, AI Agents, Agentic AI... You can’t go a day without coming across at least one of these.
What exactly are they???
In today’s blog we’ll be looking at AI Agents, what they are, what they do and how to create one.
Let’s take them one by one.
AI (Artificial intelligence): AI or Artificial intelligence is the ability of of computer systems to perform tasks that normally require human intelligence, such as learning, problem-solving, decision making and recognizing patterns. You can see how that applies when using chatbots and LLMs like ChatGPT and Gemini. 1.
AI Agents: An AI Agent is a program that combines intelligence with the ability to act. It doesn’t just process information, it can take action using connected tools and systems, often without human intervention. Fo…
AI, AI Agents, Agentic AI... You can’t go a day without coming across at least one of these.
What exactly are they???
In today’s blog we’ll be looking at AI Agents, what they are, what they do and how to create one.
Let’s take them one by one.
AI (Artificial intelligence): AI or Artificial intelligence is the ability of of computer systems to perform tasks that normally require human intelligence, such as learning, problem-solving, decision making and recognizing patterns. You can see how that applies when using chatbots and LLMs like ChatGPT and Gemini. 1.
AI Agents: An AI Agent is a program that combines intelligence with the ability to act. It doesn’t just process information, it can take action using connected tools and systems, often without human intervention. For example, when you ask a regular AI chatbot to grab an article from some blog for you, it won’t be able to do that. That’s because these type of AI models only use data from their knowledge base to respond, they can’t visit websites or fetch data. That’s where AI Agents come into play they combine their intelligence and some “tools” they can use to make even tasks like checking the weather and planning your trip possible. 1.
Agentic AI: This is the framework or the broad concept of building AI Agents.
With that out of the way, let’s see how to build our own AI agent.
We will be building a very simple agent with a focus on understanding how these AI Agents work without all the complexity.
Also to make the process easy and follow a structured approach, we will be using Mastra. Mastra as they brand it is “The TypeScript Agent Framework”. It does all the work of connecting agents to tools and other agents without a hitch and ensure a clean workflow.
So, we will be build an AI agent that returns the current time.
As simple as that sounds, LLMs can’t do that by themselves.
So let’s get into it.
First things first,let’s set up our environment using mastra CLI.
npm create mastra@latest
Follow the CLI interface to setup a project, one your done you’ll have a starter project, then open it in your favorite Code Editor or IDE.
After that, grab your API key for the model you selected in the setup and add it to a .env file.
It’ll have this structure
src/mastra/
├── index.ts # Main Mastra configuration
├── agents/
│ └── weather-agent.ts # Example weather agent
'── tools/
└── weather-tool.ts # Example weather tool
Now let’s ignore the example project and build our own.
Create a time-tool.ts file in the tools/ directory and paste/write this.
import { createTool } from "@mastra/core/tools";
import { z } from "zod";
export const timeTool = createTool({
id: "get-time",
description: "Get current time for a location",
inputSchema: z.object({
timezone: z.string().describe("Timezone"),
}),
outputSchema: z.object({
output: z.string(),
}),
// The actual function that gets the time and returns it
execute: async ({ context }) => {
const options = { timeZone: context.timezone, hour: "2-digit", minute: "2-digit", second: "2-digit" };
const time = new Date().toLocaleTimeString("en-GB", options);
return {
output: time,
};
},
});
So basically, we’re expecting the LLM to send us a javascript format timezone, and then we get the time and return it to the model.
Next, we’ll create the Agent. Create a time-agent.ts file in the agents/ directory and paste/type this snippet:
import { Agent } from "@mastra/core/agent";
import { timeTool } from "../tools/time-tool";
export const timeAgent = new Agent({
name: "Time Agent",
instructions: `
You are a helpful time assistant that provides accurate time for a given timezone.
Your primary function is to help users get the current time for specific timezones. When responding:
- Always ask for a timezone if none is provided
- If provided with a location, infer its timezone
- If the location name isn't in English, please translate it
- If giving a timezone with multiple parts (e.g. "New York, NY"), use the most relevant part (e.g. "New York")
- Keep responses concise but informative
- Make sure to pass a javascript format timezone (e.g. Africa/Lagos)
Use the timeTool to fetch current time data.
`,
// Replace with your model
model: "google/gemini-2.5-pro",
tools: { timeTool },
});
Great, you just created your AI Agent and gave it instruction and how to use a “tool”.
- A tool is basically a function available to an Agent to get extra context/data.
Now let’s let Matra know about out Agent by registering it in the index.ts file.
import { Mastra } from "@mastra/core/mastra";
import { timeAgent } from "./agents/time-agent";
export const mastra = new Mastra({
agents: { timeAgent },
});
That’s literally it. Now Mastra knows about our agent and will provide us with a server and a UI to interact with our Agent via a chat interface.
Open your terminal and run
npm run dev
One the server is started visit http://localhost:4111 in your browser. You’ll your Time Agent, click on to open the chat page.
Here you can prompt it to get a time for a timezone, eg “What’s the time in Nigeria?”
And if you’ve done everything correctly, you should get a response from the Agent with the current time in the timezone you asked for.
Congrats🎉, you just build a working AI Agent to solve the problem of AI not knowing the current time.
I hope you learnt a thing or two. Now that you know how to build AI Agents, the sky is your limit.
Go build something awesome.
If you enjoyed the blog, drop a follow and check me out on Youtube.
Thanks for reading.