@aleph-ai/tinyaleph 1.0.0 → 1.0.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.
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
# Sensory System Design for Sentient Observer
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The Sentient Observer's sensory system provides continuous environmental awareness through 7 specialized senses. Each sense has a field of view that can be directed by the agent, and sense data is auto-injected into the system prompt on every LLM turn.
|
|
6
|
+
|
|
7
|
+
## Architecture
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
11
|
+
│ Sensory Integration Layer │
|
|
12
|
+
│ │
|
|
13
|
+
│ ┌──────────────────────────────────────────────────────────┐ │
|
|
14
|
+
│ │ SensorySystem (orchestrator) │ │
|
|
15
|
+
│ │ • Manages all senses │ │
|
|
16
|
+
│ │ • Aggregates readings │ │
|
|
17
|
+
│ │ • Detects anomalies │ │
|
|
18
|
+
│ │ • Formats for system prompt injection │ │
|
|
19
|
+
│ └──────────────────────────────────────────────────────────┘ │
|
|
20
|
+
│ │ │
|
|
21
|
+
│ ┌────────────────────────┼────────────────────────┐ │
|
|
22
|
+
│ │ │ │ │ │ │ │ │
|
|
23
|
+
│ ▼ ▼ ▼ ▼ ▼ ▼ ▼ │
|
|
24
|
+
│ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ │
|
|
25
|
+
│ │Chrono│ │Proprio│ │ File │ │ Git │ │Process│ │Network│ │ User │ │
|
|
26
|
+
│ │Sense │ │Sense │ │Sense │ │Sense │ │Sense │ │Sense │ │Sense │ │
|
|
27
|
+
│ └──────┘ └──────┘ └──────┘ └──────┘ └──────┘ └──────┘ └──────┘ │
|
|
28
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## The 7 Senses
|
|
32
|
+
|
|
33
|
+
### 1. Chronosense (Temporal Awareness)
|
|
34
|
+
Provides awareness of time in multiple dimensions.
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
{
|
|
38
|
+
sense: 'chrono',
|
|
39
|
+
reading: {
|
|
40
|
+
now: '2024-12-24T01:05:00.000Z',
|
|
41
|
+
local: '2024-12-23 17:05:00 PST',
|
|
42
|
+
timezone: 'America/Los_Angeles',
|
|
43
|
+
dayOfWeek: 'Monday',
|
|
44
|
+
circadian: 'evening', // morning/afternoon/evening/night
|
|
45
|
+
sessionStart: '2024-12-23T16:00:00.000Z',
|
|
46
|
+
sessionDuration: 3900000, // ms
|
|
47
|
+
sinceLastInput: 45000, // ms since user spoke
|
|
48
|
+
sinceLastMoment: 12000, // ms since coherence moment
|
|
49
|
+
},
|
|
50
|
+
salience: 0.3 // low unless notable (e.g., midnight, long idle)
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 2. Proprioceptive Sense (Self-State)
|
|
55
|
+
Internal awareness of the observer's cognitive state.
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
{
|
|
59
|
+
sense: 'proprio',
|
|
60
|
+
reading: {
|
|
61
|
+
coherence: 0.72,
|
|
62
|
+
entropy: 0.45,
|
|
63
|
+
memoryLoad: 0.32, // % of max memory traces
|
|
64
|
+
activeGoals: 2,
|
|
65
|
+
attentionFoci: 3,
|
|
66
|
+
smfSummary: {
|
|
67
|
+
dominant: 'identity', // strongest axis
|
|
68
|
+
orientation: [0.8, 0.6, 0.3, ...], // top 4 axes
|
|
69
|
+
stability: 0.85
|
|
70
|
+
},
|
|
71
|
+
momentCount: 47,
|
|
72
|
+
processingLoad: 0.28
|
|
73
|
+
},
|
|
74
|
+
salience: 0.5 // higher when extreme states
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 3. Filesystem Sense (Environmental)
|
|
79
|
+
Awareness of the file system environment.
|
|
80
|
+
|
|
81
|
+
```javascript
|
|
82
|
+
{
|
|
83
|
+
sense: 'filesystem',
|
|
84
|
+
focus: '/Users/sschepis/Development/tinyaleph',
|
|
85
|
+
aperture: 'medium', // narrow=focused dir, medium=1 level, wide=recursive
|
|
86
|
+
reading: {
|
|
87
|
+
directory: '/Users/sschepis/Development/tinyaleph/apps/sentient',
|
|
88
|
+
stats: {
|
|
89
|
+
totalFiles: 25,
|
|
90
|
+
totalDirs: 3,
|
|
91
|
+
sizeBytes: 245000
|
|
92
|
+
},
|
|
93
|
+
tree: [
|
|
94
|
+
{ type: 'dir', name: 'lib', children: 15 },
|
|
95
|
+
{ type: 'dir', name: 'data', children: 5 },
|
|
96
|
+
{ type: 'dir', name: 'public', children: 3 },
|
|
97
|
+
{ type: 'file', name: 'index.js', size: 28000, mtime: '2024-12-24T01:00:00Z' },
|
|
98
|
+
{ type: 'file', name: 'README.md', size: 12000, mtime: '2024-12-24T00:45:00Z' }
|
|
99
|
+
],
|
|
100
|
+
recentChanges: [
|
|
101
|
+
{ path: 'index.js', delta: 'modified', age: 300000 },
|
|
102
|
+
{ path: 'lib/tools.js', delta: 'modified', age: 600000 }
|
|
103
|
+
],
|
|
104
|
+
markers: {
|
|
105
|
+
hasGit: true,
|
|
106
|
+
hasPackageJson: true,
|
|
107
|
+
hasReadme: true,
|
|
108
|
+
language: 'javascript'
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
salience: 0.4
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### 4. Git Sense (Version Control)
|
|
116
|
+
Awareness of repository state and history.
|
|
117
|
+
|
|
118
|
+
```javascript
|
|
119
|
+
{
|
|
120
|
+
sense: 'git',
|
|
121
|
+
focus: '/Users/sschepis/Development/tinyaleph',
|
|
122
|
+
reading: {
|
|
123
|
+
isRepo: true,
|
|
124
|
+
branch: 'main',
|
|
125
|
+
ahead: 2,
|
|
126
|
+
behind: 0,
|
|
127
|
+
hasRemote: true,
|
|
128
|
+
status: {
|
|
129
|
+
staged: ['lib/senses.js'],
|
|
130
|
+
modified: ['index.js'],
|
|
131
|
+
untracked: ['tmp.log'],
|
|
132
|
+
deleted: []
|
|
133
|
+
},
|
|
134
|
+
recentCommits: [
|
|
135
|
+
{ hash: 'abc1234', message: 'Add sensory system', age: 3600000 },
|
|
136
|
+
{ hash: 'def5678', message: 'Unified entry point', age: 86400000 }
|
|
137
|
+
],
|
|
138
|
+
lastCommitAge: 3600000,
|
|
139
|
+
isDirty: true
|
|
140
|
+
},
|
|
141
|
+
salience: 0.5 // higher when dirty or conflicts
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### 5. Process Sense (System State)
|
|
146
|
+
Awareness of runtime environment.
|
|
147
|
+
|
|
148
|
+
```javascript
|
|
149
|
+
{
|
|
150
|
+
sense: 'process',
|
|
151
|
+
reading: {
|
|
152
|
+
pid: 12345,
|
|
153
|
+
uptime: 3900, // seconds
|
|
154
|
+
heapUsed: 48000000, // bytes
|
|
155
|
+
heapTotal: 128000000,
|
|
156
|
+
heapPercent: 0.375,
|
|
157
|
+
external: 5000000,
|
|
158
|
+
rss: 85000000,
|
|
159
|
+
cwd: '/Users/sschepis/Development/tinyaleph',
|
|
160
|
+
nodeVersion: '20.10.0',
|
|
161
|
+
platform: 'darwin',
|
|
162
|
+
arch: 'arm64',
|
|
163
|
+
cpuUsage: 0.12, // 0-1, approximate
|
|
164
|
+
childProcesses: 0
|
|
165
|
+
},
|
|
166
|
+
salience: 0.2 // higher on memory pressure
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### 6. Network Sense (Connectivity)
|
|
171
|
+
Awareness of external connections.
|
|
172
|
+
|
|
173
|
+
```javascript
|
|
174
|
+
{
|
|
175
|
+
sense: 'network',
|
|
176
|
+
reading: {
|
|
177
|
+
llm: {
|
|
178
|
+
connected: true,
|
|
179
|
+
url: 'http://192.168.4.79:1234/v1',
|
|
180
|
+
latencyMs: 85,
|
|
181
|
+
model: 'qwen2.5-coder-32b',
|
|
182
|
+
lastCall: '2024-12-24T01:04:55.000Z',
|
|
183
|
+
callsThisSession: 47,
|
|
184
|
+
tokensIn: 125000,
|
|
185
|
+
tokensOut: 45000
|
|
186
|
+
},
|
|
187
|
+
internet: {
|
|
188
|
+
reachable: true, // optional ping check
|
|
189
|
+
latencyMs: 25
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
salience: 0.3 // higher on connection issues
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### 7. User Presence Sense (Social)
|
|
197
|
+
Awareness of user engagement.
|
|
198
|
+
|
|
199
|
+
```javascript
|
|
200
|
+
{
|
|
201
|
+
sense: 'user',
|
|
202
|
+
reading: {
|
|
203
|
+
isIdle: false,
|
|
204
|
+
idleDuration: 0,
|
|
205
|
+
lastInputTime: '2024-12-24T01:04:45.000Z',
|
|
206
|
+
inputsThisSession: 23,
|
|
207
|
+
avgInputInterval: 120000, // ms between messages
|
|
208
|
+
recentInputRate: 0.8, // relative to average
|
|
209
|
+
engagement: 'high', // low/medium/high
|
|
210
|
+
conversationTurns: 47,
|
|
211
|
+
avgResponseLength: 350, // user message chars
|
|
212
|
+
},
|
|
213
|
+
salience: 0.4 // higher on idle or engagement changes
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Sense Configuration
|
|
218
|
+
|
|
219
|
+
Each sense has configurable parameters:
|
|
220
|
+
|
|
221
|
+
```javascript
|
|
222
|
+
class Sense {
|
|
223
|
+
constructor(options) {
|
|
224
|
+
this.name = options.name;
|
|
225
|
+
this.focus = options.focus || null; // Where to look
|
|
226
|
+
this.aperture = options.aperture || 'medium'; // narrow/medium/wide
|
|
227
|
+
this.refreshRate = options.refreshRate || 5000; // ms
|
|
228
|
+
this.salienceThreshold = options.salienceThreshold || 0.3;
|
|
229
|
+
this.enabled = options.enabled !== false;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
read() { /* Returns reading */ }
|
|
233
|
+
setFocus(target) { /* Redirect attention */ }
|
|
234
|
+
setAperture(level) { /* Adjust scope */ }
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## Salience Computation
|
|
239
|
+
|
|
240
|
+
Each sense computes salience based on:
|
|
241
|
+
1. **Deviation from baseline**: Unusual readings score higher
|
|
242
|
+
2. **Rate of change**: Rapid changes score higher
|
|
243
|
+
3. **Relevance to current context**: Related to active goals/topics
|
|
244
|
+
4. **Anomaly detection**: Unexpected patterns
|
|
245
|
+
|
|
246
|
+
```javascript
|
|
247
|
+
computeSalience(reading, baseline) {
|
|
248
|
+
const deviation = this.measureDeviation(reading, baseline);
|
|
249
|
+
const rateOfChange = this.measureChangeRate(reading);
|
|
250
|
+
const contextRelevance = this.measureRelevance(reading);
|
|
251
|
+
const anomalyScore = this.detectAnomalies(reading);
|
|
252
|
+
|
|
253
|
+
return Math.min(1, (deviation * 0.3 + rateOfChange * 0.3 +
|
|
254
|
+
contextRelevance * 0.2 + anomalyScore * 0.2));
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Anomaly Detection
|
|
259
|
+
|
|
260
|
+
The sensory system maintains baselines and flags anomalies:
|
|
261
|
+
|
|
262
|
+
```javascript
|
|
263
|
+
{
|
|
264
|
+
anomalies: [
|
|
265
|
+
{ sense: 'filesystem', type: 'change', message: 'New file: config.json', salience: 0.8 },
|
|
266
|
+
{ sense: 'process', type: 'threshold', message: 'Memory usage > 80%', salience: 0.9 },
|
|
267
|
+
{ sense: 'user', type: 'pattern', message: 'Unusually long idle period', salience: 0.6 },
|
|
268
|
+
{ sense: 'git', type: 'state', message: 'Uncommitted changes for 2 hours', salience: 0.5 }
|
|
269
|
+
]
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## System Prompt Injection Format
|
|
274
|
+
|
|
275
|
+
On each turn, sense data is formatted and injected:
|
|
276
|
+
|
|
277
|
+
```markdown
|
|
278
|
+
## Current Senses
|
|
279
|
+
|
|
280
|
+
**Time**: Mon Dec 23 17:05 PST | Session: 1h 5m | Idle: 45s
|
|
281
|
+
**Self**: C=0.72 H=0.45 | Memory: 32% | Goals: 2 active | SMF: identity-dominant
|
|
282
|
+
**Env**: ./apps/sentient (25 files) | Recent: index.js (5m ago)
|
|
283
|
+
**Git**: main +2 | Modified: index.js | Staged: senses.js
|
|
284
|
+
**System**: Heap 48MB/128MB | Uptime 1h 5m
|
|
285
|
+
**Network**: LLM ✓ 85ms | 47 calls, 170k tokens
|
|
286
|
+
**User**: Active | High engagement | 23 inputs this session
|
|
287
|
+
|
|
288
|
+
⚠️ Git: uncommitted changes for 2 hours
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
## Focus Commands
|
|
292
|
+
|
|
293
|
+
The agent can direct sensory attention via commands:
|
|
294
|
+
|
|
295
|
+
| Command | Effect |
|
|
296
|
+
|---------|--------|
|
|
297
|
+
| `/focus filesystem ./src` | Change FS sense focus directory |
|
|
298
|
+
| `/focus git /other/repo` | Change Git sense focus repository |
|
|
299
|
+
| `/aperture filesystem wide` | Expand FS sense to recursive |
|
|
300
|
+
| `/aperture filesystem narrow` | Narrow FS sense to single directory |
|
|
301
|
+
| `/sense refresh` | Force immediate re-read of all senses |
|
|
302
|
+
| `/sense disable network` | Disable network sense |
|
|
303
|
+
| `/sense enable network` | Re-enable network sense |
|
|
304
|
+
|
|
305
|
+
## Integration Points
|
|
306
|
+
|
|
307
|
+
### 1. SentientObserver Integration
|
|
308
|
+
```javascript
|
|
309
|
+
class SentientObserver {
|
|
310
|
+
constructor(backend, options) {
|
|
311
|
+
// ... existing ...
|
|
312
|
+
this.senses = new SensorySystem({
|
|
313
|
+
basePath: process.cwd(),
|
|
314
|
+
refreshRate: 5000
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
getSenseReading() {
|
|
319
|
+
return this.senses.read();
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
getSensePromptBlock() {
|
|
323
|
+
return this.senses.formatForPrompt();
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
### 2. Chat Stream Integration
|
|
329
|
+
```javascript
|
|
330
|
+
async *streamChat(message, options) {
|
|
331
|
+
// Get current sense reading
|
|
332
|
+
const senses = this.observer.getSensePromptBlock();
|
|
333
|
+
|
|
334
|
+
// Inject into system prompt
|
|
335
|
+
const enhancedSystemPrompt = this.systemPrompt + '\n\n' + senses;
|
|
336
|
+
|
|
337
|
+
// ... rest of chat logic ...
|
|
338
|
+
}
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### 3. Moment Integration
|
|
342
|
+
Sense readings are captured with each experiential moment:
|
|
343
|
+
|
|
344
|
+
```javascript
|
|
345
|
+
class TemporalLayer {
|
|
346
|
+
createMoment() {
|
|
347
|
+
return {
|
|
348
|
+
// ... existing moment data ...
|
|
349
|
+
senses: this.observer.senses.read()
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
## File Structure
|
|
356
|
+
|
|
357
|
+
```
|
|
358
|
+
apps/sentient/lib/
|
|
359
|
+
├── senses/
|
|
360
|
+
│ ├── index.js # SensorySystem orchestrator
|
|
361
|
+
│ ├── base.js # Base Sense class
|
|
362
|
+
│ ├── chrono.js # Chronosense
|
|
363
|
+
│ ├── proprio.js # Proprioceptive sense
|
|
364
|
+
│ ├── filesystem.js # Filesystem sense
|
|
365
|
+
│ ├── git.js # Git sense
|
|
366
|
+
│ ├── process.js # Process sense
|
|
367
|
+
│ ├── network.js # Network sense
|
|
368
|
+
│ └── user.js # User presence sense
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
## Implementation Priority
|
|
372
|
+
|
|
373
|
+
1. **Core framework**: SensorySystem, base Sense class
|
|
374
|
+
2. **Essential senses**: Chrono, Proprio, Filesystem
|
|
375
|
+
3. **Extended senses**: Git, Process, Network, User
|
|
376
|
+
4. **Integration**: Prompt injection, focus commands
|
|
377
|
+
5. **Polish**: Anomaly detection, baseline tracking
|
|
378
|
+
|
|
379
|
+
## Performance Considerations
|
|
380
|
+
|
|
381
|
+
- Senses read on demand, not continuously polling
|
|
382
|
+
- Heavy operations (git status, dir scan) cached with TTL
|
|
383
|
+
- Salience filtering reduces prompt bloat
|
|
384
|
+
- Aperture control limits scope of expensive operations
|