Yash Sharma

Apr 07, 2026 • 2 min read

Creating an AI Agent in TS: Beyond the Hype 🚀

An introduction to building type-safe, modular AI agents with TypeScript and Mastra.

Creating an AI Agent in TS: Beyond the Hype 🚀

We hear the term "Agentic" everywhere. Some are sophisticated; most are just simple wrappers. I’ve spent the last few months building Gemoniq, and I’ve learned that the secret isn't just a better prompt, but also a better architecture.


Today, I want to show you how to set up a basic AI agent in TypeScript using Mastra. It’s the library we use to power Gemoniq because it’s type-safe and incredibly straightforward.


1. Setting up the project

Refer this manual install doc https://mastra.ai/docs/getting-started/manual-install, till step 3 to manually install the required packages. This would prevent unnecessary bloat for now.


2. Writing our first agent

Let’s create a new agent. We’ll name it "Leo."

mkdir -p src/mastra/agents && touch src/mastra/agents/leo.ts

Don't forget to add the API Key for your model in .env.

ANTHROPIC_API_KEY=<your-api-key>
GOOGLE_GENERATIVE_AI_API_KEY=<your-api-key>
OPENAI_API_KEY=<your-api-key>

3. The Index File

Now lets setup the index file in mastra folder, the central place to export our agents.

touch src/mastra/index.ts

4. Running the agent

Lets create a new file to run this agent.

touch agentRunner.ts

Ensure that we include ".ts" in the include field in tsconfig.json, to compile it before running the file.

Finally, run the following command in the terminal:

npx tsx --env-file=.env agentRunner.ts

And that is it, you created a very basic agent. Next steps would be to add memory to the agent, then some tools, workflows and skills. I'll be writing about that as well very soon.

🔗 Github link: https://github.com/yashsharmafastlane/agent-intro

We launched our project this week! 🚀 If you want to see how such agents are performing in production, check us out here:

https://peerlist.io/fastlanedevs/project/gemoniq--aipowered-marketing-agency

Goes without saying, any support or feedback is highly appreciated.

Join Yash on Peerlist!

Join amazing folks like Yash and thousands of other builders on Peerlist.

peerlist.io/

It’s available... this username is available! 😃

Claim your username before it's too late!

This username is already taken, you’re a little late.😐

0

0

0