DEV Community

Masih Maafi
Masih Maafi

Posted on

A-Modular-Kingdom

🏰 A-Modular-Kingdom

The Foundation for AI-Powered Multi-Agent Systems

A comprehensive AI infrastructure providing building blocks for sophisticated multi-agent workflows. Built with modularity and standardization at its core, seamlessly connecting different multi-agent architectures through a unified foundation.

πŸ“‘ Table of Contents

✨ Features

  • πŸ”— Seamless Integration - Multi-agent systems connect to host.py for instant access to long-term memory, RAG, and powerful tools
  • πŸ—οΈ Modular Architecture - Build hierarchical or sequential workflows on the same foundation
  • πŸ› οΈ Rich Toolset - Vision, code execution, browser automation, web search, and more
  • πŸ“š Smart Memory - Persistent memory and RAG systems working across all agents
  • 🌐 MCP Protocol - Model Context Protocol for reliable, structured interactions
  • 🎀 Voice Control - Speech-to-text and text-to-speech capabilities
  • πŸ“‚ Transferable RAG - Work with any document directory seamlessly

πŸ—οΈ Architecture

architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚       Multi-Agent Layer             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚   Council   β”‚  β”‚     Gym     β”‚   β”‚
β”‚  β”‚   Chamber   β”‚  β”‚             β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚                β”‚
           β–Ό                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚        Foundation Layer             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚   RAG   β”‚ β”‚ Memory  β”‚ β”‚ Tools  β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚              host.py                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Enter fullscreen mode Exit fullscreen mode

πŸš€ Quick Start

Prerequisites

  • Python 3.8+
  • Ollama (for local LLM)
  • UV package manager (recommended)

Installation

# Clone the repository
git clone https://github.com/yourusername/A-Modular-Kingdom.git
cd A-Modular-Kingdom

# Install dependencies with UV
uv sync

# Or with pip
pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

Basic Usage

# Start the MCP server
python agent/host.py

# In another terminal, start the interactive client
python agent/main.py

# Or use UV
uv run agent/main.py
Enter fullscreen mode Exit fullscreen mode

πŸ› οΈ Core Components

πŸ“‘ Host.py - MCP Server

The central hub providing MCP (Model Context Protocol) access to all capabilities:

Available Tools:

  • save_memory - Direct memory storage
  • search_memories - Semantic memory search
  • query_knowledge_base - RAG document search
  • web_search - Current information retrieval
  • browser_automation - Web interaction
  • code_execute - Safe Python execution
  • analyze_media - Image/video analysis
  • text_to_speech - TTS with multiple engines
  • speech_to_text - STT with Whisper

πŸ’¬ Main.py - Interactive Client

Feature-rich chat interface with intelligent tool selection:

Key Features:

  • Auto-completion for @ mentions and / commands
  • Direct memory saving with # prefix
  • Automatic tool selection (memory vs RAG vs web)
  • Document integration via @ mentions
  • Interactive command interface

πŸ“š RAG System

Three versions of RAG implementation with different strategies:

  • V1 - Basic Chroma + BM25 ensemble
  • V2 - FAISS + CrossEncoder reranking
  • V3 - Custom indexes + RRF fusion + LLM reranking

🧠 Memory System

Mem0-based persistent memory with ChromaDB:

  • Automatic fact extraction
  • Semantic search capabilities
  • BM25 fallback for robustness
  • Memory management commands

πŸ€– Multi-Agent Systems

πŸ‘‘ Council Chamber

architecture

image

Hierarchical multi-agent system with defined roles:

πŸ‘‘ King (User) β†’ πŸ‘Έ Queen Juliette β†’ πŸ”₯ Sexy Teacher β†’ πŸ€– Code Agent
Enter fullscreen mode Exit fullscreen mode

Features:

  • Hierarchical validation
  • Smart task delegation
  • MCP tool integration
  • Code-first solutions with smolagents

πŸ’ͺ Gym

Screenshot from 2025-07-14 17-57-24

Sequential fitness-focused multi-agent system:

Interviewer β†’ Plan Generator β†’ Nutrition Agent
Enter fullscreen mode Exit fullscreen mode

Features:

  • CrewAI powered workflows
  • Specialized fitness agents
  • Web interface
  • Flexible LLM support

πŸ”§ Tools & Extensions

Tool Description Note
RAG Document retrieval βœ… 3 versions
Memory Long-term storage βœ… Integrated
Vision Image analysis βœ… Ready
Code Exec Python sandbox βœ… Secure
Browser Web automation βœ… Playwright
Web Search Info retrieval βœ… Duckduckgo
TTS Text-to-speech βœ… Kokoro
STT Speech-to-text βœ… Whisper

πŸ“ Commands Reference

Interactive Commands

# Memory Management
#message          - Save directly to memory
/memory           - List and manage memories

# Document Access  
@filename         - Reference documents
/files            - Show available documents

# RAG Search
/rag <query> [version] [path]  - Search documents
  Examples:
    /rag "machine learning"           # Search current dir with v2
    /rag "AI research" v3            # Use v3 in current dir
    /rag "python" v1 /docs           # Use v1 in /docs

# Tools & Help
/tools            - List available tools
/browser_automation - Run browser tasks
/help             - Show help information
Enter fullscreen mode Exit fullscreen mode

Keyboard Shortcuts

  • @ - Trigger document completion dropdown
  • / - Trigger command completion dropdown
  • \ at line end - Continue to next line

🎯 CLI Integration

**Claude code and Gemini-cli both connect to host.py as clients.

Gemini CLI Extension

Screenshot from 2025-08-16 01-10-56

Create gemini-extension.json:

{
  "name": "a-modular-kingdom",
  "version": "1.0.0",
  "description": "AI Multi-Agent System with transferable RAG",
  "mcpServers": {
    "unified_knowledge_agent": {
      "command": "python",
      "args": ["path/to/agent/host.py"]
    }
  },
  "contextFileName": "KINGDOM.md"
}
Enter fullscreen mode Exit fullscreen mode

RAG CLI Command

Use the /rag command for document search:

/rag <query> [version] [path]

# Default: current working directory, version 2
/rag "search term"

# Specify version
/rag "search term" v3

# Custom path
/rag "search term" v2 /path/to/docs
Enter fullscreen mode Exit fullscreen mode

🀝 Contributing

We welcome contributions! Areas of interest:

  1. New Multi-Agent Architectures - Implement novel agent coordination patterns
  2. Tool Development - Add new MCP tools
  3. RAG Improvements - Enhance retrieval strategies
  4. Memory Optimizations - Better fact extraction and storage

Development Setup

# Fork and clone
git clone https://github.com/yourusername/A-Modular-Kingdom.git

# Create branch
git checkout -b feature/your-feature

# Make changes and test
python -m pytest tests/

# Commit with descriptive message
git commit -m "feat: add new capability"

# Push and create PR
git push origin feature/your-feature
Enter fullscreen mode Exit fullscreen mode

Links

https://www.youtube.com/watch?v=hWoQnAr6R_E
https://medium.com/@masihmoafi12/a-modular-kingdom-fcaa69a6c1f0

πŸ“œ License

MIT License - See LICENSE for details


A-Modular-Kingdom: Where AI agents come together in harmony 🏰✨

Top comments (0)