Redis Persist Chat

Comprehensive persistence system with Redis for all aspects of agent-swarm: history, state, memory, embedding cache.

Demonstrates capabilities:

  • Complete Redis integration for persistence
  • Complex storage system with TTL
  • Client-server architecture with Redis backend
  • Advanced features: policies, states, embeddings
  • Complete Redis Integration: All data in Redis
  • Multiple Storage Types: History, State, Memory, Embeddings
  • TTL Support: Automatic data expiration
  • Policy System: Crimea and Putin policies for content
  • Advanced Features: Tic-tac-toe game state, fact storage
  • Embedding Cache: Vector representation caching
  • Runtime: Bun
  • Language: TypeScript
  • AI Framework: agent-swarm-kit
  • Database: Redis (ioredis)
  • ML: TensorFlow.js for embeddings
  • AI Provider: Saiga/Yandex GPT
src/
├── config/
│ ├── logger.ts # Logging
│ ├── persist.ts # Redis persistence
│ └── tf.ts # TensorFlow configuration
├── logic/
│ ├── agent/ # Triage agent
│ ├── completion/ # Saiga Yandex GPT
│ ├── embedding/ # Nomic embeddings
│ ├── policy/ # Content policies
│ ├── state/ # Game states
│ ├── storage/ # Fact storage
│ ├── swarm/ # Root swarm
│ └── tools/ # State and storage tools
├── main/
│ ├── client.ts # WebSocket client
│ └── server.ts # WebSocket server
└── model/ # Data models
# Install Redis
# Ubuntu/Debian: sudo apt install redis-server
# macOS: brew install redis
# Windows: Download from Redis website

# Start Redis
redis-server

# Install dependencies
bun install

# Start server (terminal 1)
bun run src/main/server.ts

# Start client (terminal 2)
bun run src/main/client.ts

Create a .env file:

REDIS_URL=redis://localhost:6379
REDIS_TTL=3600
YANDEX_GPT_API_KEY=your_yandex_api_key
YANDEX_FOLDER_ID=your_folder_id
  • "Hello, how are you?"
  • "Tell me a joke"
  • "Let's start a tic-tac-toe game"
  • "Put X in the center"
  • "Remember: my favorite food is pizza"
  • "What do you know about me?"
  • "Tell me about Crimea" (Crimea policy will trigger)
agent-swarm:history:{clientId}:{messageId}
agent-swarm:state:{clientId}:{stateType}
agent-swarm:memory:{clientId}:{memoryKey}
agent-swarm:embedding:{textHash}
agent-swarm:storage:{storageType}:{key}
  • Crimea Policy: Content filtering about Crimea
  • Putin Policy: Restrictions on political topics
  • Tic-tac-toe состояние в Redis
  • Persistent game sessions
  • State validation и updates
  • Vector caching with TTL
  • Nomic embeddings for semantic search
  • Memory optimization

Ideal for:

  • Production chat systems
  • Gaming applications with persistent state
  • Knowledge management systems
  • Content moderation platforms
  • Multi-session applications
  • Fast Access: Redis in-memory performance
  • Scalability: Redis cluster support
  • Persistence: RDB + AOF durability
  • Memory Efficiency: TTL for automatic cleanup