CodeMentor-AI

CodeMentor-AI

Enables IDE integration with a multi-agent AI pipeline for solving, reviewing, and optimizing code through adversarial peer review and security filtering.

Category
访问服务器

README

<div align="center">

👨‍💻 CodeMentor AI

An Autonomous Multi-Agent Pipeline That Solves, Critiques, Verifies, and Polishes Programming Code

Python 3.11+ Streamlit App Google Gemini MCP Docker Enabled License: MIT

CodeMentor AI is a state-of-the-art Model Context Protocol (MCP) server and Streamlit dashboard built to eradicate LLM hallucinations in competitive coding. By utilizing a linear state-machine verification pipeline, it moves beyond "single prompt solving" into rigorous adversarial peer-review.

Read the Kaggle WriteupView Evaluation MetricsSecurity Architecture

</div>


🎥 Demo

Note to Judges: The live video pitch and deployed application links will be placed here.

CodeMentor AI Pipeline Demo


🛑 The Problem Statement

Why do modern coding assistants hallucinate? Standard generic LLMs are autoregressive predictors, not engineers. When tasked with a dense LeetCode Hard problem, they frequently default to surface-level logic.

  • Hidden Edge Cases: Single-shot prompts regularly fail to calculate bounds like integer overflows or $O(N^2)$ bottlenecks.
  • Debugging Blindness: When AI-generated code fails, feeding the error back to the same monolithic agent often causes cyclic, oscillating hallucinations.
  • Why Multi-Agent? We must segment the cognitive load. You would not deploy code without a peer review, a QA check, and a security audit. Your AI should not either.

💡 The Solution

CodeMentor AI introduces a deterministic, multi-agent swarm.

  1. Multi-Agent Pipeline: Forces solutions through a sequenced pipeline.
  2. Adversarial Reflection: A dedicated agent whose only job is to brutally critique the code.
  3. Verification Layer: Acts as an air-gapped simulation proxy, mentally dry-running inputs.
  4. Security Firewall: A strict O(1) memory limiter blocking prompt injections before API generation.
  5. MCP Integration: Fully integrates all agents natively into IDEs (VS Code/Cursor).

✨ Key Features

Capability Description Specialized Agent
🧠 Deep Problem Solving Solves and mathematically optimizes algorithms based on constraints. SolverAgent
🐛 Logical Debugging Isolates silent logic flaws mapping them to line-by-line fixes. DebugAgent
📈 Complexity Analysis Exact Big $O$ Time/Space calculations highlighting bottlenecks. ComplexityAgent
🛡️ Edge Case Generation Hunts the specific maximum bounds that cause Memory Limit Exceeded. TestCaseAgent
👔 FAANG Mock Interview Refuses to write the code; uses Socratic probing to test your skills. InterviewAgent
🏆 Contest Strategy Parses problem sets targeting time-management and difficulty estimates. StrategyAgent
🔎 Strict Code Review Acts as an aggressive Principal Engineer enforcing Pythonic paradigms. CodeReviewAgent
🚨 Security Firewall Active heuristic scanner blocking jailbreaks and Denial of Wallet (DoW). SecurityFirewall

📐 Architecture Diagrams

System Architecture

The top-level interaction between the user interface, the Security Firewall, and the LLM Pipeline.

graph TD
    A[User via Streamlit or IDE/MCP] -->|Payload| B(Security Firewall)
    B -->|Sanitized Valid Input| C{ManagerAgent Orchestrator}
    B --x|Prompt Injection Blocked| Z[Drop Connection]
    C --> D[True Pipeline]
    C --> E[Competitive Personas]
    C --> F[Classic Tools]

The True Agent Flow Pipeline

This diagram illustrates the State-Machine generator logic replacing the flawed "single LLM call".

sequenceDiagram
    participant Manager
    participant Solver
    participant Reflector
    participant Verification
    participant QA
    
    Manager->>Solver: Draft Algorithm
    Solver-->>Manager: V1 Code
    Manager->>Reflector: Try to break V1
    Reflector-->>Manager: Revised V2 Code
    Manager->>Verification: Mentally Dry-Run Inputs
    Verification-->>Manager: Verified / Passed
    Manager->>QA: Polish and Explain
    QA-->>Manager: Perfect Pydantic Data

IDE MCP Integration

graph LR
    IDE[VS Code / Cursor] <-->|JSON-RPC via stdio| MCP(FastMCP Server)
    MCP <--> Manager[ManagerAgent Router]
    Manager <--> Gemini[Google GenAI SDK]

🔌 MCP Integration Details

Model Context Protocol (MCP) allows your local IDEs to utilize CodeMentor's unique persona-driven logic natively. CodeMentor exposes the following precise tools:

MCP Tool Name Description
solve_problem_pipeline Triggers the 4-stage Reflection loop for highly reliable code generation.
review_code Triggers the Strict Code Reviewer formatting style outputs.
interview_question_generator Converts the IDE into a Socratic questioning loop for interview prep.
hidden_test_detector Maps adversarial test cases trying to crash the current IDE buffer.
optimize_algorithm Highlights $O(N)$ Big O limits.
coding_strategy Evaluates Contest parameters.

🔒 Security Posture

AI security requires defense-in-depth methodologies. We do not rely on just prompting "Do not be malicious".

  • Prompt Injection Firewall: Employs RegExp blacklists immediately rejecting known jailbreak inputs (ignore previous).
  • Denial of Wallet (DoW) Limits: Strict string bounds mapping applied before the prompt touches the API.
  • Session Abuse Detection: Rolling 60-second window limiting spam bot execution.
  • Execution Proxy: We utilize semantic Agent dry-runs rather than exposing native eval or exec OS vectors.
graph LR
    Input[Payload] --> Bound[Length Check]
    Bound --> Regex[Heuristic Reject]
    Regex --> RateLimit[Abuse Track]
    RateLimit --> LLM[Execution]

📊 Quantitative Benchmarks

Metrics context: Benchmarking executed via simulated Leetcode Hard parameters comparing zero-shot execution versus the V2 Reflection Pipeline.

Execution Mode Prompt Type Pass@1 Accuracy Latency (Avg) Safety / Firewall
Standard LLM Zero-Shot Generalized [Insert %] [Insert sec] Bypassable
CodeMentor (V2) Pipeline Verification [Insert %] [Insert sec] Enforced

See EVALUATION_METRICS.md for our raw execution trace outputs and methodology.


📸 Presentation & Screenshots

The Timeline Dashboard

Pipeline UI Dashboard

The Socratic Mock Interview

Mock Interviewer

VS Code MCP Execution

MCP Trace Trace

Security Attack Mitigation

Firewall Drop


🚀 Installation & Local Setup

1. Repository Clone & Environment

git clone https://github.com/yourusername/codementor-ai.git
cd codementor-ai

# Python 3.11+ is strongly recommended
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt

2. Environment Variables

Copy the template and insert your GEMINI_API_KEY:

cp .env.example .env

3. Execution (Docker & Native)

Running the Web Interface (Native Streamlit):

streamlit run frontend/app.py

Running inside secure Docker containers:

docker-compose up --build

Running the MCP Server for your local IDE:

python -m mcp.server

📂 Project Structure

codementor-ai/
├── agents/                  # The Multi-Agent Intelligence Core
│   ├── manager_agent.py     # Pipeline State-Machine Router
│   ├── reflection_agent.py  # Adversarial Code Critique Component
│   ├── verification_agent.py# Code fact-checking proxy
│   ├── strategy_agent.py    # Competitive Programming Guide
│   └── (..other agents)
├── core/                    # System Integrations
│   ├── config.py            # Pydantic Settings validator
│   └── security.py          # Strict Firewall & Rate Limit logic
├── frontend/
│   └── app.py               # Glassmorphic Streamlit SaaS
├── mcp/
│   └── server.py            # FastMCP native IDE extension bindings
├── .env.example
├── docker-compose.yml
├── requirements.txt
└── README.md

🛣️ Roadmap

  • [x] Abstract initial AI logic into Pydantic structured schemas.
  • [x] Create a multi-stage generator state machine (run_pipeline).
  • [x] Deploy the Model Context Protocol (MCP) integrations.
  • [x] Build the Memory/Abuse Security Firewall.
  • [ ] Connect a true virtualized sub-process REPL (e.g., gVisor) for compilation testing.
  • [ ] Implement Session History export to Cloud Storage (AWS S3/GCP).

🤝 Contributing

We welcome competitive programmers, ML researchers, and open-source contributors to the CodeMentor ecosystem!

  1. Fork the Project.
  2. Create your Feature Branch (git checkout -b feature/AmazingAgent).
  3. Commit your Changes (git commit -m 'Added memory constraint agent').
  4. Push to the Branch (git push origin feature/AmazingAgent).
  5. Open a Pull Request.

Please ensure any new Agent inherits from agents.base_agent and defines a strict Pydantic Output schema.


📄 License

Distributed under the MIT License. See LICENSE for more information.


🙏 Acknowledgements

<div align="center"> <b>Architected for the Kaggle Capstone AI Agents competition.</b> </div>

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选