Update agents.py
Browse files
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
|
| 11 |
-
Beta
|
| 12 |
-
Gamma
|
| 13 |
-
Delta
|
| 14 |
-
Epsilon
|
| 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": "
|
| 25 |
-
"provider": "
|
| 26 |
-
"client_type": "
|
| 27 |
"color": "red",
|
| 28 |
"personality": (
|
| 29 |
-
"You are Agent Alpha
|
| 30 |
-
"Challenge every claim aggressively. Demand evidence.
|
| 31 |
"Point out what is NOT in the sources. Be blunt and relentless."
|
| 32 |
)
|
| 33 |
},
|
| 34 |
{
|
| 35 |
"name": "Beta",
|
| 36 |
-
"model": "
|
| 37 |
-
"provider": "
|
| 38 |
-
"client_type": "
|
| 39 |
"color": "yellow",
|
| 40 |
"personality": (
|
| 41 |
-
"You are Agent Beta
|
| 42 |
-
"
|
| 43 |
-
"
|
|
|
|
| 44 |
)
|
| 45 |
},
|
| 46 |
{
|
| 47 |
"name": "Gamma",
|
| 48 |
-
"model": "
|
| 49 |
-
"provider": "
|
| 50 |
-
"client_type": "
|
| 51 |
"color": "green",
|
| 52 |
"personality": (
|
| 53 |
-
"You are Agent Gamma
|
| 54 |
-
"Find non-obvious connections between sources."
|
| 55 |
-
"Look for relationships and synthesis opportunities others miss."
|
|
|
|
| 56 |
)
|
| 57 |
},
|
| 58 |
{
|
| 59 |
"name": "Delta",
|
| 60 |
-
"model": "
|
| 61 |
-
"provider": "
|
| 62 |
-
"client_type": "
|
| 63 |
"color": "purple",
|
| 64 |
"personality": (
|
| 65 |
-
"You are Agent Delta
|
| 66 |
-
"
|
| 67 |
-
"
|
|
|
|
| 68 |
)
|
| 69 |
},
|
| 70 |
{
|
| 71 |
"name": "Epsilon",
|
| 72 |
-
"model": "llama-3.
|
| 73 |
"provider": "groq",
|
| 74 |
"client_type": "groq",
|
| 75 |
"color": "blue",
|
| 76 |
"personality": (
|
| 77 |
-
"You are Agent Epsilon
|
| 78 |
-
"
|
| 79 |
-
"
|
|
|
|
| 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
|
| 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 |
-
#
|
| 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 |
-
#
|
| 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 |
-
#
|
| 263 |
emit({"type": "synthesizing"})
|
| 264 |
-
|
|
|
|
|
|
|
| 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 |
|