RohanB67 commited on
Commit
13394a2
Β·
verified Β·
1 Parent(s): 189df32

Update agents.py

Browse files
Files changed (1) hide show
  1. agents.py +43 -39
agents.py CHANGED
@@ -7,80 +7,82 @@ Multi-agent swarm debate engine with real-time SSE callbacks.
7
  enabling live streaming to the browser via SSE.
8
 
9
  Agent roster:
10
- Alpha - meta-llama/Llama-3.1-8B-Instruct (cerebras) - Skeptic
11
- Beta - Qwen/Qwen2.5-7B-Instruct (together) - Literalist
12
- Gamma - HuggingFaceH4/zephyr-7b-beta (featherless) - Connector
13
- Delta - deepseek-ai/DeepSeek-R1 (sambanova) - Deep Reasoner
14
- Epsilon - llama-3.3-70b-versatile (groq) - Synthesizer
15
  """
16
 
17
  import concurrent.futures
18
  from groq import Groq
19
- from huggingface_hub import InferenceClient
20
 
21
  AGENTS = [
22
  {
23
  "name": "Alpha",
24
- "model": "meta-llama/Llama-3.1-8B-Instruct",
25
- "provider": "cerebras",
26
- "client_type": "hf",
27
  "color": "red",
28
  "personality": (
29
- "You are Agent Alpha - a ruthless Skeptic. "
30
- "Challenge every claim aggressively. Demand evidence. Math nerd. "
31
  "Point out what is NOT in the sources. Be blunt and relentless."
32
  )
33
  },
34
  {
35
  "name": "Beta",
36
- "model": "Qwen/Qwen2.5-7B-Instruct",
37
- "provider": "together",
38
- "client_type": "hf",
39
  "color": "yellow",
40
  "personality": (
41
- "You are Agent Beta - a strict Literalist. "
42
- "Accept ONLY what is explicitly stated in the source text. "
43
- "Reject all inferences. If it is not literally written, it does not exist."
 
44
  )
45
  },
46
  {
47
  "name": "Gamma",
48
- "model": "HuggingFaceH4/zephyr-7b-beta",
49
- "provider": "featherless-ai",
50
- "client_type": "hf",
51
  "color": "green",
52
  "personality": (
53
- "You are Agent Gamma - a Pattern Connector. "
54
- "Find non-obvious connections between sources."
55
- "Look for relationships and synthesis opportunities others miss."
 
56
  )
57
  },
58
  {
59
  "name": "Delta",
60
- "model": "deepseek-ai/DeepSeek-R1",
61
- "provider": "sambanova",
62
- "client_type": "hf",
63
  "color": "purple",
64
  "personality": (
65
- "You are Agent Delta - a Deep Reasoner. Prefer Detailed answer or to the point. "
66
- "Move slowly and carefully. Check every logical step. "
67
- "Flag hidden assumptions and claims beyond what sources support."
 
68
  )
69
  },
70
  {
71
  "name": "Epsilon",
72
- "model": "llama-3.3-70b-versatile",
73
  "provider": "groq",
74
  "client_type": "groq",
75
  "color": "blue",
76
  "personality": (
77
- "You are Agent Epsilon - the Synthesizer. "
78
- "Reconcile the debate. Find where agents agree and disagree. "
79
- "Produce a final authoritative answer with source citations."
 
80
  )
81
  },
82
  ]
83
-
84
  MAX_ROUNDS = 3
85
  MAX_TOKENS_AGENT = 500
86
  MAX_TOKENS_SYNTH = 900
@@ -88,7 +90,7 @@ TIMEOUT_SECONDS = 30
88
  CONTEXT_LIMIT = 3000 # chars fed to synthesizer to avoid 413
89
 
90
  DOMAIN_GUARD = """
91
- SCOPE: EpiRAG β€” strictly epidemic modeling, network science, mathematical epidemiology, disease biology and related epidemiology.
92
  Do NOT answer anything outside this domain. If off-topic, say so and stop.
93
  """
94
 
@@ -204,7 +206,7 @@ def run_debate(question, context, groq_key, hf_token, callback=None):
204
  agent_colors = {a["name"]: a["color"] for a in AGENTS}
205
  debate_rounds = []
206
 
207
- # -- Round 1 ------------------------------------------------------------
208
  emit({"type": "round_start", "round": 1})
209
  round1 = {}
210
 
@@ -231,7 +233,7 @@ def run_debate(question, context, groq_key, hf_token, callback=None):
231
  current = round1
232
  rounds_run = 1
233
 
234
- # -- Rounds 2+ ------------------------------------------------------------
235
  while not consensus and rounds_run < MAX_ROUNDS:
236
  rounds_run += 1
237
  emit({"type": "round_start", "round": rounds_run})
@@ -259,9 +261,11 @@ def run_debate(question, context, groq_key, hf_token, callback=None):
259
  current = next_round
260
  consensus = _converged(next_round)
261
 
262
- # -- Synthesis ------------------------------------------------------------
263
  emit({"type": "synthesizing"})
264
- final = _call_agent(synthesizer, _synth_msgs(question, context, debate_rounds),
 
 
265
  groq_key, hf_token, max_tokens=MAX_TOKENS_SYNTH)
266
  emit({"type": "done", "consensus": consensus, "rounds": rounds_run})
267
 
 
7
  enabling live streaming to the browser via SSE.
8
 
9
  Agent roster:
10
+ Alpha β€” meta-llama/Llama-3.1-8B-Instruct (cerebras) β€” Skeptic
11
+ Beta β€” Qwen/Qwen2.5-7B-Instruct (together) β€” Literalist
12
+ Gamma β€” HuggingFaceH4/zephyr-7b-beta (featherless) β€” Connector
13
+ Delta β€” deepseek-ai/DeepSeek-R1 (sambanova) β€” Deep Reasoner
14
+ Epsilon β€” llama-3.3-70b-versatile (groq) β€” Synthesizer
15
  """
16
 
17
  import concurrent.futures
18
  from groq import Groq
 
19
 
20
  AGENTS = [
21
  {
22
  "name": "Alpha",
23
+ "model": "llama-3.3-70b-versatile",
24
+ "provider": "groq",
25
+ "client_type": "groq",
26
  "color": "red",
27
  "personality": (
28
+ "You are Agent Alpha β€” a ruthless Skeptic. "
29
+ "Challenge every claim aggressively. Demand evidence. "
30
  "Point out what is NOT in the sources. Be blunt and relentless."
31
  )
32
  },
33
  {
34
  "name": "Beta",
35
+ "model": "deepseek-r1-distill-llama-70b",
36
+ "provider": "groq",
37
+ "client_type": "groq",
38
  "color": "yellow",
39
  "personality": (
40
+ "You are Agent Beta β€” a Deep Reasoner. "
41
+ "Think step by step. Show your chain of thought explicitly. "
42
+ "Identify hidden assumptions and logical gaps the other agents miss. "
43
+ "Precision and thoroughness over speed."
44
  )
45
  },
46
  {
47
  "name": "Gamma",
48
+ "model": "gemma2-9b-it",
49
+ "provider": "groq",
50
+ "client_type": "groq",
51
  "color": "green",
52
  "personality": (
53
+ "You are Agent Gamma β€” a Pattern Connector. "
54
+ "Find non-obvious connections between different sources. "
55
+ "Look for relationships and synthesis opportunities others miss. "
56
+ "Think laterally and creatively."
57
  )
58
  },
59
  {
60
  "name": "Delta",
61
+ "model": "qwen-qwq-32b",
62
+ "provider": "groq",
63
+ "client_type": "groq",
64
  "color": "purple",
65
  "personality": (
66
+ "You are Agent Delta β€” a strict Literalist. "
67
+ "Accept ONLY what is explicitly stated in the source text. "
68
+ "Reject all inferences and extrapolations. "
69
+ "If it is not literally written in the excerpts, it does not exist."
70
  )
71
  },
72
  {
73
  "name": "Epsilon",
74
+ "model": "llama-3.1-8b-instant",
75
  "provider": "groq",
76
  "client_type": "groq",
77
  "color": "blue",
78
  "personality": (
79
+ "You are Agent Epsilon β€” the Synthesizer. "
80
+ "Read all agents arguments, identify where they agree and disagree, "
81
+ "and produce a final authoritative answer incorporating the strongest points. "
82
+ "Be decisive. Cite sources clearly."
83
  )
84
  },
85
  ]
 
86
  MAX_ROUNDS = 3
87
  MAX_TOKENS_AGENT = 500
88
  MAX_TOKENS_SYNTH = 900
 
90
  CONTEXT_LIMIT = 3000 # chars fed to synthesizer to avoid 413
91
 
92
  DOMAIN_GUARD = """
93
+ SCOPE: EpiRAG β€” strictly epidemic modeling, network science, mathematical epidemiology.
94
  Do NOT answer anything outside this domain. If off-topic, say so and stop.
95
  """
96
 
 
206
  agent_colors = {a["name"]: a["color"] for a in AGENTS}
207
  debate_rounds = []
208
 
209
+ # ── Round 1 ───────────────────────────────────────────────────────────────
210
  emit({"type": "round_start", "round": 1})
211
  round1 = {}
212
 
 
233
  current = round1
234
  rounds_run = 1
235
 
236
+ # ── Rounds 2+ ─────────────────────────────────────────────────────────────
237
  while not consensus and rounds_run < MAX_ROUNDS:
238
  rounds_run += 1
239
  emit({"type": "round_start", "round": rounds_run})
 
261
  current = next_round
262
  consensus = _converged(next_round)
263
 
264
+ # ── Synthesis ──────────────────────────────────────────────────────────────
265
  emit({"type": "synthesizing"})
266
+ # Truncate context for synthesis to avoid 413 token limit errors
267
+ ctx_trunc = context[:4000] if len(context) > 4000 else context
268
+ final = _call_agent(synthesizer, _synth_msgs(question, ctx_trunc, debate_rounds),
269
  groq_key, hf_token, max_tokens=MAX_TOKENS_SYNTH)
270
  emit({"type": "done", "consensus": consensus, "rounds": rounds_run})
271