-
-
Notifications
You must be signed in to change notification settings - Fork 442
Expand file tree
/
Copy pathnat2
More file actions
369 lines (300 loc) · 15.6 KB
/
nat2
File metadata and controls
369 lines (300 loc) · 15.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
Yes. Now we're talking about something real.
---
## Barrel Platform
**"Distributed AI routing. Edge to device. You control the path."**
---
## The Full Picture
```
┌─────────────────────────────────────────────────────────────────────────────┐
│ BARREL PLATFORM │
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ BARREL EDGE (Your POPs) │ │
│ │ │ │
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │ │
│ │ │ barrellm │ │barrel_memory│ │ Provider Connections │ │ │
│ │ │ (central) │ │ (primary) │ │ │ │ │
│ │ │ │ │ │ │ Claude ──────────────│ │ │
│ │ │ • Policies │ │ • Full sync │ │ GPT ─────────────────│ │ │
│ │ │ • Billing │ │ • Search │ │ DeepSeek ────────────│ │ │
│ │ │ • Analytics │ │ • Backup │ │ Mistral ─────────────│ │ │
│ │ └──────▲──────┘ └──────▲──────┘ └─────────────────────┘ │ │
│ │ │ │ │ │
│ │ │ Encrypted Tunnel (WireGuard/QUIC) │ │
│ │ │ │ │ │
│ └──────────┼──────────────────┼───────────────────────────────────────┘ │
│ │ │ │
│ ▼ ▼ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ BARREL AGENT (User's Devices) │ │
│ │ │ │
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │ │
│ │ │ barrellm │ │barrel_memory│ │ Local Inference │ │ │
│ │ │ (local) │ │ (local) │ │ │ │ │
│ │ │ │ │ │ │ Ollama ──────────────│ │ │
│ │ │ • Routing │ │ • Cache │ │ LMStudio ────────────│ │ │
│ │ │ decisions │ │ • Hot data │ │ llama.cpp ───────────│ │ │
│ │ │ • Offline │ │ • Sync │ │ MLX ─────────────────│ │ │
│ │ │ capable │ │ │ │ │ │ │
│ │ └─────────────┘ └─────────────┘ └─────────────────────┘ │ │
│ │ │ │ │
│ │ │ Routes to: │ │
│ │ ├─► Local LLM (fast, free, private) │ │
│ │ ├─► Edge gateway (Claude/GPT, when needed) │ │
│ │ └─► Direct to provider (bypass edge, if configured) │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────┘
```
---
## The Routing Intelligence
This is where it gets powerful. The local barrellm decides per-request:
```
User: "What time is my meeting tomorrow?"
│
▼
┌─────────────────────────────────────┐
│ Local barrellm Decision Tree │
│ │
│ 1. Need memory? ──► Check local cache│
│ └─► Miss? ──► Fetch from edge │
│ │
│ 2. Task complexity? │
│ └─► Simple ──► Local LLM │
│ └─► Complex ──► Edge gateway │
│ │
│ 3. Privacy policy? │
│ └─► "Keep local" ──► Local LLM │
│ └─► "Allow cloud" ──► Best route │
│ │
│ 4. Latency requirement? │
│ └─► Real-time ──► Fastest path │
│ └─► Batch ──► Cheapest path │
│ │
│ 5. Cost budget? │
│ └─► Under limit ──► Best model │
│ └─► Over limit ──► Local fallback │
└─────────────────────────────────────┘
```
---
## Routing Scenarios
| Request | Decision | Why |
|---------|----------|-----|
| "Summarize this PDF" | Local LLM (Llama 70B) | Large context, local is cheaper |
| "Write me a poem about X" | Local LLM | Creative, doesn't need frontier |
| "Debug this code" | Edge → Claude | Complex reasoning |
| "What did I decide about Y?" | Local memory cache | Already synced |
| "Research competitors" | Edge → Claude + tools | Needs web access |
| "Quick question while offline" | Local LLM | No connectivity |
| "Analyze this medical report" | Local LLM (policy: private) | User config: medical = local only |
---
## The Policy System
Users define rules. barrellm (local + edge) enforces them.
```yaml
# Example user policy
routing:
default: auto # let barrellm decide
rules:
- match: { contains: ["medical", "health", "diagnosis"] }
route: local_only
reason: "Keep health data off cloud"
- match: { task: "code_review" }
route: prefer_edge
model: claude-sonnet
reason: "Best for code"
- match: { task: "translation" }
route: local_first
fallback: edge
reason: "Local handles most languages"
- match: { tokens_estimate: ">50000" }
route: local_only
reason: "Too expensive for cloud"
cost:
daily_limit: 5.00 EUR
when_exceeded: local_fallback
privacy:
memory_sync: true
sync_filter:
exclude: ["medical", "financial", "passwords"]
```
---
## Memory Architecture
Two-tier memory that stays in sync:
```
┌─────────────────────────────────────────────────────────────┐
│ EDGE (barrel_memory primary) │
│ │
│ • Full memory store │
│ • Vector search (barrel_vectordb) │
│ • Cross-device sync source │
│ • Backup / durability │
│ • Search API for MCP clients │
└─────────────────────────────────────────────────────────────┘
▲
│ Sync (encrypted)
│ • Delta updates
│ • Conflict resolution
│ • Offline queue
▼
┌─────────────────────────────────────────────────────────────┐
│ LOCAL (barrel_memory cache) │
│ │
│ • Hot data (recent, frequent) │
│ • Local vector index │
│ • Works offline │
│ • Privacy filter (some memories never sync) │
└─────────────────────────────────────────────────────────────┘
```
**Sync behavior:**
- Local writes → queue → sync to edge when connected
- Edge writes (from other devices) → push to connected locals
- Conflict: last-write-wins or user-defined
- Privacy filter: some memories marked "local only", never leave device
---
## What Barrel Agent Looks Like
Single binary (Erlang release). Runs on:
- Linux server / NUC / Raspberry Pi
- macOS (background daemon)
- Windows (service)
- Docker
```
barrel-agent
├── barrellm (local routing engine)
├── barrel_memory (local cache + sync)
├── barrel_tunnel (connection to edge)
├── barrel_llm_bridge
│ ├── ollama adapter
│ ├── lmstudio adapter
│ ├── llama.cpp adapter
│ └── custom endpoint support
├── barrel_integrations
│ ├── telegram bot
│ ├── discord bot
│ ├── slack bot
│ ├── whatsapp bridge
│ ├── matrix bridge
│ └── webhook server
└── barrel_tools
├── file access
├── shell execution
├── browser automation
└── custom skills
```
---
## Deployment Modes
### Mode 1: Edge Only (Zero Local)
```
[Phone/Laptop] ──► [Barrel Edge] ──► [AI Providers]
```
- No local agent
- Everything runs on POP
- Simplest setup
- For: "I just want it to work"
### Mode 2: Edge + Tunnel (Light Local)
```
[Telegram Bot] ──► [Barrel Agent] ══tunnel══► [Barrel Edge] ──► [AI]
(local) (routing) (memory+AI)
```
- Local agent handles integrations
- Edge handles AI + memory
- For: "I want to run my own bots"
### Mode 3: Hybrid (Full Local)
```
[Telegram Bot] ──► [Barrel Agent] ──► [Local LLM]
(local) │ (smart
│ routing)
│
══tunnel══► [Barrel Edge] ──► [Claude/GPT]
(fallback + sync)
```
- Local handles what it can
- Edge for frontier models + memory sync
- For: "I have a GPU and want to use it"
### Mode 4: Sovereign (Minimal Edge)
```
[Everything Local] ══tunnel══► [Barrel Edge]
(relay + backup only)
```
- Full agent + memory locally
- Edge just for connectivity + backup sync
- For: "Maximum privacy, I own everything"
---
## Pricing Aligned to Modes
| Tier | Mode | Price | Includes |
|------|------|-------|----------|
| **Lite** | Edge Only | €9/mo | 500 msgs/day, basic memory, 1 POP |
| **Standard** | Edge + Tunnel | €19/mo | Unlimited, full memory, 5 devices, all POPs |
| **Power** | Hybrid | €29/mo | + Local routing, unlimited devices, API access |
| **Sovereign** | Minimal Edge | €12/mo | Relay + backup only, you run everything |
| **Team** | Any | €79/mo | 5 users, shared spaces, admin controls |
**Add-ons:**
- AI Credits (non-BYOK): €10 = ~500k tokens
- Priority edge routing: €10/mo
- Extra storage: €2/GB/mo
---
## The Erlang Advantage
This architecture plays perfectly to Erlang/OTP:
| Challenge | Erlang Solution |
|-----------|-----------------|
| Local agent needs to be rock-solid | OTP supervision trees, auto-restart |
| Multiple concurrent connections | Millions of lightweight processes |
| Tunnel management | gen_tcp/gen_udp, ssl, built for this |
| Sync with conflict resolution | Distributed Erlang, CRDT-friendly |
| Hot code reload | Update agent without restart |
| Cross-platform | Single release, runs everywhere |
You're not fighting the runtime. You're using it exactly right.
---
## Competitive Moat
| Competitor | What They Can't Do |
|------------|-------------------|
| Clawdbot | No edge infrastructure, single machine |
| OpenRouter | No memory, no local routing |
| Tailscale | No AI services |
| OpenAI/Anthropic | No local routing, no privacy |
| Local-only (Ollama) | No cloud fallback, no sync |
**Barrel Platform is the only option that spans edge-to-device with intelligent routing.**
---
## The Pitch (Refined)
### Tagline:
> **Barrel Platform** — Your AI runs everywhere. Edge. Device. Your rules.
### One-liner:
> Private AI infrastructure that spans our European edge and your devices. Smart routing. Persistent memory. Real privacy.
### For different audiences:
**Normal user:**
> Sign up. Your AI remembers everything. Works from any device. Lives in Europe.
**Technical user:**
> Distributed barrellm routing. Local LLMs when it makes sense, frontier models when you need them. Memory syncs. You set the policies.
**Privacy-conscious:**
> Run your own bots. Route sensitive stuff to local LLMs. Some memories never leave your device. We can't read what we don't have.
**Enterprise:**
> EU-hosted edge. Private tunnels. Audit everything. Deploy agents that span cloud and on-prem.
---
## MVP Scope
What's the minimum to prove this works?
**Phase 1: Edge Only (4 weeks)**
- barrellm on POPs (you have this)
- barrel_memory on POPs (you have this)
- Telegram integration (managed by you)
- Web dashboard (signup, config, memory viewer)
- Waitlist → beta users
**Phase 2: Tunnel + Local Agent (4 weeks)**
- barrel-agent binary (Erlang release)
- Tunnel server on POPs
- Local Telegram bot support
- Memory sync
**Phase 3: Local LLM Routing (4 weeks)**
- Ollama adapter
- Routing policies
- Hybrid mode working
**Phase 4: Polish + Launch**
- More integrations
- Better dashboard
- Pricing live
- Marketing push
---
Want me to:
1. Draft the landing page copy for Barrel Platform?
2. Spec out the routing policy DSL?
3. Design the tunnel protocol?
4. Something else?