@agent-e/core 1.1.1 → 1.1.2
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.
- package/README.md +136 -0
- package/package.json +3 -2
package/README.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# @agent-e/core
|
|
2
|
+
|
|
3
|
+
Autonomous economic balancer SDK. 60 built-in principles, 5-stage pipeline, zero dependencies.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @agent-e/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { AgentE } from '@agent-e/core';
|
|
15
|
+
|
|
16
|
+
const agent = new AgentE({
|
|
17
|
+
adapter: {
|
|
18
|
+
getState: () => ({
|
|
19
|
+
tick: currentTick,
|
|
20
|
+
agentBalances: { /* id → gold */ },
|
|
21
|
+
agentRoles: { /* id → role */ },
|
|
22
|
+
agentInventories: { /* id → { resource → qty } */ },
|
|
23
|
+
marketPrices: { /* resource → price */ },
|
|
24
|
+
agentSatisfaction: { /* id → 0-100 */ },
|
|
25
|
+
poolSizes: { /* pool → amount */ },
|
|
26
|
+
}),
|
|
27
|
+
setParam: async (param, value) => {
|
|
28
|
+
// Apply parameter change to your economy
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
mode: 'advisor', // or 'autonomous'
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
agent.connect(agent.adapter).start();
|
|
35
|
+
|
|
36
|
+
// Call once per tick in your loop:
|
|
37
|
+
await agent.tick();
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## The 5-Stage Pipeline
|
|
41
|
+
|
|
42
|
+
1. **Observer** — Translates raw state into 40+ metrics at 3 resolutions (fine/medium/coarse)
|
|
43
|
+
2. **Diagnoser** — Runs 60 principles, returns violations sorted by severity
|
|
44
|
+
3. **Simulator** — Monte Carlo forward projection (≥100 iterations) before any action
|
|
45
|
+
4. **Planner** — Lag-aware, cooldown-aware planning with rollback conditions
|
|
46
|
+
5. **Executor** — Applies actions and monitors for rollback triggers
|
|
47
|
+
|
|
48
|
+
## Modes
|
|
49
|
+
|
|
50
|
+
| Mode | Behavior |
|
|
51
|
+
|------|----------|
|
|
52
|
+
| `autonomous` | Full pipeline — executes parameter changes automatically |
|
|
53
|
+
| `advisor` | Full pipeline but stops before execution — emits recommendations via `onDecision` |
|
|
54
|
+
|
|
55
|
+
## 60 Principles
|
|
56
|
+
|
|
57
|
+
Organized across 15 categories: supply chain, incentives, population, currency flow, bootstrap, feedback loops, regulator, market dynamics, measurement, statistical, system dynamics, resource management, player experience, open economy, and liveops.
|
|
58
|
+
|
|
59
|
+
Each principle has a `check(metrics, thresholds)` function that returns either `{ violated: false }` or a violation with severity, evidence, suggested action, confidence, and estimated lag.
|
|
60
|
+
|
|
61
|
+
## Developer API
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
// Lock a parameter from automated adjustment
|
|
65
|
+
agent.lock('craftingCost');
|
|
66
|
+
agent.unlock('craftingCost');
|
|
67
|
+
|
|
68
|
+
// Constrain a parameter to a range
|
|
69
|
+
agent.constrain('auctionFee', { min: 0.01, max: 0.50 });
|
|
70
|
+
|
|
71
|
+
// Add a custom principle
|
|
72
|
+
agent.addPrinciple(myPrinciple);
|
|
73
|
+
|
|
74
|
+
// Register a custom metric
|
|
75
|
+
agent.registerCustomMetric('myMetric', (state) => compute(state));
|
|
76
|
+
|
|
77
|
+
// Veto actions
|
|
78
|
+
agent.on('beforeAction', (plan) => {
|
|
79
|
+
if (plan.targetValue > 2.0) return false;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// Query decision history
|
|
83
|
+
const decisions = agent.getDecisions({ outcome: 'applied' });
|
|
84
|
+
|
|
85
|
+
// Health score (0-100)
|
|
86
|
+
const health = agent.getHealth();
|
|
87
|
+
|
|
88
|
+
// Metric time-series
|
|
89
|
+
const latest = agent.metrics.latest('fine');
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Custom Principles
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
import type { Principle } from '@agent-e/core';
|
|
96
|
+
|
|
97
|
+
const myRule: Principle = {
|
|
98
|
+
id: 'MY_01',
|
|
99
|
+
name: 'Healer Population Floor',
|
|
100
|
+
category: 'population',
|
|
101
|
+
description: 'Healer share below 5% is a crisis',
|
|
102
|
+
check(metrics, thresholds) {
|
|
103
|
+
const share = metrics.roleShares['Healer'] ?? 0;
|
|
104
|
+
if (share < 0.05) {
|
|
105
|
+
return {
|
|
106
|
+
violated: true,
|
|
107
|
+
severity: 8,
|
|
108
|
+
evidence: { share },
|
|
109
|
+
suggestedAction: {
|
|
110
|
+
parameter: 'healerReward',
|
|
111
|
+
direction: 'increase',
|
|
112
|
+
magnitude: 0.25,
|
|
113
|
+
reasoning: 'Healer population critically low.',
|
|
114
|
+
},
|
|
115
|
+
confidence: 0.90,
|
|
116
|
+
estimatedLag: 10,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
return { violated: false };
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
agent.addPrinciple(myRule);
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Performance
|
|
127
|
+
|
|
128
|
+
- **O(N) event classification** — single-pass instead of 6 separate filters
|
|
129
|
+
- **Cached diagnosis** — no redundant principle checks within the same tick
|
|
130
|
+
- **Numerical stability** — clamped inputs to prevent NaN edge cases
|
|
131
|
+
|
|
132
|
+
Typical for 1,000 agents, 100 events/tick: ~60ms end-to-end.
|
|
133
|
+
|
|
134
|
+
## License
|
|
135
|
+
|
|
136
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-e/core",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Autonomous economic balancer — observe, diagnose, simulate, plan, execute",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
|
-
"dist"
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md"
|
|
23
24
|
],
|
|
24
25
|
"scripts": {
|
|
25
26
|
"build": "tsup",
|