-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdiscursive_debate.py
More file actions
125 lines (95 loc) Β· 3.61 KB
/
discursive_debate.py
File metadata and controls
125 lines (95 loc) Β· 3.61 KB
1
2
3
4
5
6
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
"""Discursive Debate β Multi-agent dialectic.
Demonstrates two agents (Optimist vs Pessimist) debating a topic
via the relay until a turn limit is reached.
Flow:
1. Moderator -> Optimist: "Topic: Future of AI..."
2. Optimist -> Relay (broadcast): "AI is great..."
3. Pessimist -> Relay (broadcast): "AI is dangerous..."
"""
import threading
import time
from agent_utils import get_llm_client
from codomyrmex.agents.core import AgentRequest
from codomyrmex.ide.antigravity.agent_relay import AgentRelay
from codomyrmex.ide.antigravity.live_bridge import ClaudeCodeEndpoint
CHANNEL = "debate-club"
class DebaterAgent:
"""Run a debater agent with a specific stance."""
def __init__(self, identity, stance, duration=15):
self.identity = identity
self.stance = stance
self.duration = duration
self.client = get_llm_client(identity=identity)
self.endpoint = ClaudeCodeEndpoint(
CHANNEL,
identity=identity,
poll_interval=0.5,
claude_client=self.client,
auto_respond=False,
)
self.endpoint.on_message(self._handle_message)
def start(self):
self.endpoint.start()
time.sleep(self.duration)
self.endpoint.stop()
def _handle_message(self, msg):
print(f"\n[{self.identity.title()}] Received from {msg.sender}: {msg.content}")
# Don't reply to self! (Already filtered by endpoint but good to be safe logic-wise)
if msg.sender == self.identity:
return None
# Moderator starts it
# Or other debater replies
# System Prompt construction
full_prompt = (
f"System: You are an {self.stance.title()} debating the topic 'Future of AI'. "
f"Your opponent just said: '{msg.content}'. "
"Respond with a counter-argument consistent with your stance. "
"Keep it short (max 2 sentences). "
"If the moderator spoke, start your opening statement."
f"\n\nUser: {msg.content}"
)
request = AgentRequest(prompt=full_prompt, context=msg.metadata)
try:
response = self.client.execute_with_session(request, session=None)
if hasattr(response, "is_success") and response.is_success():
return response.content
return (
f"Error: {response.error}"
if hasattr(response, "error")
else str(response.content)
)
except Exception as e:
return f"Error executing agent: {e}"
def run_debater(identity, stance):
agent = DebaterAgent(identity, stance, duration=20)
agent.start()
def main():
# Auto-injected: Load configuration
from pathlib import Path
import yaml
config_path = (
Path(__file__).resolve().parent.parent.parent
/ "config"
/ "agents"
/ "config.yaml"
)
if config_path.exists():
with open(config_path) as f:
yaml.safe_load(f) or {}
print("Loaded config from config/agents/config.yaml")
AgentRelay(CHANNEL).clear()
# Start agents
t1 = threading.Thread(target=run_debater, args=("optimist", "optimist"))
t2 = threading.Thread(target=run_debater, args=("pessimist", "pessimist"))
t1.start()
t2.start()
# Kick it off manually
time.sleep(2)
relay = AgentRelay(CHANNEL)
print("\n[Moderator] Topic: The Future of AI. Optimist, start.")
relay.post_message("moderator", "Topic: The Future of AI. Optimist, please start.")
t1.join()
t2.join()
print("\nDebate concluded.")
if __name__ == "__main__":
main()