hch-dev commited on
Commit
f9af852
·
verified ·
1 Parent(s): 0da6f89

Update Version_5/src/sub_agents.py

Browse files
Files changed (1) hide show
  1. 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
- def run_agent(role_prompt: str, target_data: str) -> AgentReport:
9
- # We call Groq's hosted 8B infrastructure instead of local resources
10
- response = client.chat.completions.create(
11
- model="llama-3.1-8b-instant",
12
- messages=[
13
- {"role": "system", "content": role_prompt},
14
- {"role": "user", "content": target_data}
15
- ],
16
- # Groq enforces JSON mode via this parameter block
17
- response_format={"type": "json_object"},
18
- temperature=0.0
19
- )
20
- return AgentReport.model_validate_json(response.choices[0].message.content)
21
-
22
- def agent_url_analyst(url: str) -> AgentReport:
23
- prompt = (
24
- "You are a URL Shadows Analyst. Respond strictly in valid JSON matching this schema:\n"
25
- "{\"claim\": \"PHISHING\"|\"LEGITIMATE\"|\"AMBIGUOUS\", \"confidence\": float, \"evidence\": [string]}\n"
26
- "Analyze the structure for structural entropy, unusual domains, and brand keywords."
27
- )
28
- return run_agent(prompt, f"URL to analyze: {url}")
29
-
30
- def agent_html_structure(dom_json: str) -> AgentReport:
31
- prompt = (
32
- "You are an HTML Code Analyst. Respond strictly in valid JSON matching this schema:\n"
33
- "{\"claim\": \"PHISHING\"|\"LEGITIMATE\"|\"AMBIGUOUS\", \"confidence\": float, \"evidence\": [string]}\n"
34
- "Analyze these DOM elements. Flag external tracking inputs or forms posting to alternative servers."
35
- )
36
- return run_agent(prompt, f"DOM Data: {dom_json}")
37
-
38
- def agent_content_semantics(email_body: str) -> AgentReport:
39
- prompt = (
40
- "You are a Phishing Copywriter Critic. Respond strictly in valid JSON matching this schema:\n"
41
- "{\"claim\": \"PHISHING\"|\"LEGITIMATE\"|\"AMBIGUOUS\", \"confidence\": float, \"evidence\": [string]}\n"
42
- "Extract semantic compliance anomalies, high emotional coercion markers, and urgency loops."
43
- )
44
- return run_agent(prompt, f"Email Body: {email_body}")
45
-
46
- def agent_brand_impersonation(email_body: str, sender: str) -> AgentReport:
47
- prompt = (
48
- "You are an Identity Protection Agent. Respond strictly in valid JSON matching this schema:\n"
49
- "{\"claim\": \"PHISHING\"|\"LEGITIMATE\"|\"AMBIGUOUS\", \"confidence\": float, \"evidence\": [string]}\n"
50
- "Flag mismatched target namespaces where sender domains do not match corporate identifiers."
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}")