Spaces:
Sleeping
Sleeping
deploy from github
Browse files- core/simulation.py +27 -6
- frontend/src/App.jsx +8 -4
core/simulation.py
CHANGED
|
@@ -375,34 +375,55 @@ class Simulation:
|
|
| 375 |
Chaos agent creates unpredictable market moves.
|
| 376 |
Forces other agents to react to unexpected volatility.
|
| 377 |
"""
|
| 378 |
-
# Random action type:
|
| 379 |
-
action_type = random.choice(['
|
| 380 |
|
| 381 |
# Random volatility between 25-50% (increased impact)
|
| 382 |
volatility = random.uniform(0.25, 0.50)
|
| 383 |
|
| 384 |
-
|
|
|
|
|
|
|
| 385 |
# Random direction swap
|
| 386 |
direction = random.choice(['a', 'b'])
|
| 387 |
amount = self.pool.reserve_a * volatility
|
| 388 |
output, fee = self.pool.swap(direction, amount, 'ChaosAgent')
|
|
|
|
|
|
|
| 389 |
print(f" [ChaosAgent]: Random swap {amount:.0f} -> {output:.1f}")
|
| 390 |
|
| 391 |
-
elif action_type == '
|
| 392 |
# Random liquidity provision
|
| 393 |
amount_a = self.pool.reserve_a * volatility
|
| 394 |
amount_b = self.pool.reserve_b * volatility
|
| 395 |
-
# Liquidity agent doesn't track, just burns tokens for effect
|
| 396 |
self.pool.provide_liquidity(amount_a, amount_b, 'ChaosAgent')
|
|
|
|
|
|
|
| 397 |
print(f" [ChaosAgent]: Random liquidity +{amount_a:.0f}A/+{amount_b:.0f}B")
|
| 398 |
|
| 399 |
-
else: #
|
| 400 |
# Huge random trade that moves price significantly
|
| 401 |
direction = random.choice(['a', 'b'])
|
| 402 |
amount = self.pool.reserve_a * volatility * 1.5 # Even bigger
|
| 403 |
output, fee = self.pool.swap(direction, amount, 'ChaosAgent')
|
|
|
|
|
|
|
| 404 |
print(f" [ChaosAgent]: MASSIVE swap {amount:.0f} -> {output:.1f}!")
|
| 405 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 406 |
def _process_alliances(self, turn: int):
|
| 407 |
"""
|
| 408 |
Process alliances and grant bonuses for mutual proposals.
|
|
|
|
| 375 |
Chaos agent creates unpredictable market moves.
|
| 376 |
Forces other agents to react to unexpected volatility.
|
| 377 |
"""
|
| 378 |
+
# Random action type: swap, liquidity, or massive_swap
|
| 379 |
+
action_type = random.choice(['chaos_swap', 'chaos_liquidity', 'chaos_massive_swap'])
|
| 380 |
|
| 381 |
# Random volatility between 25-50% (increased impact)
|
| 382 |
volatility = random.uniform(0.25, 0.50)
|
| 383 |
|
| 384 |
+
chaos_agent = Agent("ChaosAgent")
|
| 385 |
+
|
| 386 |
+
if action_type == 'chaos_swap':
|
| 387 |
# Random direction swap
|
| 388 |
direction = random.choice(['a', 'b'])
|
| 389 |
amount = self.pool.reserve_a * volatility
|
| 390 |
output, fee = self.pool.swap(direction, amount, 'ChaosAgent')
|
| 391 |
+
decision = {"action": "chaos_swap", "direction": direction, "amount": amount}
|
| 392 |
+
self._save_chaos_action(chaos_agent, turn, decision, "Chaos agent creates random market volatility")
|
| 393 |
print(f" [ChaosAgent]: Random swap {amount:.0f} -> {output:.1f}")
|
| 394 |
|
| 395 |
+
elif action_type == 'chaos_liquidity':
|
| 396 |
# Random liquidity provision
|
| 397 |
amount_a = self.pool.reserve_a * volatility
|
| 398 |
amount_b = self.pool.reserve_b * volatility
|
|
|
|
| 399 |
self.pool.provide_liquidity(amount_a, amount_b, 'ChaosAgent')
|
| 400 |
+
decision = {"action": "chaos_liquidity", "amount_a": amount_a, "amount_b": amount_b}
|
| 401 |
+
self._save_chaos_action(chaos_agent, turn, decision, "Chaos agent adds unpredictable liquidity")
|
| 402 |
print(f" [ChaosAgent]: Random liquidity +{amount_a:.0f}A/+{amount_b:.0f}B")
|
| 403 |
|
| 404 |
+
else: # chaos_massive_swap
|
| 405 |
# Huge random trade that moves price significantly
|
| 406 |
direction = random.choice(['a', 'b'])
|
| 407 |
amount = self.pool.reserve_a * volatility * 1.5 # Even bigger
|
| 408 |
output, fee = self.pool.swap(direction, amount, 'ChaosAgent')
|
| 409 |
+
decision = {"action": "chaos_massive_swap", "direction": direction, "amount": amount}
|
| 410 |
+
self._save_chaos_action(chaos_agent, turn, decision, "Chaos agent executes MASSIVE trade causing extreme volatility!")
|
| 411 |
print(f" [ChaosAgent]: MASSIVE swap {amount:.0f} -> {output:.1f}!")
|
| 412 |
|
| 413 |
+
def _save_chaos_action(self, agent: Agent, turn: int, decision: Dict, thinking: str):
|
| 414 |
+
"""Save chaos agent action to database."""
|
| 415 |
+
if not self.supabase:
|
| 416 |
+
return
|
| 417 |
+
self.supabase.save_action(ActionData(
|
| 418 |
+
run_id=self.current_run_id,
|
| 419 |
+
turn=turn,
|
| 420 |
+
agent_name=agent.name,
|
| 421 |
+
action_type=decision.get("action", "unknown"),
|
| 422 |
+
payload=decision,
|
| 423 |
+
reasoning_trace=thinking,
|
| 424 |
+
thinking_trace=""
|
| 425 |
+
))
|
| 426 |
+
|
| 427 |
def _process_alliances(self, turn: int):
|
| 428 |
"""
|
| 429 |
Process alliances and grant bonuses for mutual proposals.
|
frontend/src/App.jsx
CHANGED
|
@@ -161,9 +161,13 @@ function App() {
|
|
| 161 |
|
| 162 |
const getFilteredSummaries = () => {
|
| 163 |
if (!expandedRun) return summaries
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
}
|
| 168 |
|
| 169 |
if (loading) {
|
|
@@ -458,7 +462,7 @@ function App() {
|
|
| 458 |
}
|
| 459 |
return (
|
| 460 |
<fieldset key={summary.id} className="border border-gray-400 p-2 bg-white">
|
| 461 |
-
<legend className="px-1 font-bold">Run {summary.run_id} Report</legend>
|
| 462 |
<p className="text-xs font-mono whitespace-pre-wrap">{text}</p>
|
| 463 |
</fieldset>
|
| 464 |
)
|
|
|
|
| 161 |
|
| 162 |
const getFilteredSummaries = () => {
|
| 163 |
if (!expandedRun) return summaries
|
| 164 |
+
// Match by internal run ID (summary.run_id contains internal database ID)
|
| 165 |
+
return summaries.filter(s => s.run_id === expandedRun)
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
const getRunNumber = (internalId) => {
|
| 169 |
+
const run = runs.find(r => r.id === internalId)
|
| 170 |
+
return run ? run.run_number : internalId
|
| 171 |
}
|
| 172 |
|
| 173 |
if (loading) {
|
|
|
|
| 462 |
}
|
| 463 |
return (
|
| 464 |
<fieldset key={summary.id} className="border border-gray-400 p-2 bg-white">
|
| 465 |
+
<legend className="px-1 font-bold">Run {getRunNumber(summary.run_id)} Report</legend>
|
| 466 |
<p className="text-xs font-mono whitespace-pre-wrap">{text}</p>
|
| 467 |
</fieldset>
|
| 468 |
)
|