cogames-agents 0.0.0.7__cp312-cp312-macosx_11_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cogames_agents/__init__.py +0 -0
- cogames_agents/evals/__init__.py +5 -0
- cogames_agents/evals/planky_evals.py +415 -0
- cogames_agents/policy/__init__.py +0 -0
- cogames_agents/policy/evolution/__init__.py +0 -0
- cogames_agents/policy/evolution/cogsguard/__init__.py +0 -0
- cogames_agents/policy/evolution/cogsguard/evolution.py +695 -0
- cogames_agents/policy/evolution/cogsguard/evolutionary_coordinator.py +540 -0
- cogames_agents/policy/nim_agents/__init__.py +20 -0
- cogames_agents/policy/nim_agents/agents.py +98 -0
- cogames_agents/policy/nim_agents/bindings/generated/libnim_agents.dylib +0 -0
- cogames_agents/policy/nim_agents/bindings/generated/nim_agents.py +215 -0
- cogames_agents/policy/nim_agents/cogsguard_agents.nim +555 -0
- cogames_agents/policy/nim_agents/cogsguard_align_all_agents.nim +569 -0
- cogames_agents/policy/nim_agents/common.nim +1054 -0
- cogames_agents/policy/nim_agents/install.sh +1 -0
- cogames_agents/policy/nim_agents/ladybug_agent.nim +954 -0
- cogames_agents/policy/nim_agents/nim_agents.nim +68 -0
- cogames_agents/policy/nim_agents/nim_agents.nims +14 -0
- cogames_agents/policy/nim_agents/nimby.lock +3 -0
- cogames_agents/policy/nim_agents/racecar_agents.nim +844 -0
- cogames_agents/policy/nim_agents/random_agents.nim +68 -0
- cogames_agents/policy/nim_agents/test_agents.py +53 -0
- cogames_agents/policy/nim_agents/thinky_agents.nim +677 -0
- cogames_agents/policy/nim_agents/thinky_eval.py +230 -0
- cogames_agents/policy/scripted_agent/README.md +360 -0
- cogames_agents/policy/scripted_agent/__init__.py +0 -0
- cogames_agents/policy/scripted_agent/baseline_agent.py +1031 -0
- cogames_agents/policy/scripted_agent/cogas/__init__.py +5 -0
- cogames_agents/policy/scripted_agent/cogas/context.py +68 -0
- cogames_agents/policy/scripted_agent/cogas/entity_map.py +152 -0
- cogames_agents/policy/scripted_agent/cogas/goal.py +115 -0
- cogames_agents/policy/scripted_agent/cogas/goals/__init__.py +27 -0
- cogames_agents/policy/scripted_agent/cogas/goals/aligner.py +160 -0
- cogames_agents/policy/scripted_agent/cogas/goals/gear.py +197 -0
- cogames_agents/policy/scripted_agent/cogas/goals/miner.py +441 -0
- cogames_agents/policy/scripted_agent/cogas/goals/scout.py +40 -0
- cogames_agents/policy/scripted_agent/cogas/goals/scrambler.py +174 -0
- cogames_agents/policy/scripted_agent/cogas/goals/shared.py +160 -0
- cogames_agents/policy/scripted_agent/cogas/goals/stem.py +60 -0
- cogames_agents/policy/scripted_agent/cogas/goals/survive.py +100 -0
- cogames_agents/policy/scripted_agent/cogas/navigator.py +401 -0
- cogames_agents/policy/scripted_agent/cogas/obs_parser.py +238 -0
- cogames_agents/policy/scripted_agent/cogas/policy.py +525 -0
- cogames_agents/policy/scripted_agent/cogas/trace.py +69 -0
- cogames_agents/policy/scripted_agent/cogsguard/CLAUDE.md +517 -0
- cogames_agents/policy/scripted_agent/cogsguard/README.md +252 -0
- cogames_agents/policy/scripted_agent/cogsguard/__init__.py +74 -0
- cogames_agents/policy/scripted_agent/cogsguard/aligned_junction_held_investigation.md +152 -0
- cogames_agents/policy/scripted_agent/cogsguard/aligner.py +333 -0
- cogames_agents/policy/scripted_agent/cogsguard/behavior_hooks.py +44 -0
- cogames_agents/policy/scripted_agent/cogsguard/control_agent.py +323 -0
- cogames_agents/policy/scripted_agent/cogsguard/debug_agent.py +533 -0
- cogames_agents/policy/scripted_agent/cogsguard/miner.py +589 -0
- cogames_agents/policy/scripted_agent/cogsguard/options.py +67 -0
- cogames_agents/policy/scripted_agent/cogsguard/parity_metrics.py +36 -0
- cogames_agents/policy/scripted_agent/cogsguard/policy.py +1967 -0
- cogames_agents/policy/scripted_agent/cogsguard/prereq_trace.py +33 -0
- cogames_agents/policy/scripted_agent/cogsguard/role_trace.py +50 -0
- cogames_agents/policy/scripted_agent/cogsguard/roles.py +31 -0
- cogames_agents/policy/scripted_agent/cogsguard/rollout_trace.py +40 -0
- cogames_agents/policy/scripted_agent/cogsguard/scout.py +69 -0
- cogames_agents/policy/scripted_agent/cogsguard/scrambler.py +350 -0
- cogames_agents/policy/scripted_agent/cogsguard/targeted_agent.py +418 -0
- cogames_agents/policy/scripted_agent/cogsguard/teacher.py +224 -0
- cogames_agents/policy/scripted_agent/cogsguard/types.py +381 -0
- cogames_agents/policy/scripted_agent/cogsguard/v2_agent.py +49 -0
- cogames_agents/policy/scripted_agent/common/__init__.py +0 -0
- cogames_agents/policy/scripted_agent/common/geometry.py +24 -0
- cogames_agents/policy/scripted_agent/common/roles.py +34 -0
- cogames_agents/policy/scripted_agent/common/tag_utils.py +48 -0
- cogames_agents/policy/scripted_agent/demo_policy.py +242 -0
- cogames_agents/policy/scripted_agent/pathfinding.py +126 -0
- cogames_agents/policy/scripted_agent/pinky/DESIGN.md +317 -0
- cogames_agents/policy/scripted_agent/pinky/__init__.py +5 -0
- cogames_agents/policy/scripted_agent/pinky/behaviors/__init__.py +17 -0
- cogames_agents/policy/scripted_agent/pinky/behaviors/aligner.py +400 -0
- cogames_agents/policy/scripted_agent/pinky/behaviors/base.py +119 -0
- cogames_agents/policy/scripted_agent/pinky/behaviors/miner.py +632 -0
- cogames_agents/policy/scripted_agent/pinky/behaviors/scout.py +138 -0
- cogames_agents/policy/scripted_agent/pinky/behaviors/scrambler.py +433 -0
- cogames_agents/policy/scripted_agent/pinky/policy.py +570 -0
- cogames_agents/policy/scripted_agent/pinky/services/__init__.py +7 -0
- cogames_agents/policy/scripted_agent/pinky/services/map_tracker.py +808 -0
- cogames_agents/policy/scripted_agent/pinky/services/navigator.py +864 -0
- cogames_agents/policy/scripted_agent/pinky/services/safety.py +189 -0
- cogames_agents/policy/scripted_agent/pinky/state.py +299 -0
- cogames_agents/policy/scripted_agent/pinky/types.py +138 -0
- cogames_agents/policy/scripted_agent/planky/CLAUDE.md +124 -0
- cogames_agents/policy/scripted_agent/planky/IMPROVEMENTS.md +160 -0
- cogames_agents/policy/scripted_agent/planky/NOTES.md +153 -0
- cogames_agents/policy/scripted_agent/planky/PLAN.md +254 -0
- cogames_agents/policy/scripted_agent/planky/README.md +214 -0
- cogames_agents/policy/scripted_agent/planky/STRATEGY.md +100 -0
- cogames_agents/policy/scripted_agent/planky/__init__.py +5 -0
- cogames_agents/policy/scripted_agent/planky/context.py +68 -0
- cogames_agents/policy/scripted_agent/planky/entity_map.py +152 -0
- cogames_agents/policy/scripted_agent/planky/goal.py +107 -0
- cogames_agents/policy/scripted_agent/planky/goals/__init__.py +27 -0
- cogames_agents/policy/scripted_agent/planky/goals/aligner.py +168 -0
- cogames_agents/policy/scripted_agent/planky/goals/gear.py +179 -0
- cogames_agents/policy/scripted_agent/planky/goals/miner.py +416 -0
- cogames_agents/policy/scripted_agent/planky/goals/scout.py +40 -0
- cogames_agents/policy/scripted_agent/planky/goals/scrambler.py +174 -0
- cogames_agents/policy/scripted_agent/planky/goals/shared.py +160 -0
- cogames_agents/policy/scripted_agent/planky/goals/stem.py +49 -0
- cogames_agents/policy/scripted_agent/planky/goals/survive.py +96 -0
- cogames_agents/policy/scripted_agent/planky/navigator.py +388 -0
- cogames_agents/policy/scripted_agent/planky/obs_parser.py +238 -0
- cogames_agents/policy/scripted_agent/planky/policy.py +485 -0
- cogames_agents/policy/scripted_agent/planky/tests/__init__.py +0 -0
- cogames_agents/policy/scripted_agent/planky/tests/conftest.py +66 -0
- cogames_agents/policy/scripted_agent/planky/tests/helpers.py +152 -0
- cogames_agents/policy/scripted_agent/planky/tests/test_aligner.py +24 -0
- cogames_agents/policy/scripted_agent/planky/tests/test_miner.py +30 -0
- cogames_agents/policy/scripted_agent/planky/tests/test_scout.py +15 -0
- cogames_agents/policy/scripted_agent/planky/tests/test_scrambler.py +29 -0
- cogames_agents/policy/scripted_agent/planky/tests/test_stem.py +36 -0
- cogames_agents/policy/scripted_agent/planky/trace.py +69 -0
- cogames_agents/policy/scripted_agent/types.py +239 -0
- cogames_agents/policy/scripted_agent/unclipping_agent.py +461 -0
- cogames_agents/policy/scripted_agent/utils.py +381 -0
- cogames_agents/policy/scripted_registry.py +80 -0
- cogames_agents/py.typed +0 -0
- cogames_agents-0.0.0.7.dist-info/METADATA +98 -0
- cogames_agents-0.0.0.7.dist-info/RECORD +128 -0
- cogames_agents-0.0.0.7.dist-info/WHEEL +6 -0
- cogames_agents-0.0.0.7.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
# CoGsGuard Scripted Agent
|
|
2
|
+
|
|
3
|
+
A vibe-based multi-agent policy for the Cogs vs Clips arena game.
|
|
4
|
+
|
|
5
|
+
## Vibe-Based Role System
|
|
6
|
+
|
|
7
|
+
Agents use **vibes** to determine their behavior dynamically:
|
|
8
|
+
|
|
9
|
+
| Vibe | Behavior |
|
|
10
|
+
| ----------- | --------------------------------------------------------------- |
|
|
11
|
+
| `default` | Do nothing (noop) - agent is idle |
|
|
12
|
+
| `gear` | Pick a role via the smart/evolutionary coordinator, change vibe |
|
|
13
|
+
| `miner` | Get miner gear if needed, then mine resources |
|
|
14
|
+
| `scout` | Get scout gear if needed, then explore the map |
|
|
15
|
+
| `aligner` | Get aligner gear if needed, then align junctions to cogs |
|
|
16
|
+
| `scrambler` | Get scrambler gear if needed, then scramble enemy junctions |
|
|
17
|
+
| `heart` | Do nothing (noop) |
|
|
18
|
+
|
|
19
|
+
This allows external systems (like training policies) to control agent behavior by setting their vibe.
|
|
20
|
+
|
|
21
|
+
## Game Rules
|
|
22
|
+
|
|
23
|
+
### Overview
|
|
24
|
+
|
|
25
|
+
CoGsGuard is a team-based resource management game where the **Cogs** team competes against the **Clips** team. The Cogs
|
|
26
|
+
team uses this scripted policy while Clips can be controlled by another policy or bot.
|
|
27
|
+
|
|
28
|
+
### Resources
|
|
29
|
+
|
|
30
|
+
- **Elements**: carbon, oxygen, germanium, silicon (gathered from extractors)
|
|
31
|
+
- **Energy**: Required for movement (auto-regenerates near aligned structures)
|
|
32
|
+
- **Hearts**: Required for align/scramble actions
|
|
33
|
+
- **Influence**: Required for aligning supply depots
|
|
34
|
+
- **HP**: Health points
|
|
35
|
+
|
|
36
|
+
### Key Structures
|
|
37
|
+
|
|
38
|
+
| Structure | Owner | Function |
|
|
39
|
+
| -------------------------- | ----------------- | ------------------------------------------------------------ |
|
|
40
|
+
| **Main Nexus** | Cogs | Energy AOE regeneration, resource deposits, heart withdrawal |
|
|
41
|
+
| **Supply Depot (Charger)** | Clips (initially) | Can be scrambled (→neutral) then aligned (→cogs) |
|
|
42
|
+
| **Gear Stations** | Cogs | Dispense role-specific gear (costs commons resources) |
|
|
43
|
+
| **Extractors** | Neutral | Gather element resources (in map corners) |
|
|
44
|
+
|
|
45
|
+
### Gear System
|
|
46
|
+
|
|
47
|
+
Agents must acquire role-specific gear from gear stations before executing their role. Gear costs are paid from the
|
|
48
|
+
**cogs commons** inventory:
|
|
49
|
+
|
|
50
|
+
| Gear | Cost | Bonus |
|
|
51
|
+
| --------- | ------------------------------------------ | ---------------------- |
|
|
52
|
+
| Miner | 3 carbon, 1 oxygen, 1 germanium, 1 silicon | +40 cargo capacity |
|
|
53
|
+
| Scout | 1 carbon, 1 oxygen, 1 germanium, 3 silicon | +100 energy, +400 HP |
|
|
54
|
+
| Aligner | 3 carbon, 1 oxygen, 1 germanium, 1 silicon | +20 influence capacity |
|
|
55
|
+
| Scrambler | 1 carbon, 3 oxygen, 1 germanium, 1 silicon | +200 HP |
|
|
56
|
+
|
|
57
|
+
### Supply Depot Mechanics
|
|
58
|
+
|
|
59
|
+
- **Align**: Convert neutral depot to cogs-aligned (requires aligner gear + 1 influence + 1 heart)
|
|
60
|
+
- **Scramble**: Remove depot's alignment (requires scrambler gear + 1 heart)
|
|
61
|
+
- Aligned depots provide energy AOE to their team
|
|
62
|
+
|
|
63
|
+
## Agent Strategy
|
|
64
|
+
|
|
65
|
+
### Vibe State Machine
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
┌─────────────┐ ┌─────────────┐
|
|
69
|
+
│ default │ ◄──────────────────│ heart │
|
|
70
|
+
│ (noop) │ │ (noop) │
|
|
71
|
+
└─────────────┘ └─────────────┘
|
|
72
|
+
|
|
73
|
+
External vibe change
|
|
74
|
+
│
|
|
75
|
+
▼
|
|
76
|
+
┌─────────────┐ Pick smart role ┌───────────────┐
|
|
77
|
+
│ gear │ ──────────────────► │ role vibe │
|
|
78
|
+
│ │ role vibe │ (miner/scout/ │
|
|
79
|
+
└─────────────┘ │ aligner/ │
|
|
80
|
+
│ scrambler) │
|
|
81
|
+
└───────────────┘
|
|
82
|
+
│
|
|
83
|
+
▼
|
|
84
|
+
┌─────────────┐ ┌──────────────┐
|
|
85
|
+
│ GET_GEAR │ ──► │ EXECUTE_ROLE │
|
|
86
|
+
└─────────────┘ └──────────────┘
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Phase System (within role vibes)
|
|
90
|
+
|
|
91
|
+
When an agent has a role vibe (miner/scout/aligner/scrambler):
|
|
92
|
+
|
|
93
|
+
1. **GET_GEAR**: Find and bump the role-specific gear station
|
|
94
|
+
2. **EXECUTE_ROLE**: Perform role-specific behavior
|
|
95
|
+
|
|
96
|
+
### Role Behaviors
|
|
97
|
+
|
|
98
|
+
#### 🔨 Miner
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
1. Find nearest extractor (carbon/oxygen/germanium/silicon chests)
|
|
102
|
+
2. Navigate to extractor and extract resources
|
|
103
|
+
3. When cargo full (40 capacity), return to supply depot to deposit
|
|
104
|
+
4. Repeat
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
#### 🔭 Scout
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
1. Explore the map systematically (high energy allows long-range scouting)
|
|
111
|
+
2. Discover structures and resources for team knowledge
|
|
112
|
+
3. Patrol map edges to maximize coverage
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
#### 🔗 Aligner
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
1. Get influence from nexus AOE (stand nearby)
|
|
119
|
+
2. Get hearts from nexus (bump to withdraw from commons)
|
|
120
|
+
3. Find neutral supply depots (after scrambler has neutralized them)
|
|
121
|
+
4. Bump depot to align it to cogs
|
|
122
|
+
5. Repeat
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
#### 🌀 Scrambler
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
1. Get hearts from nexus or chest
|
|
129
|
+
2. Find clips-aligned supply depots (junctions)
|
|
130
|
+
3. Bump depot to scramble (remove alignment → neutral)
|
|
131
|
+
4. Repeat
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Exploration Strategy
|
|
135
|
+
|
|
136
|
+
Agents explore systematically by cycling through cardinal directions:
|
|
137
|
+
|
|
138
|
+
```
|
|
139
|
+
East (8 steps) → South (8 steps) → West (8 steps) → North (8 steps) → repeat
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Starting direction is East (where gear stations are typically located in hub maps).
|
|
143
|
+
|
|
144
|
+
### Resource Flow
|
|
145
|
+
|
|
146
|
+
```
|
|
147
|
+
Extractors ──► Miners ──► Commons ──► Gear Stations ──► Agents
|
|
148
|
+
│
|
|
149
|
+
└──► Hearts ──► Aligners/Scramblers
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Known Limitations
|
|
153
|
+
|
|
154
|
+
1. **Aligner Timing**: Aligners often take too long to find their gear stations. By then, the commons may be depleted of
|
|
155
|
+
resources needed for aligner gear.
|
|
156
|
+
|
|
157
|
+
2. **No Communication**: Agents don't share discovered locations. Each agent must independently explore to find
|
|
158
|
+
structures.
|
|
159
|
+
|
|
160
|
+
3. **Random Station Placement**: Gear stations are randomly placed around the hub perimeter, making exploration outcomes
|
|
161
|
+
variable.
|
|
162
|
+
|
|
163
|
+
## Investigations
|
|
164
|
+
|
|
165
|
+
- [aligned_junction_held_investigation](aligned_junction_held_investigation.md): AOE energy issues blocking junction
|
|
166
|
+
alignment in `aligned.junction.held`.
|
|
167
|
+
|
|
168
|
+
## Usage
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
# Run with the role policy (default: 1 scrambler, 4 miners)
|
|
172
|
+
./tools/run.py recipes.experiment.cogsguard.play policy_uri=metta://policy/role
|
|
173
|
+
|
|
174
|
+
# With limited timesteps and log rendering
|
|
175
|
+
./tools/run.py recipes.experiment.cogsguard.play policy_uri=metta://policy/role render=log max_steps=500
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Specifying Initial Vibe Counts
|
|
179
|
+
|
|
180
|
+
You can control how many agents start with each role using URI query parameters:
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
# Custom distribution: 4 miners, 2 scramblers, 1 gear (smart role)
|
|
184
|
+
./tools/run.py recipes.experiment.cogsguard.play \
|
|
185
|
+
policy_uri="metta://policy/role?miner=4&scrambler=2&gear=1"
|
|
186
|
+
|
|
187
|
+
# All miners
|
|
188
|
+
./tools/run.py recipes.experiment.cogsguard.play \
|
|
189
|
+
policy_uri="metta://policy/role?miner=10"
|
|
190
|
+
|
|
191
|
+
# Balanced team
|
|
192
|
+
./tools/run.py recipes.experiment.cogsguard.play \
|
|
193
|
+
policy_uri="metta://policy/role?miner=3&scout=2&aligner=2&scrambler=3"
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
**Supported vibe parameters:**
|
|
197
|
+
|
|
198
|
+
| Parameter | Description |
|
|
199
|
+
| ----------- | ------------------------------------------------------------------------------------- |
|
|
200
|
+
| `miner` | Number of agents starting as miners |
|
|
201
|
+
| `scout` | Number of agents starting as scouts |
|
|
202
|
+
| `aligner` | Number of agents starting as aligners |
|
|
203
|
+
| `scrambler` | Number of agents starting as scramblers |
|
|
204
|
+
| `gear` | Number of agents starting with gear (smart role) |
|
|
205
|
+
| `evolution` | Use evolutionary role selection for `gear` agents (aliases: `evolutionary`, `evolve`) |
|
|
206
|
+
|
|
207
|
+
**Assignment order:** `scrambler → aligner → miner → scout → gear`
|
|
208
|
+
|
|
209
|
+
Agents are assigned vibes in order by agent ID. Agents beyond the total count specified get no initial target vibe and
|
|
210
|
+
start with the `gear` vibe (smart role selection).
|
|
211
|
+
|
|
212
|
+
**Default counts** (if no params specified): `scrambler=1, miner=4`, remainder `gear`
|
|
213
|
+
|
|
214
|
+
### Role Cycle / Fixed Mix
|
|
215
|
+
|
|
216
|
+
If you want a fixed, repeating role pattern by agent index, use `role_cycle` (comma-separated). This is handy for
|
|
217
|
+
hardcoding a mix like 3 aligners, 3 miners, 2 scramblers, 2 scouts when running 10 agents.
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
# 10 agents: aligner, miner, scrambler, scout repeating (3/3/2/2)
|
|
221
|
+
./tools/run.py recipes.experiment.cogsguard.play \
|
|
222
|
+
policy_uri="metta://policy/role_py?role_cycle=aligner,miner,scrambler,scout" \
|
|
223
|
+
sim.env.game.num_agents=10 \
|
|
224
|
+
sim.env.game.map_builder.instance.spawn_count=10
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
For a one-off explicit ordering, use `role_order` (comma-separated) to list the exact vibes per agent id.
|
|
228
|
+
|
|
229
|
+
## File Structure
|
|
230
|
+
|
|
231
|
+
```
|
|
232
|
+
cogsguard/
|
|
233
|
+
├── __init__.py # Exports CogsguardPolicy
|
|
234
|
+
├── policy.py # Base agent logic, vibe state machine, navigation
|
|
235
|
+
├── types.py # State definitions (CogsguardAgentState, Role, Phase)
|
|
236
|
+
├── miner.py # Miner role implementation
|
|
237
|
+
├── scout.py # Scout role implementation
|
|
238
|
+
├── aligner.py # Aligner role implementation
|
|
239
|
+
├── scrambler.py # Scrambler role implementation
|
|
240
|
+
├── README.md # This file
|
|
241
|
+
└── CLAUDE.md # AI debugging guide
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Debug Mode
|
|
245
|
+
|
|
246
|
+
Set `DEBUG = True` in `policy.py` to enable detailed logging:
|
|
247
|
+
|
|
248
|
+
```python
|
|
249
|
+
DEBUG = True # Enable debug logging
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
This will print agent vibe transitions, decisions, discoveries, and phase transitions.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""CoGsGuard scripted agent with role-based behavior."""
|
|
2
|
+
|
|
3
|
+
from cogames_agents.policy.evolution.cogsguard.evolution import (
|
|
4
|
+
BehaviorDef,
|
|
5
|
+
BehaviorSource,
|
|
6
|
+
EvolutionConfig,
|
|
7
|
+
RoleCatalog,
|
|
8
|
+
RoleDef,
|
|
9
|
+
RoleTier,
|
|
10
|
+
TierSelection,
|
|
11
|
+
materialize_role_behaviors,
|
|
12
|
+
mutate_role,
|
|
13
|
+
pick_role_id_weighted,
|
|
14
|
+
recombine_roles,
|
|
15
|
+
record_behavior_score,
|
|
16
|
+
record_role_score,
|
|
17
|
+
sample_role,
|
|
18
|
+
)
|
|
19
|
+
from cogames_agents.policy.evolution.cogsguard.evolutionary_coordinator import (
|
|
20
|
+
EvolutionaryRoleCoordinator,
|
|
21
|
+
)
|
|
22
|
+
from cogames_agents.policy.scripted_agent.cogsguard.behavior_hooks import build_cogsguard_behavior_hooks
|
|
23
|
+
from cogames_agents.policy.scripted_agent.cogsguard.control_agent import CogsguardControlAgent
|
|
24
|
+
from cogames_agents.policy.scripted_agent.cogsguard.policy import CogsguardPolicy, CogsguardWomboPolicy
|
|
25
|
+
from cogames_agents.policy.scripted_agent.cogsguard.roles import (
|
|
26
|
+
AlignerPolicy,
|
|
27
|
+
MinerPolicy,
|
|
28
|
+
ScoutPolicy,
|
|
29
|
+
ScramblerPolicy,
|
|
30
|
+
)
|
|
31
|
+
from cogames_agents.policy.scripted_agent.cogsguard.targeted_agent import CogsguardTargetedAgent
|
|
32
|
+
from cogames_agents.policy.scripted_agent.cogsguard.v2_agent import CogsguardV2Agent
|
|
33
|
+
|
|
34
|
+
try:
|
|
35
|
+
from cogames_agents.policy.scripted_agent.cogsguard.teacher import CogsguardTeacherPolicy
|
|
36
|
+
except ModuleNotFoundError as exc: # pragma: no cover - optional for environments without nim agents
|
|
37
|
+
if exc.name and exc.name.startswith("cogames_agents.policy.nim_agents"):
|
|
38
|
+
CogsguardTeacherPolicy = None
|
|
39
|
+
else:
|
|
40
|
+
raise
|
|
41
|
+
|
|
42
|
+
__all__ = [
|
|
43
|
+
"CogsguardControlAgent",
|
|
44
|
+
"CogsguardPolicy",
|
|
45
|
+
"CogsguardWomboPolicy",
|
|
46
|
+
"CogsguardTargetedAgent",
|
|
47
|
+
"CogsguardV2Agent",
|
|
48
|
+
"MinerPolicy",
|
|
49
|
+
"ScoutPolicy",
|
|
50
|
+
"AlignerPolicy",
|
|
51
|
+
"ScramblerPolicy",
|
|
52
|
+
# Evolution types
|
|
53
|
+
"BehaviorDef",
|
|
54
|
+
"BehaviorSource",
|
|
55
|
+
"EvolutionConfig",
|
|
56
|
+
"RoleCatalog",
|
|
57
|
+
"RoleDef",
|
|
58
|
+
"RoleTier",
|
|
59
|
+
"TierSelection",
|
|
60
|
+
# Evolution functions
|
|
61
|
+
"materialize_role_behaviors",
|
|
62
|
+
"mutate_role",
|
|
63
|
+
"pick_role_id_weighted",
|
|
64
|
+
"recombine_roles",
|
|
65
|
+
"record_behavior_score",
|
|
66
|
+
"record_role_score",
|
|
67
|
+
"sample_role",
|
|
68
|
+
# Coordinator + hooks
|
|
69
|
+
"EvolutionaryRoleCoordinator",
|
|
70
|
+
"build_cogsguard_behavior_hooks",
|
|
71
|
+
]
|
|
72
|
+
|
|
73
|
+
if CogsguardTeacherPolicy is not None:
|
|
74
|
+
__all__.append("CogsguardTeacherPolicy")
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# Investigation: aligned.junction.held Scoring Gap (300 vs 30k)
|
|
2
|
+
|
|
3
|
+
## Summary
|
|
4
|
+
|
|
5
|
+
The 100x scoring gap (PPO: ~300 vs expected: ~30,000) for `aligned.junction.held` is caused by a fundamental energy
|
|
6
|
+
starvation problem that prevents agents from effectively navigating and completing their roles.
|
|
7
|
+
|
|
8
|
+
## Key Findings
|
|
9
|
+
|
|
10
|
+
### 1. Scripted Agents Are NOT Successfully Aligning Junctions
|
|
11
|
+
|
|
12
|
+
After running `cogames play` with both the Nim (`metta://policy/role`) and Python (`metta://policy/role_py`) policies, I
|
|
13
|
+
observed:
|
|
14
|
+
|
|
15
|
+
- **clips.aligned.junction.held: ~135,000** (over 5000 steps)
|
|
16
|
+
- **cogs.aligned.junction.held: 0** (zero junctions aligned to cogs)
|
|
17
|
+
|
|
18
|
+
This means the scripted agents themselves are failing to align junctions, just like PPO.
|
|
19
|
+
|
|
20
|
+
### 2. Root Cause: Energy Starvation
|
|
21
|
+
|
|
22
|
+
Agents are experiencing severe energy starvation:
|
|
23
|
+
|
|
24
|
+
| Metric | Expected | Observed |
|
|
25
|
+
| -------------------------- | -------- | ------------------------- |
|
|
26
|
+
| action.move.failed | ~0% | ~99% |
|
|
27
|
+
| action.move.success | ~99% | ~1% |
|
|
28
|
+
| max_steps_without_motion | low | ~2900 (out of 3000 steps) |
|
|
29
|
+
| energy.gained (3000 steps) | ~300,000 | ~130-200 |
|
|
30
|
+
|
|
31
|
+
### 3. Why Energy is Depleted
|
|
32
|
+
|
|
33
|
+
The game is designed with an energy-based economy:
|
|
34
|
+
|
|
35
|
+
- **Move action costs**: 3 energy per move
|
|
36
|
+
- **Agent initial energy**: 100
|
|
37
|
+
- **Base energy regen**: +1 energy/tick
|
|
38
|
+
- **Hub AOE (expected)**: +100 energy/tick to cogs agents within range 10
|
|
39
|
+
|
|
40
|
+
**Problem**: The hub's AOE energy buff is NOT being applied to agents.
|
|
41
|
+
|
|
42
|
+
In testing, I observed:
|
|
43
|
+
|
|
44
|
+
- Agent spawns at (26, 26), hub at (29, 29) - distance 6 (within AOE range 10)
|
|
45
|
+
- Agent starts with 100 energy
|
|
46
|
+
- After 1 step: energy = 10 (dropped 90!)
|
|
47
|
+
- Expected: energy should increase to 200+ from AOE
|
|
48
|
+
|
|
49
|
+
### 4. The Junction Alignment Flow
|
|
50
|
+
|
|
51
|
+
To align a junction, agents must:
|
|
52
|
+
|
|
53
|
+
1. **Scrambler** scrambles clips-aligned junctions to neutral
|
|
54
|
+
- Requires: scrambler gear + 1 heart
|
|
55
|
+
- Must navigate to junction and bump into it
|
|
56
|
+
|
|
57
|
+
2. **Aligner** aligns neutral junctions to cogs
|
|
58
|
+
- Requires: aligner gear + 1 influence + 1 heart
|
|
59
|
+
- Must navigate to junction and bump into it
|
|
60
|
+
|
|
61
|
+
**Problem**: Agents can't navigate because they don't have energy to move.
|
|
62
|
+
|
|
63
|
+
### 5. Chicken-and-Egg Problem
|
|
64
|
+
|
|
65
|
+
The game design creates a catch-22:
|
|
66
|
+
|
|
67
|
+
- Agents need energy to move to junctions
|
|
68
|
+
- Junctions provide energy AOE when aligned to cogs
|
|
69
|
+
- But junctions start aligned to clips (enemy)
|
|
70
|
+
- The hub should provide energy, but its AOE isn't working
|
|
71
|
+
|
|
72
|
+
## Configuration Details
|
|
73
|
+
|
|
74
|
+
### Agent Energy Config
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
inventory.limits = {'energy': ResourceLimitsConfig(min=10, max=65535, ...)}
|
|
78
|
+
inventory.initial = {'energy': 100}
|
|
79
|
+
inventory.regen_amounts = {'default': {'energy': 1, 'hp': -1, 'influence': -1}}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Move Action Cost
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
actions.move = MoveActionConfig(consumed_resources={'energy': 3})
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Hub AOE (Hub)
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
aoes = [
|
|
92
|
+
AOEEffectConfig(
|
|
93
|
+
range=10,
|
|
94
|
+
resource_deltas={'influence': 10, 'energy': 100, 'hp': 100},
|
|
95
|
+
filters=[isAlignedToActor()] # Same collective
|
|
96
|
+
),
|
|
97
|
+
AOEEffectConfig(
|
|
98
|
+
range=10,
|
|
99
|
+
resource_deltas={'hp': -1, 'influence': -100},
|
|
100
|
+
filters=[isEnemy()] # Different collective
|
|
101
|
+
)
|
|
102
|
+
]
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Junction AOE
|
|
106
|
+
|
|
107
|
+
Same structure as hub, but junctions are clips-aligned, so they:
|
|
108
|
+
|
|
109
|
+
- Give +100 energy to clips agents
|
|
110
|
+
- Deal -1 hp to cogs agents
|
|
111
|
+
|
|
112
|
+
## Recommendations
|
|
113
|
+
|
|
114
|
+
1. **Investigate AOE Application Bug**: The hub's energy AOE is not being applied to cogs agents. Check if there's a bug
|
|
115
|
+
in the collective alignment matching for AOE effects.
|
|
116
|
+
|
|
117
|
+
2. **Reduce Move Energy Cost**: Consider lowering from 3 to 1 or 2 to make agents more mobile.
|
|
118
|
+
|
|
119
|
+
3. **Increase Base Energy Regen**: Increase from +1 to +5 or +10 per tick.
|
|
120
|
+
|
|
121
|
+
4. **Give Agents Initial Hearts**: Currently agents start with 0 hearts and must get them from chests, but they can't
|
|
122
|
+
reach chests without energy.
|
|
123
|
+
|
|
124
|
+
5. **Check Scripted Agent Logic**: The Nim agents may have bugs in their pathfinding or role execution that cause them
|
|
125
|
+
to get stuck even when they have energy.
|
|
126
|
+
|
|
127
|
+
## Test Commands Used
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
# Run with teacher policy (uses Nim backend)
|
|
131
|
+
uv run tools/run.py cogsguard.play "policy_uri=metta://policy/teacher" render=log max_steps=3000
|
|
132
|
+
|
|
133
|
+
# Run with Python policy
|
|
134
|
+
uv run tools/run.py cogsguard.play "policy_uri=metta://policy/role_py" render=log max_steps=3000
|
|
135
|
+
|
|
136
|
+
# Check simulation state
|
|
137
|
+
uv run python -c "
|
|
138
|
+
from mettagrid.simulator.simulator import Simulator
|
|
139
|
+
from recipes.experiment.cogsguard import make_env
|
|
140
|
+
cfg = make_env(num_agents=10, max_steps=100)
|
|
141
|
+
sim = Simulator().new_simulation(cfg, seed=42)
|
|
142
|
+
# ... inspect state
|
|
143
|
+
"
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Related Files
|
|
147
|
+
|
|
148
|
+
- `packages/cogames/src/cogames/cogs_vs_clips/mission.py` - CogsGuard mission config
|
|
149
|
+
- `packages/cogames/src/cogames/cogs_vs_clips/stations.py` - Junction and Hub configs
|
|
150
|
+
- `packages/cogames-agents/src/cogames_agents/policy/nim_agents/cogsguard_agents.nim` - Nim scripted agents
|
|
151
|
+
- `packages/cogames-agents/src/cogames_agents/policy/scripted_agent/cogsguard/` - Python scripted agents
|
|
152
|
+
- `recipes/experiment/cogsguard.py` - Recipe for running CogsGuard
|