rust-kgdb 0.5.12 → 0.6.0
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 +253 -0
- package/README.md +170 -0
- package/examples/fraud-detection-agent.js +157 -1
- package/examples/fraud-memory-hypergraph.js +658 -0
- package/examples/underwriting-agent.js +142 -2
- package/hypermind-agent.js +1199 -1
- package/index.d.ts +735 -0
- package/index.js +24 -0
- package/package.json +8 -3
|
@@ -35,7 +35,19 @@ const {
|
|
|
35
35
|
DatalogProgram,
|
|
36
36
|
evaluateDatalog,
|
|
37
37
|
GraphFrame,
|
|
38
|
-
getVersion
|
|
38
|
+
getVersion,
|
|
39
|
+
// Memory Layer (v0.5.13+) - GraphDB-Powered Agent Memory
|
|
40
|
+
AgentState,
|
|
41
|
+
AgentRuntime,
|
|
42
|
+
WorkingMemory,
|
|
43
|
+
EpisodicMemory,
|
|
44
|
+
LongTermMemory,
|
|
45
|
+
MemoryManager,
|
|
46
|
+
// Governance Layer
|
|
47
|
+
GovernancePolicy,
|
|
48
|
+
GovernanceEngine,
|
|
49
|
+
// Scope Layer
|
|
50
|
+
AgentScope
|
|
39
51
|
} = require('../index.js')
|
|
40
52
|
|
|
41
53
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
@@ -283,6 +295,67 @@ async function main() {
|
|
|
283
295
|
console.log(` Agent "${agent.getName()}" spawned with model: ${agent.getModel()}`)
|
|
284
296
|
console.log()
|
|
285
297
|
|
|
298
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
299
|
+
// PHASE 2.5: Memory Layer Initialization (NEW in v0.5.13)
|
|
300
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
301
|
+
|
|
302
|
+
console.log('┌─ MEMORY: AgentRuntime + MemoryManager + Governance ────────────────────┐')
|
|
303
|
+
console.log('│ Memory Layer: Working + Episodic + LongTerm (GraphDB-backed) │')
|
|
304
|
+
console.log('└─────────────────────────────────────────────────────────────────────────┘')
|
|
305
|
+
|
|
306
|
+
// Create agent runtime with identity
|
|
307
|
+
const runtime = new AgentRuntime({
|
|
308
|
+
name: 'underwriter',
|
|
309
|
+
model: MODEL,
|
|
310
|
+
tools: ['kg.sparql.query', 'kg.datalog.apply', 'kg.embeddings.search'],
|
|
311
|
+
memoryCapacity: 100,
|
|
312
|
+
episodeLimit: 1000
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
// Initialize memory manager with GraphDB
|
|
316
|
+
const memoryManager = new MemoryManager(runtime, db, {
|
|
317
|
+
recencyWeight: 0.3,
|
|
318
|
+
relevanceWeight: 0.5,
|
|
319
|
+
importanceWeight: 0.2
|
|
320
|
+
})
|
|
321
|
+
|
|
322
|
+
// Create governance policy for underwriting
|
|
323
|
+
const policy = new GovernancePolicy({
|
|
324
|
+
capabilities: ['ReadKG', 'ExecuteTool', 'UseEmbeddings', 'AccessMemory'],
|
|
325
|
+
maxMemoryMB: 256,
|
|
326
|
+
maxExecutionTimeMs: 60000,
|
|
327
|
+
maxToolCalls: 100
|
|
328
|
+
})
|
|
329
|
+
|
|
330
|
+
// Initialize governance engine
|
|
331
|
+
const governance = new GovernanceEngine(policy)
|
|
332
|
+
|
|
333
|
+
// Create agent scope with namespace isolation
|
|
334
|
+
const scope = new AgentScope({
|
|
335
|
+
name: 'underwriting-scope',
|
|
336
|
+
graphUri: 'http://underwriting.org/data',
|
|
337
|
+
allowedGraphs: ['http://underwriting.org/data', 'http://underwriting.org/memory'],
|
|
338
|
+
maxToolCalls: 50
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
console.log(` Runtime ID: ${runtime.id}`)
|
|
342
|
+
console.log(` Memory: recency=${memoryManager.weights.recency}, relevance=${memoryManager.weights.relevance}, importance=${memoryManager.weights.importance}`)
|
|
343
|
+
console.log(` Governance: ${policy.capabilities.size} capabilities, ${policy.limits.maxToolCalls} max tool calls`)
|
|
344
|
+
console.log()
|
|
345
|
+
|
|
346
|
+
// Store initial context in working memory
|
|
347
|
+
memoryManager.addToWorking({
|
|
348
|
+
type: 'session_start',
|
|
349
|
+
task: 'underwriting_analysis',
|
|
350
|
+
triple_count: tripleCount
|
|
351
|
+
})
|
|
352
|
+
|
|
353
|
+
// Transition to READY state first
|
|
354
|
+
runtime.transitionTo(AgentState.READY)
|
|
355
|
+
|
|
356
|
+
// Start execution for episodic tracking
|
|
357
|
+
const executionId = runtime.startExecution('Commercial underwriting risk analysis')
|
|
358
|
+
|
|
286
359
|
// ─────────────────────────────────────────────────────────────────────────
|
|
287
360
|
// PHASE 3: Execute Underwriting Tools
|
|
288
361
|
// ─────────────────────────────────────────────────────────────────────────
|
|
@@ -475,6 +548,54 @@ async function main() {
|
|
|
475
548
|
console.log()
|
|
476
549
|
}
|
|
477
550
|
|
|
551
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
552
|
+
// Memory Layer: Store Tool Executions as Episodes (NEW in v0.5.13)
|
|
553
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
554
|
+
|
|
555
|
+
await memoryManager.storeExecution({
|
|
556
|
+
id: `${executionId}-sparql`,
|
|
557
|
+
prompt: 'Query all business accounts',
|
|
558
|
+
tool: 'kg.sparql.query',
|
|
559
|
+
output: { accountCount: accounts.length },
|
|
560
|
+
success: true,
|
|
561
|
+
durationMs: 50
|
|
562
|
+
})
|
|
563
|
+
|
|
564
|
+
await memoryManager.storeExecution({
|
|
565
|
+
id: `${executionId}-graphframe`,
|
|
566
|
+
prompt: 'Risk network analysis',
|
|
567
|
+
tool: 'kg.graphframe.analyze',
|
|
568
|
+
output: { vertices: riskVertices.length, pageRank: 'complete' },
|
|
569
|
+
success: true,
|
|
570
|
+
durationMs: 30
|
|
571
|
+
})
|
|
572
|
+
|
|
573
|
+
await memoryManager.storeExecution({
|
|
574
|
+
id: `${executionId}-datalog`,
|
|
575
|
+
prompt: 'Apply underwriting rules',
|
|
576
|
+
tool: 'kg.datalog.infer',
|
|
577
|
+
output: { decisions: decisions.length, autoApprove: autoApprove.length, referToUW: referToUW.length },
|
|
578
|
+
success: true,
|
|
579
|
+
durationMs: 20
|
|
580
|
+
})
|
|
581
|
+
|
|
582
|
+
// Track resource usage in scope
|
|
583
|
+
scope.trackUsage('toolCalls', 4)
|
|
584
|
+
scope.trackUsage('graphQueries', 2)
|
|
585
|
+
|
|
586
|
+
// Add findings to working memory
|
|
587
|
+
memoryManager.addToWorking({
|
|
588
|
+
type: 'findings',
|
|
589
|
+
accountsProcessed: accounts.length,
|
|
590
|
+
autoApproveCount: autoApprove.length,
|
|
591
|
+
referToUWCount: referToUW.length
|
|
592
|
+
})
|
|
593
|
+
|
|
594
|
+
// Complete execution
|
|
595
|
+
runtime.completeExecution({ accounts: accounts.length, decisions: decisions.length }, true)
|
|
596
|
+
const memStats = memoryManager.getStats()
|
|
597
|
+
const remaining = scope.getRemainingResources()
|
|
598
|
+
|
|
478
599
|
// ─────────────────────────────────────────────────────────────────────────
|
|
479
600
|
// PHASE 5: Generate Execution Witness (Proof Theory)
|
|
480
601
|
// ─────────────────────────────────────────────────────────────────────────
|
|
@@ -498,6 +619,16 @@ async function main() {
|
|
|
498
619
|
console.log(' - BUS004 (Downtown): MODERATE - flood exposure, established')
|
|
499
620
|
console.log()
|
|
500
621
|
|
|
622
|
+
// Memory Layer Statistics (NEW in v0.5.13)
|
|
623
|
+
console.log(' MEMORY LAYER STATISTICS (v0.5.13+):')
|
|
624
|
+
console.log(` Runtime ID: ${(runtime.id || 'unknown').substring(0, 36)}`)
|
|
625
|
+
console.log(` Final State: ${runtime.state}`)
|
|
626
|
+
console.log(` Working Memory Items: ${memStats.working.contextSize}`)
|
|
627
|
+
console.log(` Episodic Episodes: ${memStats.episodic.episodeCount}`)
|
|
628
|
+
console.log(` Tool Calls Remaining: ${remaining.toolCalls}`)
|
|
629
|
+
console.log(` Graph Queries Used: ${scope.usage.graphQueries}`)
|
|
630
|
+
console.log()
|
|
631
|
+
|
|
501
632
|
// Execution Witness
|
|
502
633
|
const witness = {
|
|
503
634
|
agent: agent.getName(),
|
|
@@ -515,7 +646,16 @@ async function main() {
|
|
|
515
646
|
referToUW: referToUW.map(d => d.args[0])
|
|
516
647
|
},
|
|
517
648
|
premiums: premiums.map(p => ({ id: p.id, premium: p.premium, decision: p.decision })),
|
|
518
|
-
trace: agent.getTrace()
|
|
649
|
+
trace: agent.getTrace(),
|
|
650
|
+
// Memory Layer (v0.5.13+)
|
|
651
|
+
memory: {
|
|
652
|
+
runtimeId: runtime.id,
|
|
653
|
+
finalState: runtime.state,
|
|
654
|
+
workingMemoryItems: memStats.working.contextSize,
|
|
655
|
+
episodicMemoryEpisodes: memStats.episodic.episodeCount,
|
|
656
|
+
toolCallsUsed: scope.usage.toolCalls,
|
|
657
|
+
governanceAuditEntries: governance.auditLog.length
|
|
658
|
+
}
|
|
519
659
|
}
|
|
520
660
|
|
|
521
661
|
// Generate deterministic hash
|