<?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>DEV Community: ibrahimabdulquadri101</title>
    <description>The latest articles on DEV Community by ibrahimabdulquadri101 (@ibrahimabdulquadri101).</description>
    <link>https://dev.to/ibrahimabdulquadri101</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%2F1701445%2Fcbea34eb-51f5-4ab2-863a-0e333d5afd0c.jpg</url>
      <title>DEV Community: ibrahimabdulquadri101</title>
      <link>https://dev.to/ibrahimabdulquadri101</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ibrahimabdulquadri101"/>
    <language>en</language>
    <item>
      <title>From Casual to Corporate: Building a Formalizer Agent with Mastra and Telex.im</title>
      <dc:creator>ibrahimabdulquadri101</dc:creator>
      <pubDate>Sat, 01 Nov 2025 21:34:00 +0000</pubDate>
      <link>https://dev.to/ibrahimabdulquadri101/from-casual-to-corporate-building-a-formalizer-agent-with-mastra-and-telexim-52a2</link>
      <guid>https://dev.to/ibrahimabdulquadri101/from-casual-to-corporate-building-a-formalizer-agent-with-mastra-and-telexim-52a2</guid>
      <description>&lt;p&gt;&lt;strong&gt;Formalizer Agent&lt;/strong&gt;, an AI Co-Worker designed for the Telex.im platform. This agent uses the &lt;strong&gt;Mastra TypeScript framework&lt;/strong&gt; to transform informal chat into professional, sophisticated prose, demonstrating a robust implementation of the &lt;strong&gt;Agent-to-Agent (A2A) protocol&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The core challenge of Stage 3 was moving beyond basic applications and building a reliable, intelligent service that communicates flawlessly with Telex.im.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;I. Defining the Core Logic: The Formalizer Agent&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The first step was to define the agent's identity and its singular purpose: &lt;strong&gt;linguistic formalization&lt;/strong&gt;. This is handled in src/agents/formalizer-agent.ts.&lt;/p&gt;

&lt;p&gt;The primary instruction set, or System Prompt, was critical to ensuring the agent adhered to strict output constraints, specifically the "no conversational fillers" rule.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Key Design Choices&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Model:&lt;/strong&gt; We selected google/gemini-2.5-flash for its speed and exceptional language manipulation capabilities.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Instructions:&lt;/strong&gt; The agent was given explicit &lt;strong&gt;"CRITICAL RULES"&lt;/strong&gt; to prevent boilerplate text, ensuring the output is immediately usable.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Name Consistency:&lt;/strong&gt; The agent was named &lt;strong&gt;FormalizerAgent&lt;/strong&gt;—a name that must be consistently matched across the code, the deployment URL, and the Telex Workflow JSON.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;II. The Bridge: A2A Protocol and Mastra Registration&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The Telex platform communicates with external agents using the &lt;strong&gt;Agent-to-Agent (A2A) protocol&lt;/strong&gt;, which is based on &lt;strong&gt;JSON-RPC 2.0&lt;/strong&gt;. Our Mastra application needed a bridge to translate this protocol into Mastra's internal messaging format.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;The A2A Route Handler (src/routes/a2a-agent-route.ts)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This file serves as the crucial translation layer, performing four essential tasks:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Parsing:&lt;/strong&gt; It receives the A2A JSON-RPC request and extracts the message and agentId (FormalizerAgent).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lookup:&lt;/strong&gt; It uses mastra.getAgent(agentId) to retrieve the correct agent instance.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Execution:&lt;/strong&gt; It calls the agent's core logic with the user's prompt (agent.generate(mastraMessages)).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Response Formatting:&lt;/strong&gt; It packages the agent's text output back into the required JSON-RPC 2.0 response structure, complete with history and artifact information.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Agent Registration&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The agent must be successfully registered in the main application file, src/mastra/index.ts, so the route handler can find it:&lt;/p&gt;

&lt;p&gt;// In src/mastra/index.ts&lt;br&gt;&lt;br&gt;
import { formalizerAgent } from './agents/formalizer-agent';&lt;/p&gt;

&lt;p&gt;export const mastra = new Mastra({&lt;br&gt;&lt;br&gt;
    // Agent is registered here, making it accessible by its name via the route.&lt;br&gt;&lt;br&gt;
    agents: { formalizerAgent },&lt;br&gt;&lt;br&gt;
    apiRoutes: [a2aAgentRoute],&lt;br&gt;&lt;br&gt;
    // ...&lt;br&gt;&lt;br&gt;
});&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;III. The Challenge: Debugging the Persistent "Agent Not Found" Error&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;After initial deployment, testing with Postman and Telex consistently returned a 500 Internal error with the critical detail: &lt;strong&gt;"Agent with name FormalizerAgent not found"&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;What didn't work:&lt;/strong&gt; Simply checking the code. The file structure and naming appeared correct.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Diagnosis:&lt;/strong&gt; The error was not a typo in the URL or the agent definition, but a failure during the build or deployment process where the central Mastra registry was not properly loading the agent.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;The Solution (The Key to the Integration)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To eliminate any ambiguity in the registration process, I modified src/mastra/index.ts to use the &lt;strong&gt;explicit string name&lt;/strong&gt; as the key in the agents object:&lt;/p&gt;

&lt;p&gt;// The critical fix in src/mastra/index.ts&lt;br&gt;&lt;br&gt;
agents: { 'FormalizerAgent': formalizerAgent },&lt;/p&gt;

&lt;p&gt;After implementing this change and executing a final clean build and redeployment, the Mastra server successfully recognized the agent and began processing requests flawlessly. This confirmed that ensuring &lt;strong&gt;absolute string-key parity during registration&lt;/strong&gt; is vital for stable A2A services.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;IV. Final Integration and Demonstration&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;With the backend stable, the final step was configuring the Telex Workflow JSON:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;URL:&lt;/strong&gt; The final A2A endpoint was set: [Your Base URL]/a2a/agent/FormalizerAgent.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Workflow Name:&lt;/strong&gt; Set to Formalizer Agent.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The agent is now live and can be tested on the Telex platform.&lt;br&gt;
github-url:github.com/ibrahimabdulquadri101/hng13-intern-assesment-stage-3&lt;br&gt;
mastra-website: &lt;a href="http://www.mastra.ai" rel="noopener noreferrer"&gt;www.mastra.ai&lt;/a&gt;&lt;/p&gt;

</description>
      <category>agents</category>
      <category>llm</category>
      <category>typescript</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
