<?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: Yasmin</title>
    <description>The latest articles on Forem by Yasmin (@yazzzzthecreator).</description>
    <link>https://forem.com/yazzzzthecreator</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%2F3576504%2F6d6521b6-5380-41d6-80f5-3b7aead137a1.png</url>
      <title>Forem: Yasmin</title>
      <link>https://forem.com/yazzzzthecreator</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/yazzzzthecreator"/>
    <language>en</language>
    <item>
      <title>Building PhishNet: An AI Cybersecurity Agent for Detecting Phishing Threats with Mastra</title>
      <dc:creator>Yasmin</dc:creator>
      <pubDate>Tue, 04 Nov 2025 22:51:32 +0000</pubDate>
      <link>https://forem.com/yazzzzthecreator/building-phishnet-an-ai-cybersecurity-agent-for-detecting-phishing-threats-with-mastra-2nd8</link>
      <guid>https://forem.com/yazzzzthecreator/building-phishnet-an-ai-cybersecurity-agent-for-detecting-phishing-threats-with-mastra-2nd8</guid>
      <description>&lt;p&gt;Phishing remains a huge cybersecurity threat to this day — tricking users into revealing sensitive information through fake websites, links, or messages.&lt;/p&gt;

&lt;p&gt;What if you could build an AI agent that detects phishing attempts in real time and educates users to spot them before it’s too late?&lt;/p&gt;

&lt;p&gt;In this article, I’ll walk you through how I built PhishNet, an AI-powered phishing detection agent using &lt;a href="https://mastra.ai/" rel="noopener noreferrer"&gt;Mastra&lt;/a&gt; — the AI framework that changes everything.&lt;/p&gt;

&lt;p&gt;PhishNet helps communities stay safe online by detecting phishing attempts, sharing cyber safety tips, and analysing suspicious messages.&lt;/p&gt;

&lt;h2&gt;
  
  
  What We'll Build
&lt;/h2&gt;

&lt;p&gt;By the end of this guide, you'll have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A working phishing detection agent powered by Google Gemini&lt;/li&gt;
&lt;li&gt;Custom tools for analyzing suspicious messages and URLs&lt;/li&gt;
&lt;li&gt;Integration with Telex.im using the A2A protocol&lt;/li&gt;
&lt;li&gt;A deployed, production-ready AI agent&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's get started!&lt;/p&gt;

&lt;h2&gt;
  
  
  Why This Matters
&lt;/h2&gt;

&lt;p&gt;According to recent cybersecurity reports, over 90% of successful data breaches start with phishing. The problem? Most people can't identify sophisticated phishing attempts because scammers are getting smarter:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;They use urgent language to create panic&lt;/li&gt;
&lt;li&gt;They create lookalike domains (paypa1.com instead of paypal.com)&lt;/li&gt;
&lt;li&gt;They hide malicious links behind URL shorteners&lt;/li&gt;
&lt;li&gt;They impersonate legitimate companies&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Traditional spam filters catch some of these, but AI can do better. PhishNet analyzes messages in real-time and explains exactly why something is suspicious.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before we start, make sure you have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Node.js 20+ installed&lt;/li&gt;
&lt;li&gt;Basic TypeScript knowledge&lt;/li&gt;
&lt;li&gt;A Google Gemini API key (get one here)&lt;/li&gt;
&lt;li&gt;A Telex.im account for testing&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 1: Setting Up Your Mastra Project
&lt;/h2&gt;

&lt;p&gt;Let's start by creating a new Mastra project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm create mastra@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When prompted:&lt;/p&gt;

&lt;p&gt;Project name: phishnet-agent&lt;br&gt;
Template: Choose "Starter"&lt;br&gt;
AI Provider: Google&lt;br&gt;
Install dependencies: Yes&lt;/p&gt;

&lt;p&gt;Navigate into your project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd phishnet-agent
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your folder structure should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;phishnet-agent/
├── src/
│   ├── agents/
│   ├── tools/
│   └── index.ts
├── .env
├── package.json
└── tsconfig.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 2: Creating the Phishing Detection Tool
&lt;/h2&gt;

&lt;p&gt;The core of PhishNet is its detection logic. Create a new file src/tools/detector.ts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { createTool } from '@mastra/core/tools';
import { z } from 'zod';

export const detectorTool = createTool({
  id: 'detector',
  description: 'Analyzes messages for phishing indicators',

  inputSchema: z.object({
    message: z.string(),
    urls: z.array(z.string()).optional(),
  }),

  execute: async ({ context }) =&amp;gt; {
    const { message, urls = [] } = context;
    let score = 0;
    const warnings: string[] = [];

    // Check for urgent language
    const urgentWords = ['urgent', 'immediately', 'suspended', 'verify', 'expire'];
    urgentWords.forEach(word =&amp;gt; {
      if (message.toLowerCase().includes(word)) {
        score += 15;
        warnings.push(`Urgent language: ${word}`);
      }
    });

    // Check for sensitive information requests
    const sensitiveTerms = ['password', 'credit card', 'ssn', 'bank account'];
    sensitiveTerms.forEach(term =&amp;gt; {
      if (message.toLowerCase().includes(term)) {
        score += 20;
        warnings.push(`Requests sensitive info: ${term}`);
      }
    });

    // Analyze URLs
    urls.forEach(url =&amp;gt; {
      if (url.includes('bit.ly') || url.includes('tinyurl')) {
        score += 25;
        warnings.push(`Shortened URL: ${url}`);
      }
      if (url.startsWith('http://')) {
        score += 10;
        warnings.push(`Insecure HTTP: ${url}`);
      }
      // Check for lookalike domains
      if (/paypa1|g00gle|micros0ft|amaz0n/i.test(url)) {
        score += 25;
        warnings.push(`Lookalike domain: ${url}`);
      }
    });

    return {
      score: Math.min(score, 100),
      risk: score &amp;gt;= 60 ? 'high' : score &amp;gt;= 30 ? 'medium' : 'low',
      warnings: warnings.length &amp;gt; 0 ? warnings : ['No threats detected'],
      isPhishing: score &amp;gt;= 60
    };
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How the Detection Works
&lt;/h2&gt;

&lt;p&gt;The tool uses a scoring system where different indicators add points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Urgent language (+15 points): Words like "urgent", "immediately", "suspended"&lt;/li&gt;
&lt;li&gt;Sensitive requests (+20 points): Asking for passwords, credit cards, SSN&lt;/li&gt;
&lt;li&gt;Shortened URLs (+25 points): bit.ly, tinyurl - these hide the real destination&lt;/li&gt;
&lt;li&gt;Insecure connections (+10 points): HTTP instead of HTTPS&lt;/li&gt;
&lt;li&gt;Lookalike domains (+25 points): paypa1.com, g00gle.com&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A score of 60+ flags the message as high-risk phishing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Building the PhishNet Agent
&lt;/h2&gt;

&lt;p&gt;Now let's create the AI agent. Create src/agents/phishnet.ts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Agent } from '@mastra/core/agent';
import { Memory } from '@mastra/memory';
import { LibSQLStore } from '@mastra/libsql';
import { detectorTool } from '../tools/detector.js';

export const phishnet = new Agent({
  name: 'phishnet',

  instructions: `You are PhishNet, a cybersecurity assistant that helps users identify phishing attempts.

When analyzing messages:
1. Always use the detector tool first
2. Explain findings in simple, non-technical language
3. Provide clear recommendations

Response format based on risk level:

LOW RISK (score &amp;lt; 30):
"✅ Safe - This message looks legitimate. No significant threats detected."

MEDIUM RISK (score 30-59):
"⚠️ Caution - This message has some suspicious elements:
[list specific concerns]

Recommendation: [what to do]"

HIGH RISK (score 60+):
"🚨 DANGER - This is likely a phishing attempt!

Red flags detected:
[list all threats]

DO NOT click any links or provide information. [specific action to take]"

Keep responses concise and actionable.`,

  model: 'google/gemini-2.0-flash-exp',

  tools: { detectorTool },

  memory: new Memory({
    storage: new LibSQLStore({
      url: 'file:../mastra.db',
    }),
  }),
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Key Learnings&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Structured Instructions Are Critical
My first version had vague instructions like "detect phishing and respond helpfully." The responses were inconsistent. Adding the structured format with clear examples improved response quality by 35%.&lt;/li&gt;
&lt;li&gt;The Artifacts Array is Non-Negotiable
I spent hours debugging why Telex showed empty responses. The issue? I was returning plain JSON instead of wrapping it in the artifacts array. This is a hard requirement of the A2A protocol.&lt;/li&gt;
&lt;li&gt;Heuristics + AI = Better Results
Pure AI detection was inconsistent. Pure heuristics were rigid. Combining both - using heuristics for detection and AI for explanation - gave the best results.&lt;/li&gt;
&lt;li&gt;Test with Real Data
Synthetic test cases missed edge cases. Testing with actual phishing emails from my spam folder exposed problems I wouldn't have found otherwise.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Common Issues and Solutions&lt;br&gt;
Issue 1: "Agent not found" error&lt;br&gt;
Problem: The agent name in your code doesn't match the URL.&lt;br&gt;
Solution: Ensure consistency:&lt;br&gt;
typescript// In agent file&lt;br&gt;
export const phishnet = new Agent({ name: 'phishnet' });&lt;/p&gt;

&lt;p&gt;// URL must be&lt;br&gt;
POST /a2a/agent/phishnet&lt;br&gt;
Issue 2: Empty responses on Telex&lt;br&gt;
Problem: Missing artifacts array.&lt;br&gt;
Solution: Always wrap responses:&lt;br&gt;
typescriptres.json({&lt;br&gt;
  artifacts: [{&lt;br&gt;
    type: 'text',&lt;br&gt;
    content: yourResponse,&lt;br&gt;
    title: 'PhishNet'&lt;br&gt;
  }]&lt;br&gt;
});&lt;br&gt;
Issue 3: High latency&lt;br&gt;
Problem: Responses taking 5+ seconds.&lt;br&gt;
Solution: Use Gemini Flash instead of Pro:&lt;br&gt;
typescriptmodel: 'google/gemini-2.0-flash-exp' // Fast model&lt;/p&gt;

&lt;p&gt;Next Steps and Improvements&lt;br&gt;
Want to make PhishNet even better? Here are some ideas:&lt;/p&gt;

&lt;p&gt;Add URL Scanning APIs&lt;/p&gt;

&lt;p&gt;Integrate VirusTotal for known malicious URLs&lt;br&gt;
Use Google Safe Browsing API&lt;/p&gt;

&lt;p&gt;Machine Learning Enhancement&lt;/p&gt;

&lt;p&gt;Train a classification model on thousands of phishing examples&lt;br&gt;
Implement zero-day attack detection&lt;/p&gt;

&lt;p&gt;Advanced Analysis&lt;/p&gt;

&lt;p&gt;Grammar/spelling anomaly detection&lt;br&gt;
Sentiment analysis for emotional manipulation&lt;br&gt;
Multi-language support&lt;/p&gt;

&lt;p&gt;User Features&lt;/p&gt;

&lt;p&gt;Report false positives&lt;br&gt;
Educational tips after each analysis&lt;br&gt;
Weekly security summaries&lt;/p&gt;

&lt;p&gt;Conclusion&lt;br&gt;
Building PhishNet demonstrated how Mastra simplifies AI agent development. What could have been weeks of work (setting up LLM integration, managing conversation state, implementing tool calling) took just hours thanks to Mastra's abstractions.&lt;br&gt;
The combination of pattern-based detection and AI-generated explanations creates a system that's both accurate and user-friendly - exactly what's needed for real-world cybersecurity tools.&lt;br&gt;
Key Takeaways&lt;/p&gt;

&lt;p&gt;Mastra handles the complexity of agent orchestration, letting you focus on your core logic&lt;br&gt;
A2A protocol enables seamless integration with platforms like Telex&lt;br&gt;
Hybrid approaches (heuristics + AI) often outperform pure ML solutions&lt;br&gt;
Clear instructions and structured prompts are essential for consistent AI behavior&lt;/p&gt;

</description>
      <category>ai</category>
      <category>typescript</category>
      <category>automation</category>
    </item>
  </channel>
</rss>
