rust-kgdb 0.5.6 → 0.5.7
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/CHANGELOG.md +84 -0
- package/README.md +196 -0
- package/examples/hypermind-agent-architecture.js +1709 -0
- package/hypermind-agent.js +617 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,90 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to the rust-kgdb TypeScript SDK will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [0.5.7] - 2025-12-15
|
|
6
|
+
|
|
7
|
+
### HyperMind Architecture Components - Production-Ready Framework
|
|
8
|
+
|
|
9
|
+
This release adds the complete HyperMind agent architecture with production-ready components for building neuro-symbolic AI systems.
|
|
10
|
+
|
|
11
|
+
#### New Architecture Components
|
|
12
|
+
|
|
13
|
+
**TypeId System (Hindley-Milner Style)**
|
|
14
|
+
```javascript
|
|
15
|
+
const { TypeId } = require('rust-kgdb/hypermind-agent')
|
|
16
|
+
|
|
17
|
+
// Base types
|
|
18
|
+
TypeId.String, TypeId.Int64, TypeId.Float64, TypeId.Bool
|
|
19
|
+
|
|
20
|
+
// RDF-native types
|
|
21
|
+
TypeId.Node, TypeId.Triple, TypeId.BindingSet
|
|
22
|
+
|
|
23
|
+
// Compound types
|
|
24
|
+
TypeId.List('Fact'), TypeId.Option('String'), TypeId.Result('T', 'Error')
|
|
25
|
+
|
|
26
|
+
// Refinement types for business domains
|
|
27
|
+
TypeId.RiskScore, // 0.0..1.0
|
|
28
|
+
TypeId.PolicyNumber, // POL-NNNN-NNNN
|
|
29
|
+
TypeId.ClaimAmount // Currency > 0
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**LLMPlanner Class**
|
|
33
|
+
- Natural language → typed tool pipelines
|
|
34
|
+
- Intent decomposition with domain awareness
|
|
35
|
+
- Type composition validation at plan time
|
|
36
|
+
- Confidence scoring for execution plans
|
|
37
|
+
|
|
38
|
+
**WasmSandbox Class**
|
|
39
|
+
- Capability-based security (ReadKG, ExecuteTool, WriteKG)
|
|
40
|
+
- Fuel metering for resource limits
|
|
41
|
+
- Memory isolation (configurable limits)
|
|
42
|
+
- Full audit logging via Object Proxy
|
|
43
|
+
|
|
44
|
+
**AgentBuilder (Fluent Builder Pattern)**
|
|
45
|
+
```javascript
|
|
46
|
+
const agent = new AgentBuilder('compliance-checker')
|
|
47
|
+
.withTool('kg.sparql.query')
|
|
48
|
+
.withTool('kg.datalog.infer')
|
|
49
|
+
.withPlanner(new LLMPlanner('claude-sonnet-4', TOOL_REGISTRY))
|
|
50
|
+
.withSandbox({ capabilities: ['ReadKG'], fuelLimit: 1000000 })
|
|
51
|
+
.withHook('afterExecute', (step, result) => console.log(step.tool))
|
|
52
|
+
.build()
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**ComposedAgent**
|
|
56
|
+
- Executable agent with full execution witness
|
|
57
|
+
- SHA-256 cryptographic proof hashes
|
|
58
|
+
- Complete audit trail for compliance
|
|
59
|
+
|
|
60
|
+
#### New Example: Complete Architecture Demo
|
|
61
|
+
|
|
62
|
+
`examples/hypermind-agent-architecture.js` - 1000+ line comprehensive demo:
|
|
63
|
+
1. Problem Statement (Why current AI agents fail)
|
|
64
|
+
2. High-Level Architecture Diagram
|
|
65
|
+
3. Sequence Diagram (User → SDK → Planner → Sandbox → KG)
|
|
66
|
+
4. Component Interaction Diagram
|
|
67
|
+
5. Type System Foundation (TypeId)
|
|
68
|
+
6. WASM Sandbox Security
|
|
69
|
+
7. Agent Composition
|
|
70
|
+
8. Core Concepts (Type/Category/Proof Theory)
|
|
71
|
+
9. HyperMind vs MCP Comparison
|
|
72
|
+
10. Live Agent Demonstration
|
|
73
|
+
|
|
74
|
+
#### Updated README.md
|
|
75
|
+
|
|
76
|
+
- Added "HyperMind Architecture Deep Dive" section with ASCII diagrams
|
|
77
|
+
- Added "HyperMind vs MCP" comparison showing domain proxy advantages
|
|
78
|
+
- Full code examples for AgentBuilder pattern
|
|
79
|
+
|
|
80
|
+
#### New Exports
|
|
81
|
+
|
|
82
|
+
```javascript
|
|
83
|
+
const {
|
|
84
|
+
TypeId, TOOL_REGISTRY, LLMPlanner, WasmSandbox,
|
|
85
|
+
AgentBuilder, ComposedAgent
|
|
86
|
+
} = require('rust-kgdb/hypermind-agent')
|
|
87
|
+
```
|
|
88
|
+
|
|
5
89
|
## [0.5.6] - 2025-12-15
|
|
6
90
|
|
|
7
91
|
### Enhanced HyperMind Examples - Show REAL Power
|
package/README.md
CHANGED
|
@@ -253,6 +253,202 @@ console.log('Inferred:', evaluateDatalog(datalog))
|
|
|
253
253
|
|
|
254
254
|
---
|
|
255
255
|
|
|
256
|
+
## HyperMind Architecture Deep Dive
|
|
257
|
+
|
|
258
|
+
For a complete walkthrough of the architecture, run:
|
|
259
|
+
```bash
|
|
260
|
+
node examples/hypermind-agent-architecture.js
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Full System Architecture
|
|
264
|
+
|
|
265
|
+
```
|
|
266
|
+
╔════════════════════════════════════════════════════════════════════════════════╗
|
|
267
|
+
║ HYPERMIND NEURO-SYMBOLIC ARCHITECTURE ║
|
|
268
|
+
╠════════════════════════════════════════════════════════════════════════════════╣
|
|
269
|
+
║ ║
|
|
270
|
+
║ ┌────────────────────────────────────────────────────────────────────────┐ ║
|
|
271
|
+
║ │ APPLICATION LAYER │ ║
|
|
272
|
+
║ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ ║
|
|
273
|
+
║ │ │ Fraud │ │ Underwriting│ │ Compliance │ │ Custom │ │ ║
|
|
274
|
+
║ │ │ Detection │ │ Agent │ │ Checker │ │ Agents │ │ ║
|
|
275
|
+
║ │ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │ ║
|
|
276
|
+
║ └─────────┼────────────────┼────────────────┼────────────────┼───────────┘ ║
|
|
277
|
+
║ └────────────────┴────────┬───────┴────────────────┘ ║
|
|
278
|
+
║ │ ║
|
|
279
|
+
║ ┌───────────────────────────────────┼────────────────────────────────────┐ ║
|
|
280
|
+
║ │ HYPERMIND RUNTIME │ ║
|
|
281
|
+
║ │ ┌────────────────┐ ┌─────────┴─────────┐ ┌─────────────────┐ │ ║
|
|
282
|
+
║ │ │ LLM PLANNER │ │ PLAN EXECUTOR │ │ WASM SANDBOX │ │ ║
|
|
283
|
+
║ │ │ • Claude/GPT │───▶│ • Type validation │───▶│ • Capabilities │ │ ║
|
|
284
|
+
║ │ │ • Intent parse │ │ • Morphism compose│ │ • Fuel metering │ │ ║
|
|
285
|
+
║ │ │ • Tool select │ │ • Step execution │ │ • Memory limits │ │ ║
|
|
286
|
+
║ │ └────────────────┘ └───────────────────┘ └────────┬────────┘ │ ║
|
|
287
|
+
║ │ │ │ ║
|
|
288
|
+
║ │ ┌───────────────────────────────────────────────────────┼───────────┐ │ ║
|
|
289
|
+
║ │ │ OBJECT PROXY (gRPC-style) │ │ │ ║
|
|
290
|
+
║ │ │ proxy.call("kg.sparql.query", args) ────────────────┤ │ │ ║
|
|
291
|
+
║ │ │ proxy.call("kg.motif.find", args) ────────────────┤ │ │ ║
|
|
292
|
+
║ │ │ proxy.call("kg.datalog.infer", args) ────────────────┤ │ │ ║
|
|
293
|
+
║ │ └───────────────────────────────────────────────────────┼───────────┘ │ ║
|
|
294
|
+
║ └──────────────────────────────────────────────────────────┼─────────────┘ ║
|
|
295
|
+
║ │ ║
|
|
296
|
+
║ ┌──────────────────────────────────────────────────────────┼─────────────┐ ║
|
|
297
|
+
║ │ HYPERMIND TOOLS │ │ ║
|
|
298
|
+
║ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌───┴─────────┐ │ ║
|
|
299
|
+
║ │ │ SPARQL │ │ MOTIF │ │ DATALOG │ │ EMBEDDINGS │ │ ║
|
|
300
|
+
║ │ │ String → │ │ Pattern → │ │ Rules → │ │ Entity → │ │ ║
|
|
301
|
+
║ │ │ BindingSet │ │ List<Match> │ │ List<Fact> │ │ List<Sim> │ │ ║
|
|
302
|
+
║ │ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘ │ ║
|
|
303
|
+
║ └────────────────────────────────────────────────────────────────────────┘ ║
|
|
304
|
+
║ ║
|
|
305
|
+
║ ┌────────────────────────────────────────────────────────────────────────┐ ║
|
|
306
|
+
║ │ rust-kgdb KNOWLEDGE GRAPH │ ║
|
|
307
|
+
║ │ RDF Triples | SPARQL 1.1 | GraphFrames | Embeddings | Datalog │ ║
|
|
308
|
+
║ │ 2.78µs lookups | 24 bytes/triple | 35x faster than RDFox │ ║
|
|
309
|
+
║ └────────────────────────────────────────────────────────────────────────┘ ║
|
|
310
|
+
╚════════════════════════════════════════════════════════════════════════════════╝
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
### Agent Execution Sequence
|
|
314
|
+
|
|
315
|
+
```
|
|
316
|
+
╔════════════════════════════════════════════════════════════════════════════════╗
|
|
317
|
+
║ HYPERMIND AGENT EXECUTION - SEQUENCE DIAGRAM ║
|
|
318
|
+
╠════════════════════════════════════════════════════════════════════════════════╣
|
|
319
|
+
║ ║
|
|
320
|
+
║ User SDK Planner Sandbox Proxy KG ║
|
|
321
|
+
║ │ │ │ │ │ │ ║
|
|
322
|
+
║ │ "Find suspicious claims" │ │ │ │ ║
|
|
323
|
+
║ │────────────▶│ │ │ │ │ ║
|
|
324
|
+
║ │ │ plan(prompt) │ │ │ │ ║
|
|
325
|
+
║ │ │─────────────▶│ │ │ │ ║
|
|
326
|
+
║ │ │ │ ┌──────────────────────────┐│ │ ║
|
|
327
|
+
║ │ │ │ │ LLM Reasoning: ││ │ ║
|
|
328
|
+
║ │ │ │ │ 1. Parse intent ││ │ ║
|
|
329
|
+
║ │ │ │ │ 2. Select tools ││ │ ║
|
|
330
|
+
║ │ │ │ │ 3. Validate types ││ │ ║
|
|
331
|
+
║ │ │ │ └──────────────────────────┘│ │ ║
|
|
332
|
+
║ │ │ Plan{steps, confidence} │ │ │ ║
|
|
333
|
+
║ │ │◀─────────────│ │ │ │ ║
|
|
334
|
+
║ │ │ execute(plan)│ │ │ │ ║
|
|
335
|
+
║ │ │─────────────────────────────▶ │ │ ║
|
|
336
|
+
║ │ │ │ ┌────────────────────────┐ │ │ ║
|
|
337
|
+
║ │ │ │ │ Sandbox Init: │ │ │ ║
|
|
338
|
+
║ │ │ │ │ • Capabilities: [Read] │ │ │ ║
|
|
339
|
+
║ │ │ │ │ • Fuel: 1,000,000 │ │ │ ║
|
|
340
|
+
║ │ │ │ └────────────────────────┘ │ │ ║
|
|
341
|
+
║ │ │ │ │ kg.sparql │ │ ║
|
|
342
|
+
║ │ │ │ │─────────────▶│───────────▶│ ║
|
|
343
|
+
║ │ │ │ │ │ BindingSet │ ║
|
|
344
|
+
║ │ │ │ │◀─────────────│◀───────────│ ║
|
|
345
|
+
║ │ │ │ │ kg.datalog │ │ ║
|
|
346
|
+
║ │ │ │ │─────────────▶│───────────▶│ ║
|
|
347
|
+
║ │ │ │ │ │ List<Fact> │ ║
|
|
348
|
+
║ │ │ │ │◀─────────────│◀───────────│ ║
|
|
349
|
+
║ │ │ ExecutionResult{findings, witness} │ │ ║
|
|
350
|
+
║ │ │◀───────────────────────────── │ │ ║
|
|
351
|
+
║ │ "Found 2 collusion patterns. Evidence: ..." │ │ ║
|
|
352
|
+
║ │◀────────────│ │ │ │ │ ║
|
|
353
|
+
╚════════════════════════════════════════════════════════════════════════════════╝
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
### New Architecture Components (v0.5.7+)
|
|
357
|
+
|
|
358
|
+
The TypeScript SDK now exports production-ready architecture classes:
|
|
359
|
+
|
|
360
|
+
```javascript
|
|
361
|
+
const {
|
|
362
|
+
// Type System (Hindley-Milner style)
|
|
363
|
+
TypeId, // Base types + refinement types (RiskScore, PolicyNumber)
|
|
364
|
+
TOOL_REGISTRY, // Tools as typed morphisms
|
|
365
|
+
|
|
366
|
+
// Runtime Components
|
|
367
|
+
LLMPlanner, // Natural language → typed tool pipelines
|
|
368
|
+
WasmSandbox, // Capability-based security with fuel metering
|
|
369
|
+
AgentBuilder, // Fluent builder for agent composition
|
|
370
|
+
ComposedAgent, // Executable agent with execution witness
|
|
371
|
+
} = require('rust-kgdb/hypermind-agent')
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
**Example: Build a Custom Agent**
|
|
375
|
+
```javascript
|
|
376
|
+
const { AgentBuilder, LLMPlanner, TypeId, TOOL_REGISTRY } = require('rust-kgdb/hypermind-agent')
|
|
377
|
+
|
|
378
|
+
// Compose an agent using the builder pattern
|
|
379
|
+
const agent = new AgentBuilder('compliance-checker')
|
|
380
|
+
.withTool('kg.sparql.query')
|
|
381
|
+
.withTool('kg.datalog.infer')
|
|
382
|
+
.withPlanner(new LLMPlanner('claude-sonnet-4', TOOL_REGISTRY))
|
|
383
|
+
.withSandbox({
|
|
384
|
+
capabilities: ['ReadKG', 'ExecuteTool'], // No WriteKG for safety
|
|
385
|
+
fuelLimit: 1000000,
|
|
386
|
+
maxMemory: 64 * 1024 * 1024 // 64MB
|
|
387
|
+
})
|
|
388
|
+
.withHook('afterExecute', (step, result) => {
|
|
389
|
+
console.log(`Completed: ${step.tool} → ${result.length} results`)
|
|
390
|
+
})
|
|
391
|
+
.build()
|
|
392
|
+
|
|
393
|
+
// Execute with natural language
|
|
394
|
+
const result = await agent.call("Check compliance status for all vendors")
|
|
395
|
+
console.log(result.witness.proof_hash) // sha256:...
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
---
|
|
399
|
+
|
|
400
|
+
## HyperMind vs MCP (Model Context Protocol)
|
|
401
|
+
|
|
402
|
+
Why domain-enriched proxies beat generic function calling:
|
|
403
|
+
|
|
404
|
+
```
|
|
405
|
+
┌───────────────────────┬──────────────────────┬──────────────────────────┐
|
|
406
|
+
│ Feature │ MCP │ HyperMind Proxy │
|
|
407
|
+
├───────────────────────┼──────────────────────┼──────────────────────────┤
|
|
408
|
+
│ Type Safety │ ❌ String only │ ✅ Full type system │
|
|
409
|
+
│ Domain Knowledge │ ❌ Generic │ ✅ Domain-enriched │
|
|
410
|
+
│ Tool Composition │ ❌ Isolated │ ✅ Morphism composition │
|
|
411
|
+
│ Validation │ ❌ Runtime │ ✅ Compile-time │
|
|
412
|
+
│ Security │ ❌ None │ ✅ WASM sandbox │
|
|
413
|
+
│ Audit Trail │ ❌ None │ ✅ Execution witness │
|
|
414
|
+
│ LLM Context │ ❌ Generic schema │ ✅ Rich domain hints │
|
|
415
|
+
│ Capability Control │ ❌ All or nothing │ ✅ Fine-grained caps │
|
|
416
|
+
├───────────────────────┼──────────────────────┼──────────────────────────┤
|
|
417
|
+
│ Result │ 60% accuracy │ 95%+ accuracy │
|
|
418
|
+
│ │ "I think this might │ "Rule R1 matched facts │
|
|
419
|
+
│ │ be suspicious..." │ F1,F2,F3. Proof: ..." │
|
|
420
|
+
└───────────────────────┴──────────────────────┴──────────────────────────┘
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
### The Key Insight
|
|
424
|
+
|
|
425
|
+
**MCP**: LLM generates query → hope it works
|
|
426
|
+
**HyperMind**: LLM selects tools → type system validates → guaranteed correct
|
|
427
|
+
|
|
428
|
+
```javascript
|
|
429
|
+
// MCP APPROACH (Generic function calling)
|
|
430
|
+
// Tool: search_database(query: string)
|
|
431
|
+
// LLM generates: "SELECT * FROM claims WHERE suspicious = true"
|
|
432
|
+
// Result: ❌ SQL injection risk, "suspicious" column doesn't exist
|
|
433
|
+
|
|
434
|
+
// HYPERMIND APPROACH (Domain-enriched proxy)
|
|
435
|
+
// Tool: kg.datalog.infer with NICB fraud rules
|
|
436
|
+
const proxy = sandbox.createObjectProxy(tools)
|
|
437
|
+
const result = await proxy['kg.datalog.infer']({
|
|
438
|
+
rules: ['potential_collusion', 'staged_accident']
|
|
439
|
+
})
|
|
440
|
+
// Result: ✅ Type-safe, domain-aware, auditable
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
**Why Domain Proxies Win:**
|
|
444
|
+
1. LLM becomes **orchestrator**, not executor
|
|
445
|
+
2. Domain knowledge **reduces hallucination**
|
|
446
|
+
3. Composition **multiplies capability**
|
|
447
|
+
4. Audit trail **enables compliance**
|
|
448
|
+
5. Security **enables enterprise deployment**
|
|
449
|
+
|
|
450
|
+
---
|
|
451
|
+
|
|
256
452
|
## Why Vanilla LLMs Fail
|
|
257
453
|
|
|
258
454
|
When you ask an LLM to query a knowledge graph, it produces **broken SPARQL 85% of the time**:
|