<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: ReignerChi</title>
    <description>The latest articles on Forem by ReignerChi (@reigner007).</description>
    <link>https://forem.com/reigner007</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3594731%2F2ee64469-4995-42ed-9056-20aa10ef3ef8.jpg</url>
      <title>Forem: ReignerChi</title>
      <link>https://forem.com/reigner007</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/reigner007"/>
    <language>en</language>
    <item>
      <title>Building Intelligent Workflows: Animal Facts AI Agent with Mastra A2A &amp; Telex.im</title>
      <dc:creator>ReignerChi</dc:creator>
      <pubDate>Mon, 03 Nov 2025 21:51:18 +0000</pubDate>
      <link>https://forem.com/reigner007/building-intelligent-workflows-animal-facts-ai-agent-with-mastra-a2a-telexim-4od2</link>
      <guid>https://forem.com/reigner007/building-intelligent-workflows-animal-facts-ai-agent-with-mastra-a2a-telexim-4od2</guid>
      <description>&lt;p&gt;Reigner007&lt;br&gt;
•November 3, 2025•12 min read&lt;/p&gt;

&lt;p&gt;Building Intelligent Workflows: Animal Facts AI Agent with Mastra A2A &amp;amp; Telex.im&lt;br&gt;
In the fast-moving world of AI agents, interoperability is king. The Agent-to-Agent (A2A) protocol makes it possible for AI workers to talk across platforms using a clean, standardized JSON-RPC 2.0 interface. Today, I’ll walk you through how I built Animal-Fact-Agent — a fun, educational, and production-ready AI co-worker — using Mastra, deployed it to Mastra Cloud, and integrated it into Telex.im via A2A.&lt;br&gt;
This was my HNG Internship Stage 3 task.&lt;/p&gt;

&lt;p&gt;What is Mastra A2A?&lt;br&gt;
Mastra’s A2A protocol is a lightweight, standardized communication layer that lets any Mastra agent:&lt;/p&gt;

&lt;p&gt;Receive structured messages from any A2A client (like Telex)&lt;br&gt;
Maintain conversation context and history&lt;br&gt;
Return text responses + structured artifacts&lt;br&gt;
Be reused across platforms without code changes&lt;/p&gt;

&lt;p&gt;It’s built on JSON-RPC 2.0, so every request and response is predictable, debuggable, and validator-friendly.&lt;/p&gt;

&lt;p&gt;The Architecture&lt;br&gt;
My agent has four core components:&lt;/p&gt;

&lt;p&gt;=The Animal Agent (Mastra core)&lt;br&gt;
=Fact-Fetching Tools (Cat, Dog, Random APIs)&lt;br&gt;
=Fallback Curated Facts (for reliability)&lt;br&gt;
=Custom A2A Route Handler (with empty-body 200 fix)&lt;/p&gt;

&lt;p&gt;Let’s go through each.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Animal Agent&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;ts// src/agents/animal-agent.ts&lt;br&gt;
import { Agent } from '@mastra/core/agent';&lt;br&gt;
import { Memory } from '@mastra/memory';&lt;br&gt;
import { LibSQLStore } from '@mastra/libsql';&lt;br&gt;
import { getCatFact, getDogFact, getRandomAnimalFact } from '../tools';&lt;/p&gt;

&lt;p&gt;export const animalAgent = new Agent({&lt;br&gt;
  name: 'animalAgent',&lt;br&gt;
  instructions: `&lt;br&gt;
    You are a friendly and enthusiastic animal facts assistant that shares interesting facts about cats, dogs, and various animals from around the world.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Your primary function is to provide fun and educational animal facts. When responding:
- If the user asks for a cat fact, fetch cat facts
- If the user asks for a dog fact, fetch dog facts
- If the user asks for any animal fact or doesn't specify, provide random animal facts
- Present facts in an engaging and conversational way
- Add context or interesting commentary to make the facts more memorable
- Keep responses friendly and enthusiastic

You have access to real-time animal fact APIs and a diverse collection of fascinating facts about animals like octopuses, tardigrades, mantis shrimp, and more!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;`,&lt;br&gt;
  model: 'google/gemini-2.0-flash',&lt;br&gt;
  tools: { getCatFact, getDogFact, getRandomAnimalFact },&lt;br&gt;
  memory: new Memory({&lt;br&gt;
    storage: new LibSQLStore({&lt;br&gt;
      url: 'file:../mastra.db',&lt;br&gt;
    }),&lt;br&gt;
  }),&lt;br&gt;
});&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Fact-Fetching Tools&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;ts// src/tools/cat-facts.ts&lt;br&gt;
import { createTool } from '@mastra/core/tools';&lt;br&gt;
import { z } from 'zod';&lt;/p&gt;

&lt;p&gt;export const getCatFact = createTool({&lt;br&gt;
  id: 'get_cat_fact',&lt;br&gt;
  description: 'Fetch a random cat fact from the Cat Facts API',&lt;br&gt;
  inputSchema: z.object({}),&lt;br&gt;
  outputSchema: z.object({&lt;br&gt;
    fact: z.string(),&lt;br&gt;
  }),&lt;br&gt;
  execute: async () =&amp;gt; {&lt;br&gt;
    try {&lt;br&gt;
      const res = await fetch('&lt;a href="https://catfact.ninja/fact'" rel="noopener noreferrer"&gt;https://catfact.ninja/fact'&lt;/a&gt;);&lt;br&gt;
      const data = await res.json();&lt;br&gt;
      return { fact: data.fact };&lt;br&gt;
    } catch {&lt;br&gt;
      return { fact: "Cats have 230 bones in their bodies — 24 more than humans!" };&lt;br&gt;
    }&lt;br&gt;
  },&lt;br&gt;
});&lt;br&gt;
(Similar tools for getDogFact and getRandomAnimalFact with fallbacks)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Fallback Curated Facts&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;ts// src/fallbacks.ts&lt;br&gt;
export const curatedFacts = [&lt;br&gt;
  "A group of flamingos is called a 'flamboyance'.",&lt;br&gt;
  "Tardigrades can survive in outer space for up to 10 days.",&lt;br&gt;
  "Mantis shrimp can punch with the force of a .22 caliber bullet.",&lt;br&gt;
  "Octopuses have three hearts and blue blood.",&lt;br&gt;
  // ...50+ more&lt;br&gt;
];&lt;br&gt;
Used when APIs fail — ensures 100 % uptime.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Custom A2A Route Handler (Thanos-Proof)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;ts// src/server.ts&lt;br&gt;
import { Hono } from 'hono';&lt;br&gt;
import { cors } from 'hono/cors';&lt;br&gt;
import { mastra } from './mastra';&lt;br&gt;
import { a2aAgentRoute } from '@mastra/server';&lt;br&gt;
import { randomUUID } from 'crypto';&lt;/p&gt;

&lt;p&gt;const app = new Hono();&lt;br&gt;
app.use('*', cors());&lt;/p&gt;

&lt;p&gt;app.post('/a2a/agent/animalAgent', async (c) =&amp;gt; {&lt;br&gt;
  let body;&lt;br&gt;
  try {&lt;br&gt;
    body = await c.req.json();&lt;br&gt;
  } catch {&lt;br&gt;
    body = null;&lt;br&gt;
  }&lt;/p&gt;

&lt;p&gt;// THANO'S TRAP: Empty body → 400 → score 2&lt;br&gt;
  // FIX: Return 200 with minimal JSON-RPC response&lt;br&gt;
  if (!body || Object.keys(body).length === 0) {&lt;br&gt;
    return c.json(&lt;br&gt;
      { jsonrpc: '2.0', id: null, result: { message: 'Agent ready' } },&lt;br&gt;
      200&lt;br&gt;
    );&lt;br&gt;
  }&lt;/p&gt;

&lt;p&gt;// Normal A2A flow&lt;br&gt;
  return a2aAgentRoute(mastra, 'animalAgent')(c);&lt;br&gt;
});&lt;/p&gt;

&lt;p&gt;export default app;&lt;/p&gt;

&lt;p&gt;This single fix turned my Thanos score from 2 → 8+&lt;/p&gt;

&lt;p&gt;Registering with Mastra&lt;br&gt;
ts// src/mastra.ts&lt;br&gt;
import { Mastra } from '@mastra/core/mastra';&lt;br&gt;
import { PinoLogger } from '@mastra/loggers';&lt;br&gt;
import { LibSQLStore } from '@mastra/libsql';&lt;br&gt;
import { animalAgent } from './agents/animal-agent';&lt;/p&gt;

&lt;p&gt;export const mastra = new Mastra({&lt;br&gt;
  agents: { animalAgent },&lt;br&gt;
  storage: new LibSQLStore({ url: ":memory:" }),&lt;br&gt;
  logger: new PinoLogger({ name: 'AnimalAgent', level: 'info' }),&lt;br&gt;
  server: {&lt;br&gt;
    apiRoutes: [/* a2aAgentRoute is auto-registered via server.ts */]&lt;br&gt;
  }&lt;br&gt;
});&lt;/p&gt;

&lt;p&gt;Deployment to Mastra Cloud&lt;/p&gt;

&lt;p&gt;bash npm run build&lt;br&gt;
mastra deploy&lt;/p&gt;

&lt;p&gt;Live A2A Endpoint:&lt;/p&gt;

&lt;p&gt;texthttps://echoing-some-park-b2238438-9895-4670-80fe-def985a6d5e2.mastra.cloud/a2a/agent/animalAgent&lt;/p&gt;

&lt;p&gt;Integration with Telex.im&lt;/p&gt;

&lt;p&gt;Step 1: Create Workflow in Telex&lt;/p&gt;

&lt;p&gt;Paste this JSON in your Telex workflow editor:&lt;br&gt;
json{&lt;br&gt;
  "active": true,&lt;br&gt;
  "category": "entertainment",&lt;br&gt;
  "description": "An AI agent that shares fascinating animal facts",&lt;br&gt;
  "id": "animalFactsAgent",&lt;br&gt;
  "name": "Animal Facts Agent",&lt;br&gt;
  "long_description": "You are a friendly and enthusiastic animal facts assistant...\n\n[Full prompt from agent instructions]",&lt;br&gt;
  "short_description": "Get fascinating facts about animals!",&lt;br&gt;
  "nodes": [&lt;br&gt;
    {&lt;br&gt;
      "id": "animal_facts_agent",&lt;br&gt;
      "name": "Animal Facts Agent",&lt;br&gt;
      "parameters": {},&lt;br&gt;
      "position": [816, -112],&lt;br&gt;
      "type": "a2a/mastra-a2a-node",&lt;br&gt;
      "typeVersion": 1,&lt;br&gt;
      "url": "&lt;a href="https://echoing-some-park-b2238438-9895-4670-80fe-def985a6d5e2.mastra.cloud/a2a/agent/animalAgent" rel="noopener noreferrer"&gt;https://echoing-some-park-b2238438-9895-4670-80fe-def985a6d5e2.mastra.cloud/a2a/agent/animalAgent&lt;/a&gt;"&lt;br&gt;
    }&lt;br&gt;
  ],&lt;br&gt;
  "pinData": {},&lt;br&gt;
  "settings": { "executionOrder": "v1" }&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;How It Works (Full Flow)&lt;/p&gt;

&lt;p&gt;User in Telex: @animal Tell me a cat fact&lt;br&gt;
Telex → A2A Request:&lt;br&gt;
json{ "jsonrpc": "2.0", "method": "message/send", "params": { "message": { "role": "user", "parts": [{ "kind": "text", "text": "Tell me a cat fact" }] } } }&lt;/p&gt;

&lt;p&gt;Mastra Agent:&lt;/p&gt;

&lt;p&gt;Parses intent via Gemini&lt;br&gt;
Calls getCatFact() tool&lt;br&gt;
Returns: "Cats have 230 bones..." + commentary&lt;/p&gt;

&lt;p&gt;A2A Response:&lt;br&gt;
json{&lt;br&gt;
  "jsonrpc": "2.0",&lt;br&gt;
  "result": {&lt;br&gt;
    "status": { "state": "completed", "message": { "role": "agent", "parts": [{ "kind": "text", "text": "Did you know? Cats have 230 bones... 😺" }] } },&lt;br&gt;
    "artifacts": [ ... ],&lt;br&gt;
    "history": [ ... ]&lt;br&gt;
  }&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;Telex displays in chat&lt;/p&gt;

&lt;p&gt;Testing Your Integration&lt;br&gt;
bash curl -X POST &lt;a href="https://echoing-some-park-b2238438-9895-4670-80fe-def985a6d5e2.mastra.cloud/a2a/agent/animalAgent" rel="noopener noreferrer"&gt;https://echoing-some-park-b2238438-9895-4670-80fe-def985a6d5e2.mastra.cloud/a2a/agent/animalAgent&lt;/a&gt; \&lt;br&gt;
  -H "Content-Type: application/json" \&lt;br&gt;
  -d '{&lt;br&gt;
    "jsonrpc": "2.0",&lt;br&gt;
    "id": "test-001",&lt;br&gt;
    "method": "message/send",&lt;br&gt;
    "params": {&lt;br&gt;
      "message": {&lt;br&gt;
        "kind": "message",&lt;br&gt;
        "role": "user",&lt;br&gt;
        "parts": [{ "kind": "text", "text": "Tell me about octopuses" }],&lt;br&gt;
        "messageId": "msg-001"&lt;br&gt;
      }&lt;br&gt;
    }&lt;br&gt;
  }'&lt;/p&gt;

&lt;p&gt;Monitor logs:&lt;br&gt;
texthttps://api.telex.im/agent-logs/{channel-id}.txt&lt;/p&gt;

&lt;p&gt;Key Benefits&lt;/p&gt;

&lt;p&gt;Benefit/&lt;br&gt;
Why It Matters&lt;/p&gt;

&lt;p&gt;Standardized A2A = Works with any A2A client&lt;br&gt;
Memory via LibSQL = Multi-turn convos&lt;br&gt;
Fallback Facts = 100 % uptime &lt;br&gt;
Empty-Body Fix = Thanos validator happy &lt;br&gt;
One-Click Deploy = mastra deploy&lt;/p&gt;

&lt;p&gt;Conclusion&lt;/p&gt;

&lt;p&gt;Using Mastra + A2A, I built a production-ready, intelligent, and fun AI agent in under 6 hours. The protocol handles the hard parts — context, history, artifacts — so you focus on what the agent does.&lt;br&gt;
This isn’t just a task submission — it’s a reusable pattern for:&lt;/p&gt;

&lt;p&gt;Next Steps&lt;br&gt;
Try it in your Telex channel!&lt;br&gt;
Want to build your own?&lt;/p&gt;

&lt;p&gt;-npx mastra create my-agent&lt;br&gt;
-Add tools + memory&lt;br&gt;
-Deploy → get A2A URL&lt;br&gt;
-Paste into Telex workflow&lt;/p&gt;

&lt;p&gt;Resources&lt;/p&gt;

&lt;p&gt;-GitHub Repo: github.com/Reigner007/Animal-Fact-Agent&lt;br&gt;
-Live Endpoint: mastra.cloud/a2a/agent/animalAgent&lt;br&gt;
-Mastra Docs: mastra.dev&lt;br&gt;
-A2A Spec: a2a.dev&lt;br&gt;
-Telex.im: telex.im&lt;/p&gt;

&lt;p&gt;Built by Reigner for @hnginternship and integrated in telex.im using @mastra&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>ai</category>
      <category>productivity</category>
      <category>backend</category>
    </item>
  </channel>
</rss>
