nice-bill commited on
Commit
17390ee
·
verified ·
1 Parent(s): 816b1c5

deploy from github

Browse files
Files changed (2) hide show
  1. core/agent.py +38 -9
  2. core/simulation.py +13 -6
core/agent.py CHANGED
@@ -85,6 +85,31 @@ Output ONLY valid JSON with your reasoning."""
85
  You are losing {penalty:.1f} tokens per turn due to boredom penalty.
86
  ACT NOW to avoid further losses!"""
87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  prompt = f"""
89
  You are {self.name}, an AI agent in a DeFi market simulation.
90
 
@@ -97,9 +122,12 @@ Consecutive inaction: {self.consecutive_inaction}
97
  {boredom_warning}
98
 
99
  === MARKET STATE ===
100
- Pool reserves: A={pool_state.get('reserve_a', 0):.2f}, B={pool_state.get('reserve_b', 0):.2f}
101
- Price (A/B): {pool_state.get('price_ab', 0):.4f}
102
- Total liquidity: {pool_state.get('total_liquidity', 0):.2f}
 
 
 
103
 
104
  === OTHER AGENTS ===
105
  {json.dumps(other_states, indent=2)}
@@ -109,17 +137,18 @@ Total liquidity: {pool_state.get('total_liquidity', 0):.2f}
109
 
110
  === REWARDS FOR ACTIONS ===
111
  - SWAP: Active trading +3 tokens, profitable swap +5 extra!
112
- - PROVIDE_LIQUIDITY: Earns fees from all swaps, +8 bonus tokens
113
  - PROPOSE_ALLIANCE: If they accept, you BOTH get +4 bonus tokens (repeating gives less!)
114
  - COORDINATED TRADES: Trade during volatility +5 bonus tokens!
115
  - POSITIVE PROFIT: End turn with profit = +15 bonus tokens!
116
  - ESCAPE VELOCITY: TOP AGENT gets 2x on ALL bonuses!
117
 
118
- === AVAILABLE ACTIONS ===
119
- 1. "swap": Trade tokens (specify from, to, amount) - ACTIVE TRADING
120
- 2. "provide_liquidity": Add liquidity to pool (specify amounts) - EARNS FEES + BONUS
121
- 3. "propose_alliance": Suggest collaboration (specify agent name) - CAN GIVE BONUS
122
- 4. "do_nothing": Wait - CAUSES BOREDOM PENALTY!
 
123
 
124
  Output JSON:
125
  {{
 
85
  You are losing {penalty:.1f} tokens per turn due to boredom penalty.
86
  ACT NOW to avoid further losses!"""
87
 
88
+ # Calculate market insights
89
+ reserve_a = pool_state.get('reserve_a', 1000)
90
+ reserve_b = pool_state.get('reserve_b', 1000)
91
+ price_ab = pool_state.get('price_ab', 1.0)
92
+ liquidity = pool_state.get('total_liquidity', 1000000)
93
+
94
+ # Determine if pool is imbalanced
95
+ imbalance = reserve_a / reserve_b if reserve_b > 0 else 1
96
+ market_advice = ""
97
+ if imbalance > 1.5:
98
+ market_advice = "Pool is A-heavy (A is cheaper). Consider buying B or providing A liquidity."
99
+ elif imbalance < 0.67:
100
+ market_advice = "Pool is B-heavy (B is cheaper). Consider buying A or providing B liquidity."
101
+ else:
102
+ market_advice = "Pool is balanced. Look for other opportunities."
103
+
104
+ # Check tokens for trading decisions
105
+ token_advice = ""
106
+ if self.token_a < 20 and self.token_b > 50:
107
+ token_advice = "You have low Token A! Prioritize getting more A."
108
+ elif self.token_b < 20 and self.token_a > 50:
109
+ token_advice = "You have low Token B! Prioritize getting more B."
110
+ elif self.token_a > 150 and self.token_b > 150:
111
+ token_advice = "You have excess tokens. Consider providing liquidity for fee rewards (+8 bonus)."
112
+
113
  prompt = f"""
114
  You are {self.name}, an AI agent in a DeFi market simulation.
115
 
 
122
  {boredom_warning}
123
 
124
  === MARKET STATE ===
125
+ Pool reserves: A={reserve_a:.2f}, B={reserve_b:.2f}
126
+ Price (A/B): {price_ab:.4f}
127
+ Total liquidity: {liquidity:.2f}
128
+ IMBALANCE RATIO: {imbalance:.2f}x
129
+ {market_advice}
130
+ {token_advice}
131
 
132
  === OTHER AGENTS ===
133
  {json.dumps(other_states, indent=2)}
 
137
 
138
  === REWARDS FOR ACTIONS ===
139
  - SWAP: Active trading +3 tokens, profitable swap +5 extra!
140
+ - PROVIDE_LIQUIDITY: Earns fees from all swaps, +8 bonus tokens (BEST for high balances)
141
  - PROPOSE_ALLIANCE: If they accept, you BOTH get +4 bonus tokens (repeating gives less!)
142
  - COORDINATED TRADES: Trade during volatility +5 bonus tokens!
143
  - POSITIVE PROFIT: End turn with profit = +15 bonus tokens!
144
  - ESCAPE VELOCITY: TOP AGENT gets 2x on ALL bonuses!
145
 
146
+ === DECISION GUIDE ===
147
+ - If tokens > 150 each: PROVIDE_LIQUIDITY (best returns +8 bonus)
148
+ - If pool imbalanced > 1.5x: Buy the cheaper token
149
+ - If tokens < 20 of either: Prioritize getting more of that token
150
+ - If you have allies: Consider coordinated actions
151
+ - DO NOT do_nothing - you lose 10 tokens/turn!
152
 
153
  Output JSON:
154
  {{
core/simulation.py CHANGED
@@ -427,16 +427,23 @@ class Simulation:
427
  def _process_alliances(self, turn: int):
428
  """
429
  Process alliances and grant bonuses for mutual proposals.
430
- When two agents propose alliance to each other, both get a bonus.
431
  """
432
  # Find mutual alliance pairs
433
  for i, agent_a in enumerate(self.agents):
434
  for agent_b in self.agents[i + 1:]:
435
- # Check if both have proposed alliance to each other
436
- if (agent_b.name in agent_a.alliances and
437
- agent_a.name in agent_b.alliances and
438
- agent_a.alliances.get(agent_b.name) == 'proposed' and
439
- agent_b.alliances.get(agent_a.name) == 'proposed'):
 
 
 
 
 
 
 
440
 
441
  # Successful alliance! Grant bonus to both (with fatigue)
442
  fatigue_a = agent_a.get_alliance_fatigue(agent_b.name)
 
427
  def _process_alliances(self, turn: int):
428
  """
429
  Process alliances and grant bonuses for mutual proposals.
430
+ When two agents propose alliance to each other (even across turns), both get a bonus.
431
  """
432
  # Find mutual alliance pairs
433
  for i, agent_a in enumerate(self.agents):
434
  for agent_b in self.agents[i + 1:]:
435
+ # Check if both have proposed alliance to each other (any status, not just 'proposed')
436
+ a_proposed_to_b = agent_b.name in agent_a.alliances
437
+ b_proposed_to_a = agent_a.name in agent_b.alliances
438
+
439
+ if a_proposed_to_b and b_proposed_to_a:
440
+ # Get current statuses
441
+ status_a = agent_a.alliances.get(agent_b.name, "")
442
+ status_b = agent_b.alliances.get(agent_a.name, "")
443
+
444
+ # Skip if already successful
445
+ if status_a == 'success' and status_b == 'success':
446
+ continue
447
 
448
  # Successful alliance! Grant bonus to both (with fatigue)
449
  fatigue_a = agent_a.get_alliance_fatigue(agent_b.name)