Building a Programming Joke Agent with Mastra and Telex.im

Building a Programming Joke Agent with Mastra and Telex.im
I built an AI-powered programming joke agent that integrates with Telex.im (a Slack-like platform for education) using Mastra as the agent framework.
This post walks through how I built, integrated, and deployed it to Mastra Cloud, including the challenges I faced and lessons learned along the way.
The Concept
The idea was simple but fun:
Create an AI agent that delivers clean, witty programming jokes on demand.
Users can say things like:
- "Hi, what do you do?"
- "Tell me a programming joke."
- "Give me something funny to start the day."
The agent detects user intent, fetches a random clean programming joke from JokeAPI, and replies instantly with no overthinking, no explanations, just humor.
Tech Stack
| Component | Description |
|---|---|
| Framework | Mastra (v0.17.7) for AI orchestration |
| Language | TypeScript |
| Model | Google Gemini 2.0 Flash Lite |
| Protocol | A2A (Agent-to-Agent) |
| Platform | Telex.im |
| Deployment | Mastra Cloud |
Setting Up the Project
Folder Structure
dev-ai-agent/
├── src/
│ └── mastra/
│ ├── agents/
│ │ └── joke-agent.ts
│ ├── tools/
│ │ └── joke-tool.ts
│ ├── routes/
│ │ └── a2a-agent-route.ts
│ └── index.ts
├── package.json
└── tsconfig.json
Dependencies
{
"dependencies": {
"@mastra/core": "^0.23.3",
"@mastra/memory": "latest",
"@mastra/libsql": "latest",
"dotenv": "^17.2.3",
"zod": "^4.1.12"
},
"devDependencies": {
"@types/node": "^24.9.2",
"mastra": "^0.17.7",
"typescript": "^5.9.3"
}
}
Building the Joke Tool
The Joke Tool is a simple utility that calls the JokeAPI to fetch a random, clean programming joke.
Implementation
export const jokeTool = createTool({
id: "get-joke",
description: "Fetch a safe, random programming joke from JokeAPI",
inputSchema: z.object({}),
outputSchema: z.object({
joke: z.string().describe("The programming joke"),
}),
execute: async () => {
const res = await fetch(
"https://v2.jokeapi.dev/joke/Programming?blacklistFlags=nsfw,religious,political,racist,sexist,explicit&type=single"
);
const data = await res.json();
if (data.error) throw new Error("JokeAPI error");
return { joke: data.joke };
},
});
Creating the AI Agent
The Joke Agent wraps the tool and handles user interaction naturally.
Implementation
export const jokeAgent = new Agent({
name: "Joke Agent",
instructions: `
You are a friendly programming comedian.
- Deliver ONE clean programming joke per request.
- If the user greets you, respond warmly and invite them to ask for a joke.
- Always use the 'get-joke' tool to fetch a new joke.
- Return only the joke with no explanations or commentary.
`,
model: "google/gemini-2.0-flash-lite",
tools: { jokeTool },
memory: new Memory({
storage: new LibSQLStore({
url: "file:../mastra.db",
}),
}),
})
This makes the agent conversational: it understands greetings and guides users toward asking for a joke.
Integrating with the A2A Protocol
The A2A Route Handler is the bridge that lets Telex.im communicate with Mastra agents via JSON-RPC 2.0.
It ensures requests and responses stay properly formatted, with clear artifacts and history tracking.
Once added to src/mastra/routes/a2a-agent-route.ts, it makes the agent reachable at this public endpoint:
https://harsh-noisy-restaurant.mastra.cloud/a2a/agent/jokeAgent
Testing the Agent
I tested the agent both on:
- Mastra Playground: http://localhost:4111/
- Telex.im Sandbox: using workflow integration
Example test payload
{
"jsonrpc": "2.0",
"id": "test-123",
"method": "message/send",
"params": {
"message": {
"kind": "message",
"role": "user",
"parts": [
{ "kind": "text", "text": "Tell me a programming joke" }
]
}
}
}
Deployment to Mastra Cloud
Deploying was seamless:
- Pushed my repo to GitHub
- Connected it to Mastra Cloud
- Deployed with a few clicks
Final endpoint:
https://harsh-noisy-restaurant.mastra.cloud/a2a/agent/jokeAgent
Telex.im Integration
I connected the agent to Telex.im using this workflow configuration:
{
"active": true,
"category": "fun",
"description": "A workflow that delivers clean programming jokes on demand.",
"id": "joke_agent_workflow_001",
"name": "joke_agent",
"nodes": [
{
"id": "joke_agent_node",
"name": "Joke Agent",
"type": "a2a/mastra-a2a-node",
"url": "https://harsh-noisy-restaurant.mastra.cloud/a2a/agent/jokeAgent"
}
],
"settings": { "executionOrder": "v1" }
}
Once live, the agent responds directly in any Telex.im chat connected to this workflow.
Challenges and Lessons Learned
-
Handling natural prompts: Users don't always say "Tell me a joke." Some just say "Hi." I refined the agent's instructions so it recognizes greetings and encourages the user to ask for a joke.
-
A2A format debugging: Understanding how Telex expected artifacts and messages took a bit of trial and error. Logs from Telex were key in debugging that.
-
Joke consistency: The JokeAPI sometimes returns errors or empty responses, so I added graceful fallback handling to avoid awkward replies.
What Worked Well
- Mastra's simplicity for building AI logic
- Zod schemas for strict tool validation
- Seamless Mastra Cloud deployment
- Telex.im's real-time integration
Conclusion
This project showed how fun and flexible the Mastra agent framework can be, from a simple idea to a fully functional integration with Telex.im.
It's lightweight, extensible, and surprisingly expressive for creative projects like this one.
Project Repo: github.com/dubemdaniel/Dev-AI-Agent
Live Agent: harsh-noisy-restaurant.mastra.cloud/a2a/agent/jokeAgent
Resources
- Mastra Documentation
- Telex.im
- JokeAPI
- Built as part of HNG13 Stage 3 Backend Track
→ Learn more about the HNG Internship

Daniel Chukwudubem
Software engineer passionate about building great products.