Skip to content

armaniv/multi-agent-code-assistant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Multi-Agent Code Assistant

A Next.js application that leverages multiple AI agents to develop, review, and improve code through a coordinated workflow. The system uses LangChain for orchestration and integrates with external MCP (Model Context Protocol) servers for database operations.

🌟 Features

  • Multi-Agent System: Coordinator, Developer, and Checker agents working together
  • Code Development: Automated code generation using Codestral
  • Code Review: Intelligent code analysis and feedback using Gemini 2.5 Flash
  • Iterative Improvement: Automatic code refinement based on review feedback
  • Persistent Storage: Code reviews stored in PostgreSQL via MCP Toolbox server
  • Modern UI: Clean, responsive chat interface built with React and Next.js

πŸ—οΈ Architecture

System Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      
β”‚                          CLIENT TIER                               β”‚          
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚  Browser (Next.js Frontend)                                β”‚    β”‚
β”‚  β”‚  - React Component: chat.tsx                               β”‚    β”‚
β”‚  β”‚  - User Interface for code requests                        β”‚    β”‚
β”‚  β”‚  - Message display and interaction                         β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    β”‚ HTTP/JSON
                    β”‚ POST /api/chat
                    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                       APPLICATION TIER                             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚  Next.js API Routes (route.ts)                             β”‚    β”‚      
β”‚  β”‚  - Handles HTTP requests                                   β”‚    β”‚      
β”‚  β”‚  - Validates API keys                                      β”‚    β”‚      
β”‚  β”‚  - Orchestrates multi-agent workflow                       β”‚    β”‚      
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚      
β”‚                   β”‚                                                β”‚      
β”‚                   β–Ό                                                β”‚      
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚      
β”‚  β”‚  Multi-Agent System (multi-agent-system.ts)                β”‚    β”‚      
β”‚  β”‚                                                            β”‚    β”‚      
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚    β”‚      
β”‚  β”‚  β”‚ Coordinator Agentβ”‚β—€ ───────── β–Ά β”‚ Developer Agent  β”‚    β”‚    β”‚      
β”‚  β”‚  β”‚ (Gemini 2.5)     β”‚              β”‚ (Codestral)      β”‚    β”‚    β”‚      
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚    β”‚
β”‚  β”‚           β–²                                                β”‚    β”‚
β”‚  β”‚           β”‚                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚    β”‚
β”‚  β”‚           └────────────────────── β–Άβ”‚ Checker Agent    β”‚    β”‚    β”‚
β”‚  β”‚                                    β”‚ (Gemini 2.5)     β”‚    β”‚    β”‚
β”‚  β”‚                                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    β”‚ MCP Protocol
                    β”‚ HTTP (http://127.0.0.1:5000/mcp)
                    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    INTEGRATION TIER                                β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚  MCP Toolbox Server (Docker: port 5000)                    β”‚    β”‚
β”‚  β”‚  - Provides database tools via MCP protocol                β”‚    β”‚
β”‚  β”‚  - Tools: store-code-review, get-code-review, etc.         β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    β”‚ PostgreSQL Protocol
                    β”‚ (port 5432)
                    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                       DATA TIER                                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚  PostgreSQL Database (Docker: port 5432)                   β”‚    β”‚
β”‚  β”‚  - Table: code_reviews                                     β”‚    β”‚
β”‚  β”‚  - Stores: user_request, reviewed_code, timestamps         β”‚    β”‚
β”‚  β”‚  - Credentials: toolbox_user / my-password                 β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Workflow Sequence

  1. User Input: User enters a code request in the chat interface (chat.tsx)
  2. API Request: Frontend sends POST request to /api/chat (route.ts)
  3. Agent Creation: API creates coordinator agent (multi-agent-system.ts)
  4. Tool Invocation: Coordinator orchestrates the following sequence:
    • ask_developer: Developer agent creates initial code
    • ask_checker: Checker agent reviews the code
    • ask_developer_to_improve: Developer improves code based on feedback
    • store_reviewed_code: Stores final code in database via MCP
  5. MCP Integration: Toolbox MCP client connects to MCP server (toolbox-mcp-client.ts)
  6. Database Storage: MCP Toolbox executes SQL operations on PostgreSQL
  7. Response Flow: Result flows back through all layers
  8. UI Display: Frontend displays the final code to the user

🧠 LangChain

This project is built on LangChain.js, a powerful framework for developing applications powered by large language models (LLMs).

LangChain Overview

LangChain is a framework designed to simplify the creation of applications using LLMs. It provides:

  • Modular Components: Pre-built abstractions for working with language models
  • Chains: Sequences of calls to components, LLMs, or other chains
  • Agents: Systems that use LLMs to determine which actions to take
  • Memory: Mechanisms to persist state between chain or agent calls
  • Tool Integration: Easy connection to external data sources and APIs

Why We Chose LangChain

LangChain was selected as the foundation of this project because it addresses our core architectural requirements:

1. Composability

LangChain allows us to build complex multi-agent systems by composing simple, reusable components. Our coordinator, developer, and checker agents are independently defined but work together seamlessly.

2. Flexibility

We can easily swap between different LLM providers (Gemini, Codestral) without changing our application logic. LangChain's unified interface makes multi-model architectures straightforward.

3. Tool Integration

LangChain's tool abstraction made it possible to integrate external systems like our MCP servers for database operations and static analysis.

4. Flow Management

LangChain provides powerful primitives for orchestrating complex workflows. The framework's agent execution model enables our coordinator to manage the sequential flow of development β†’ review β†’ improvement β†’ storage, with conditional logic.

πŸš€ Getting Started

Prerequisites

  • Node.js 18+ and npm
  • Docker and Docker Compose
  • API Keys:
    • Google Gemini API key
    • Mistral API key

Installation

  1. Clone the repository:

    git clone <repository-url>
    cd multi-agent-code-assistant
  2. Install dependencies:

    npm install
  3. Set up environment variables: Create a .env.local file in the root directory:

    GEMINI_API_KEY=your_gemini_api_key_here
    MISTRAL_API_KEY=your_mistral_api_key_here
  4. Start the MCP Toolbox and Database:

    docker compose -f toolbox_postgresql/docker-compose.yml up -d

    This starts:

    • PostgreSQL database on port 5432
    • MCP Toolbox server on port 5000
  5. Run the development server:

    npm run dev
  6. Open your browser: Navigate to http://localhost:3000

πŸ€– Agent Architecture

1. Coordinator Agent (Gemini 2.5 Flash)

  • Role: Orchestrates the entire workflow
  • Responsibilities:
    • Receives user requests
    • Delegates tasks to specialist agents
    • Manages the development β†’ review β†’ improvement β†’ storage cycle
    • Presents final results to users

2. Developer Agent (Codestral)

  • Role: Code implementation specialist
  • Responsibilities:
    • Generates initial code implementations
    • Improves code based on review feedback
    • Follows best practices and clean code principles
    • Outputs only code without explanations

3. Checker Agent (Gemini 2.5 Flash)

  • Role: Code quality and security reviewer
  • Responsibilities:
    • Reviews code for bugs and errors
    • Identifies security vulnerabilities
    • Suggests improvements
    • Provides structured feedback

πŸ› οΈ Development

Project Structure

testmcp/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”‚   └── chat/
β”‚   β”‚   β”‚       └── route.ts          # API endpoint
β”‚   β”‚   β”œβ”€β”€ globals.css
β”‚   β”‚   β”œβ”€β”€ layout.tsx
β”‚   β”‚   └── page.tsx                  # Main page
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   └── chat.tsx                  # Chat UI component
β”‚   └── lib/
β”‚       β”œβ”€β”€ multi-agent-system.ts     # Agent definitions
β”‚       └── toolbox-mcp-client.ts     # MCP client
β”œβ”€β”€ toolbox_postgresql/
β”‚   β”œβ”€β”€ docker-compose.yml            # Docker services
β”‚   └── config/
β”‚       β”œβ”€β”€ init.sql                  # Database schema
β”‚       └── tools.yaml                # MCP tools config
β”œβ”€β”€ next.config.ts
β”œβ”€β”€ package.json
└── tsconfig.json

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors