Files
proffesor-for-testing__agen…/v2/docs/AgentDB-Integration-Guide.md
Profa fd2f37eaa0 fix(v3): update README claims and init hooks to use correct package name
Changes:
- Fix README.md agent counts (48 QE agents = 41 main + 7 subagents)
- Fix README.md skill counts (15 QE-specific skills)
- Fix v3/README.md agent counts (47 → 48)
- Fix init-wizard.ts hooks from 'npx @agentic-qe/v3' to 'npx agentic-qe'
- Complete v2 → v2/ folder reorganization (54 items moved)
- Update root package.json to point to v3 as main version

Verified claims:
- 48 QE agents (41 main + 7 TDD subagents)
- 15 QE-specific skills
- 12 DDD bounded contexts
- ~5,600+ tests
- HNSW, ReasoningBank, Queen Coordinator features exist

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-17 18:03:40 +00:00

12 KiB

AgentDB Integration Guide

Overview

The AgentDBManager provides production-ready memory management for distributed agent coordination using the agentic-flow/reasoningbank package. This replaces 2,290 lines of custom QUIC and Neural code with a battle-tested implementation.

Features

Core Capabilities

  1. QUIC Synchronization (<1ms latency)

    • Sub-millisecond cross-agent memory synchronization
    • Automatic peer discovery and connection
    • Compressed data transfer with configurable batching
    • Retry logic with exponential backoff
  2. Neural Training (9 RL Algorithms)

    • Q-Learning
    • SARSA
    • Actor-Critic
    • Deep Q-Network (DQN)
    • Policy Gradient
    • Proximal Policy Optimization (PPO)
    • Advantage Actor-Critic (A2C)
    • Trust Region Policy Optimization (TRPO)
    • Soft Actor-Critic (SAC)
  3. Vector Search (150x faster)

    • HNSW indexing for nearest neighbor search
    • Semantic similarity with cosine/euclidean/dot metrics
    • Maximal Marginal Relevance (MMR) for diversity
    • Hybrid search with metadata filters
  4. Memory Optimization

    • Quantization (4-32x memory reduction)
    • Scalar, binary, product quantization modes
    • In-memory caching (configurable size)
    • Pattern consolidation

Installation

The agentic-flow package is already included in package.json:

{
  "dependencies": {
    "agentic-flow": "^1.7.3"
  }
}

Architecture

┌─────────────────────────────────────────────────────────────┐
│                    AgentDBManager                           │
│  (Wrapper around agentic-flow/reasoningbank)                │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  ┌─────────────┐  ┌──────────────┐  ┌─────────────────┐   │
│  │   Storage   │  │  Retrieval   │  │    Training     │   │
│  │  - insert   │  │  - semantic  │  │  - 9 RL algos   │   │
│  │  - batch    │  │  - hybrid    │  │  - validation   │   │
│  └─────────────┘  └──────────────┘  └─────────────────┘   │
│                                                             │
│  ┌─────────────┐  ┌──────────────┐  ┌─────────────────┐   │
│  │  QUIC Sync  │  │ Quantization │  │  HNSW Index     │   │
│  │  - <1ms     │  │  - 4-32x     │  │  - 150x faster  │   │
│  │  - peers    │  │  - modes     │  │  - semantic     │   │
│  └─────────────┘  └──────────────┘  └─────────────────┘   │
│                                                             │
└─────────────────────────────────────────────────────────────┘
                              │
                              ▼
                ┌─────────────────────────────┐
                │  agentic-flow/reasoningbank │
                │     (Production Package)     │
                └─────────────────────────────┘

Usage

1. Basic Memory Operations

import { createAgentDBManager, MemoryPattern } from '../src/core/memory/AgentDBManager';

// Create manager with default configuration
const manager = createAgentDBManager();
await manager.initialize();

// Store a pattern
const pattern: MemoryPattern = {
  id: '',
  type: 'conversation',
  domain: 'user-interactions',
  pattern_data: JSON.stringify({
    embedding: Array(768).fill(0).map(() => Math.random()),
    pattern: {
      user: 'What is the capital of France?',
      assistant: 'The capital of France is Paris.'
    }
  }),
  confidence: 0.95,
  usage_count: 1,
  success_count: 1,
  created_at: Date.now(),
  last_used: Date.now()
};

const patternId = await manager.store(pattern);

// Retrieve similar patterns
const queryEmbedding = Array(768).fill(0).map(() => Math.random());
const result = await manager.search(queryEmbedding, 'user-interactions', 5);

console.log('Found memories:', result.memories.length);
console.log('Query time:', result.metadata.queryTime, 'ms');

await manager.close();

2. QUIC Synchronization

import { createAgentDBManager, AgentDBConfig } from '../src/core/memory/AgentDBManager';

const config: Partial<AgentDBConfig> = {
  dbPath: '.agentdb/node1.db',
  enableQUICSync: true,
  syncPort: 4433,
  syncPeers: [
    'localhost:4434', // Node 2
    'localhost:4435'  // Node 3
  ],
  syncInterval: 1000,    // Sync every second
  syncBatchSize: 100,
  compression: true
};

const manager = createAgentDBManager(config);
await manager.initialize();

// Patterns will automatically sync to peers
await manager.store(pattern);
// Synchronized across all nodes in <1ms

3. Neural Training

const manager = createAgentDBManager({
  enableLearning: true,
  enableReasoning: true,
  quantizationType: 'scalar' // 4x memory reduction
});

await manager.initialize();

// Store training experiences
for (let i = 0; i < 100; i++) {
  const experience: MemoryPattern = {
    id: '',
    type: 'experience',
    domain: 'game-playing',
    pattern_data: JSON.stringify({
      embedding: Array(768).fill(0).map(() => Math.random()),
      pattern: {
        state: Array(10).fill(0).map(() => Math.random()),
        action: Math.floor(Math.random() * 4),
        reward: Math.random(),
        next_state: Array(10).fill(0).map(() => Math.random()),
        done: Math.random() > 0.9
      }
    }),
    confidence: Math.random(),
    usage_count: 1,
    success_count: Math.random() > 0.5 ? 1 : 0,
    created_at: Date.now(),
    last_used: Date.now()
  };

  await manager.store(experience);
}

// Train learning model
const metrics = await manager.train({
  epochs: 50,
  batchSize: 32,
  learningRate: 0.001,
  validationSplit: 0.2
});

console.log('Training complete:');
console.log('  Loss:', metrics.loss);
console.log('  Val Loss:', metrics.valLoss);
console.log('  Duration:', metrics.duration, 'ms');

4. Integration with BaseAgent

import { BaseAgent, BaseAgentConfig } from './agents/BaseAgent';

const agentConfig: BaseAgentConfig = {
  type: 'test-generator',
  capabilities: [...],
  context: {...},
  memoryStore: swarmMemoryManager,
  eventBus: eventBus,
  enableLearning: true,

  // AgentDB configuration (optional)
  agentDBConfig: {
    dbPath: `.agentdb/${agentId}.db`,
    enableQUICSync: true,
    syncPort: 4433,
    syncPeers: ['peer1:4433', 'peer2:4433'],
    enableLearning: true,
    enableReasoning: true,
    quantizationType: 'scalar'
  }
};

const agent = new TestGeneratorAgent(agentConfig);
await agent.initialize();

// AgentDB is now available
const status = await agent.getAgentDBStatus();
console.log('AgentDB enabled:', status.enabled);

5. Hybrid Search with Filters

const result = await manager.retrieve(queryEmbedding, {
  domain: 'research-papers',
  k: 10,
  filters: {
    year: { $gte: 2024 },      // Published 2024 or later
    category: 'ai',             // AI papers only
    citations: { $gte: 100 }    // Highly cited
  },
  metric: 'cosine',
  useMMR: true,                 // Diverse results
  synthesizeContext: true        // Generate context
});

console.log('Results:', result.memories.length);
console.log('Context:', result.context);

Configuration Options

AgentDBConfig Interface

interface AgentDBConfig {
  // Database
  dbPath: string;                  // Path to SQLite database

  // QUIC Synchronization
  enableQUICSync: boolean;         // Enable QUIC sync
  syncPort: number;                // QUIC server port (default: 4433)
  syncPeers: string[];             // Peer addresses
  syncInterval?: number;           // Sync interval in ms (default: 1000)
  syncBatchSize?: number;          // Batch size (default: 100)
  maxRetries?: number;             // Max retry attempts (default: 3)
  compression?: boolean;           // Enable compression (default: true)

  // Learning & Reasoning
  enableLearning: boolean;         // Enable 9 RL algorithms
  enableReasoning: boolean;        // Enable reasoning agents

  // Performance
  cacheSize: number;               // Cache size (default: 1000)
  quantizationType: 'scalar' | 'binary' | 'product' | 'none';
}

Default Configuration

const defaultConfig: AgentDBConfig = {
  dbPath: '.agentdb/reasoningbank.db',
  enableQUICSync: false,
  syncPort: 4433,
  syncPeers: [],
  enableLearning: true,
  enableReasoning: true,
  cacheSize: 1000,
  quantizationType: 'scalar',
  syncInterval: 1000,
  syncBatchSize: 100,
  maxRetries: 3,
  compression: true
};

Performance Characteristics

Operation Latency Throughput
Vector Search (HNSW) <100µs N/A
Pattern Retrieval (cached) <1ms N/A
Batch Insert (100 patterns) 2ms 50,000/s
QUIC Sync <1ms N/A
Neural Training (50 epochs) ~500ms N/A

Memory Usage

Quantization Mode Memory Reduction Accuracy Loss
None 1x (baseline) 0%
Scalar 4x <1%
Binary 32x <5%
Product 8-16x <2%

Graceful Degradation

If the agentic-flow/reasoningbank package is not available:

try {
  const manager = createAgentDBManager(config);
  await manager.initialize();
} catch (error) {
  console.warn('AgentDB not available, using fallback:', error.message);
  // System continues with SwarmMemoryManager only
}

Integration Points

  1. BaseAgent: Uses agentDBConfig parameter
  2. SwarmMemoryManager: Provides enableAgentDB() method
  3. Type Definitions: src/types/agentic-flow-reasoningbank.d.ts

Examples

See comprehensive examples in:

  • /workspaces/agentic-qe-cf/examples/agentdb-manager-example.ts
  • /workspaces/agentic-qe-cf/tests/integration/agentdb-neural-training.test.ts
  • /workspaces/agentic-qe-cf/tests/integration/agentdb-quic-sync.test.ts

Benefits

  1. Replaces Custom Code: Eliminates 2,290 lines of custom QUIC and Neural implementation
  2. Production-Tested: Uses battle-tested agentic-flow package
  3. Performance: 150x faster vector search, 4-32x memory reduction
  4. Backward Compatible: Optional opt-in feature
  5. Comprehensive: 9 RL algorithms, QUIC sync, hybrid search, context synthesis

Troubleshooting

Package Not Found

npm install agentic-flow@latest

QUIC Port Conflicts

const config = {
  syncPort: 4434,  // Use different port
  // ...
};

Memory Issues

const config = {
  quantizationType: 'binary',  // Maximum memory reduction
  cacheSize: 500,              // Reduce cache size
  // ...
};

API Reference

See TypeScript definitions in:

  • /workspaces/agentic-qe-cf/src/core/memory/AgentDBManager.ts
  • /workspaces/agentic-qe-cf/src/types/agentic-flow-reasoningbank.d.ts