Spaces:
Runtime error
Runtime error
Update Version_5/src/sub_agents.py
Browse files- Version_5/src/sub_agents.py +60 -51
Version_5/src/sub_agents.py
CHANGED
|
@@ -1,52 +1,61 @@
|
|
| 1 |
-
import os
|
| 2 |
-
from groq import Groq
|
| 3 |
-
from .schemas import AgentReport
|
| 4 |
-
|
| 5 |
-
# Initialize the Groq Cloud Client
|
| 6 |
-
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
"
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
"
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
)
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
"
|
| 49 |
-
"
|
| 50 |
-
|
| 51 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
return run_agent(prompt, f"Sender: {sender}\nBody: {email_body}")
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from groq import Groq
|
| 3 |
+
from .schemas import AgentReport
|
| 4 |
+
|
| 5 |
+
# Initialize the Groq Cloud Client
|
| 6 |
+
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
|
| 7 |
+
|
| 8 |
+
# ── NEW: System Override for AMTSO & Simulated Tests ──
|
| 9 |
+
SIMULATION_OVERRIDE = """
|
| 10 |
+
CRITICAL RULE - SIMULATED THREATS:
|
| 11 |
+
If the text, HTML, or content explicitly claims to be a "Test Page", "Dummy Page", "AMTSO Phishing Check", or states it is designed to test anti-malware/antivirus software, YOU MUST treat it as a real threat. Return a claim of "PHISHING" with a high confidence score, and explicitly state in the evidence array that it is a simulated testing environment. Do not mark it as LEGITIMATE just because it is a benign test.
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
def run_agent(role_prompt: str, target_data: str) -> AgentReport:
|
| 15 |
+
# We call Groq's hosted 8B infrastructure instead of local resources
|
| 16 |
+
response = client.chat.completions.create(
|
| 17 |
+
model="llama-3.1-8b-instant",
|
| 18 |
+
messages=[
|
| 19 |
+
{"role": "system", "content": role_prompt},
|
| 20 |
+
{"role": "user", "content": target_data}
|
| 21 |
+
],
|
| 22 |
+
# Groq enforces JSON mode via this parameter block
|
| 23 |
+
response_format={"type": "json_object"},
|
| 24 |
+
temperature=0.0
|
| 25 |
+
)
|
| 26 |
+
return AgentReport.model_validate_json(response.choices[0].message.content)
|
| 27 |
+
|
| 28 |
+
def agent_url_analyst(url: str) -> AgentReport:
|
| 29 |
+
prompt = (
|
| 30 |
+
"You are a URL Shadows Analyst. Respond strictly in valid JSON matching this schema:\n"
|
| 31 |
+
"{\"claim\": \"PHISHING\"|\"LEGITIMATE\"|\"AMBIGUOUS\", \"confidence\": float, \"evidence\": [string]}\n"
|
| 32 |
+
"Analyze the structure for structural entropy, unusual domains, and brand keywords."
|
| 33 |
+
)
|
| 34 |
+
return run_agent(prompt, f"URL to analyze: {url}")
|
| 35 |
+
|
| 36 |
+
def agent_html_structure(dom_json: str) -> AgentReport:
|
| 37 |
+
prompt = (
|
| 38 |
+
"You are an HTML Code Analyst. Respond strictly in valid JSON matching this schema:\n"
|
| 39 |
+
"{\"claim\": \"PHISHING\"|\"LEGITIMATE\"|\"AMBIGUOUS\", \"confidence\": float, \"evidence\": [string]}\n"
|
| 40 |
+
"Analyze these DOM elements. Flag external tracking inputs or forms posting to alternative servers.\n"
|
| 41 |
+
+ SIMULATION_OVERRIDE
|
| 42 |
+
)
|
| 43 |
+
return run_agent(prompt, f"DOM Data: {dom_json}")
|
| 44 |
+
|
| 45 |
+
def agent_content_semantics(email_body: str) -> AgentReport:
|
| 46 |
+
prompt = (
|
| 47 |
+
"You are a Phishing Copywriter Critic. Respond strictly in valid JSON matching this schema:\n"
|
| 48 |
+
"{\"claim\": \"PHISHING\"|\"LEGITIMATE\"|\"AMBIGUOUS\", \"confidence\": float, \"evidence\": [string]}\n"
|
| 49 |
+
"Extract semantic compliance anomalies, high emotional coercion markers, and urgency loops.\n"
|
| 50 |
+
+ SIMULATION_OVERRIDE
|
| 51 |
+
)
|
| 52 |
+
return run_agent(prompt, f"Email Body: {email_body}")
|
| 53 |
+
|
| 54 |
+
def agent_brand_impersonation(email_body: str, sender: str) -> AgentReport:
|
| 55 |
+
prompt = (
|
| 56 |
+
"You are an Identity Protection Agent. Respond strictly in valid JSON matching this schema:\n"
|
| 57 |
+
"{\"claim\": \"PHISHING\"|\"LEGITIMATE\"|\"AMBIGUOUS\", \"confidence\": float, \"evidence\": [string]}\n"
|
| 58 |
+
"Flag mismatched target namespaces where sender domains do not match corporate identifiers.\n"
|
| 59 |
+
+ SIMULATION_OVERRIDE
|
| 60 |
+
)
|
| 61 |
return run_agent(prompt, f"Sender: {sender}\nBody: {email_body}")
|