惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
博客园_首页
宝玉的分享
宝玉的分享
S
SegmentFault 最新的问题
Jina AI
Jina AI
Hugging Face - Blog
Hugging Face - Blog
V
Visual Studio Blog
美团技术团队
IT之家
IT之家
罗磊的独立博客
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
月光博客
月光博客
Microsoft Azure Blog
Microsoft Azure Blog
H
Help Net Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Last Week in AI
Last Week in AI
博客园 - 叶小钗
M
MIT News - Artificial intelligence
B
Blog RSS Feed
有赞技术团队
有赞技术团队
Y
Y Combinator Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Building a Multi-Agent AI Swarm with Valkey as the Nervou...
Harish Kotra · 2026-04-22 · via DEV Community

AI agents need more than model calls. They need memory, coordination, and deterministic state transitions.

In this project, we built NeuroValkey Agents: a 3-agent Node.js swarm where Valkey is not a cache, but the central runtime substrate for orchestration.

  • Agent 1 (Researcher) generates facts and stores vector memory.
  • Agent 2 (Writer) retrieves semantic context with KNN search and drafts summary text.
  • Agent 3 (Editor) grades the draft and writes final output.

Everything is connected through Valkey primitives: Pub/Sub, Search (vector), JSON, Hashes.


Why this architecture works

Most agent prototypes couple control flow tightly to app memory. That makes state invisible and difficult to debug live.

This design externalizes swarm state into Valkey:

  • Pub/Sub channels make orchestration explicit.
  • JSON keys hold durable run snapshots.
  • Hash keys hold vectorized facts.
  • Search index enables semantic retrieval with minimal dependencies.

The result is a fast, event-driven, inspectable system.


System architecture

System architecture


Core implementation walkthrough

1) Valkey Search index creation via raw commands

To keep compatibility with module variants, we use valkey.call() directly:

await this.commandClient.call(
  'FT.CREATE',
  this.indexName,
  'ON', 'HASH',
  'PREFIX', '1', 'fact:',
  'SCHEMA',
  'topic', 'TAG',
  'agent', 'TAG',
  'embedding', 'VECTOR', 'FLAT', '6',
  'TYPE', 'FLOAT32',
  'DIM', String(CONFIG.embeddingDim),
  'DISTANCE_METRIC', 'COSINE'
);

Enter fullscreen mode Exit fullscreen mode

2) Writing vector memory into hash records

Each fact is embedded using OpenAI and written to fact:<uuid>:

await this.commandClient.hset(
  key,
  'text', text,
  'topic', normalizedTopic,
  'agent', 'researcher',
  'embedding', toFloat32Buffer(embedding)
);

Enter fullscreen mode Exit fullscreen mode

3) Writer semantic retrieval with KNN

const response = await this.commandClient.call(
  'FT.SEARCH',
  this.indexName,
  `*=>[KNN ${k} @embedding $vec AS score]`,
  'PARAMS', '2', 'vec', vector,
  'NOCONTENT',
  'DIALECT', '2'
);

Enter fullscreen mode Exit fullscreen mode

Then we hydrate matched keys with HMGET to get text/topic/agent.

4) Global state tracking with JSON

Manifest state changes are persisted as JSON, not process memory:

await this.commandClient.call('JSON.SET', key, '$', JSON.stringify(value));
const raw = await this.commandClient.call('JSON.GET', key, '$');

Enter fullscreen mode Exit fullscreen mode

This enables reproducibility and UI introspection.


The dashboard: making Valkey visible

Terminal output is useful but not audience-friendly for demos. The UI layer solves that by showing:

  • live keyspace map (swarm:*, fact:*) and key types
  • raw JSON for manifest/draft/final
  • vector fact records with embeddingBytes
  • Search index telemetry from FT.INFO
  • event timeline + process feed

Developers can correlate each event with exact state written to Valkey.


Engineering decisions and tradeoffs

  1. Polling over sockets for simplicity
  2. Chosen: periodic /api/state + /api/logs polling
  3. Tradeoff: slightly higher request volume
  4. Benefit: zero extra infra, easy local demo reliability

  5. Hash + JSON hybrid model

  6. Chosen: vectors in Hash, workflow state in JSON

  7. Tradeoff: two key representations

  8. Benefit: better fit for each data access pattern

  9. Raw Search commands vs abstraction library

  10. Chosen: raw FT.CREATE / FT.SEARCH

  11. Tradeoff: lower-level API surface

  12. Benefit: explicit control and compatibility visibility


Running the project

docker compose up -d
npm install
cp .env.example .env
# set OPENAI_API_KEY
npm run ui

Enter fullscreen mode Exit fullscreen mode

Open http://localhost:3055, launch a run, and watch the keyspace evolve.


Where to take this next

  • Convert polling to SSE/WebSockets for lower latency updates
  • Add run history table with previous manifests
  • Add configurable agent graph (DAG) in manifest
  • Add retries, backoff, and dead-letter channels
  • Add benchmark mode for throughput and latency stats
  • Add trace IDs and distributed telemetry

The important lesson is architectural, not cosmetic: LLMs are reasoning engines, but Valkey is the operational substrate that turns them into coordinated systems.

If you can observe your keyspace evolving in real time, you can trust, debug, and scale your swarm.

Screenshot

Screenshot Example

Github: https://github.com/harishkotra/neurovalkey-agents