试剂忘记煮沸板🚀
终极全栈AI代理入门套件
AgentForge是用于构建高级AI代理的生产就绪样板。它结合了 LangGraph 对于编排, 检索增强生成 用于知识检索,以及 MCP(模型上下文协议) 用于标准化工具集成——所有这些都包含在现代 快速API 后端和 反应 前端。.
✨ 主要特点
- 🤖 多代理编排器:高级V2架构,具有专门的并行代理(历史、RAG、内存、Web)和验证器循环。
- ⚡ 语义缓存:基于Qdrant的缓存,可立即为重复查询提供服务,减少延迟和成本。
- 🔄 RLHF反馈回路:内置机制,用于收集用户反馈(拇指向上/向下),以便将来对模型进行微调。
- 📚 RAG管道v2:具有语义分块、重新排名和混合搜索的高级检索。
- 🔌 MCP集成:完全支持Anthropic的模型上下文协议(客户端和服务器端)。
- 🛡️ 护栏:安全、隐私(PII编辑)和质量的输入/输出验证。
- ⚡ 全栈:
- 后端:具有异步支持和流式响应的FastAPI。 - 前端:使用TailwindCSS和markdown渲染的现代React(Vite)。
- 🧠 记忆:使用SQLite持久化用户记忆。
- 🔍 网页搜索:通过DuckDuckGo和Brave集成免费网络搜索。
🏗️ 架构概述
graph TD
User[User / Frontend] |Rest API / SSE| API[FastAPI Backend]
API |Orchestration| Agent[LangGraph Agent]
subgraph "Agent Brain"
Agent |Safety| Guard[Guardrails]
Agent |Context| RAG[RAG Pipeline]
Agent |Tools| MCP[MCP Client]
Agent |State| Memory[SQLite Memory]
end
subgraph "External"
MCP |Protocol| Tools[External Tools]
RAG |Embeddings| VectorDB[Vector Store]
Agent |Inference| LLM[OpenAI GPT-4o]
end🚀 入门指南
先决条件
- Python 3.10+
- Node.js 18+
- OpenAI API密钥
1.克隆和设置
git clone https://github.com/yourusername/agentforge.git](https://github.com/jadenitishraj/Agent-langchain-rag-mcp-tools-boilerplate.git
cd agentforge2.后端设置
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Configure environment
cp .env.example .env
# Edit .env and add your OPENAI_API_KEY3.前端设置
cd frontend
npm install4.为代码库(RAG)编制索引
通过索引代码库使代理具有自我意识:
# From root directory
source venv/bin/activate
python scripts/index_codebase.py5.运行一切
您可以单独运行组件:
后端:
uvicorn main:app --reload --port 8000前端:
cd frontend
npm run dev访问 http://localhost:5173 与您的经纪人聊天!
📂 项目结构
langraph/:核心代理逻辑,包括V2多代理编排器(agent_v2.py).rag_v2/:先进的RAG管道和 语义缓存管理器.routers/:FastAPI路由,包括新的 RLHF反馈API.mcp_servers/:模型上下文协议服务器(搜索、SQLite)。guardrails/:输入/输出安全检查(PII、毒性、幻觉)。frontend/:使用TailwindCSS进行反应应用程序。tools/:自定义工具(内存、联系人)。
🛠️ 定制
添加新工具
- 在中定义您的工具
tools/my_tool.py使用@tool装饰师。 - 添加到
ALL_TOOLS在tools/__init__.py. - 代理将自动检测并使用它!
修改系统提示
编辑 langraph/agent.py 并更新 SYSTEM_PROMPT 变量来改变代理的个性和指示。
🤝 贡献
欢迎投稿!请阅读 CONTRIBUTING.md 了解详情。
📄 许可证
麻省理工学院许可证-请随时将此样板用于您自己的项目!
🚀 Agent V2:多代理编排器
该系统现在包括一个高级 多代理架构 (agent_v2.py)它用一组专门的人工智能工作人员取代了单节点代理。
🏗️ 建筑
这 编排器 计划执行并将任务委托给并行代理。这 合并器 综合他们的报告,以及 验证器 质量检查结果。
VerifierAgent -- Rejected --> CombinerAgent
OutputGuardrails --> FinalOutput
### ⚡ Key Features
1. **Orchestrator**: The "Mastermind" that coordinates the workflow.
2. **True Parallel Execution**:
- **History Agent**: Summarizes conversation context.
- **RAG Agent**: Retrieves code/docs from the vector database.
- **Memory Agent**: Fetches user preferences and facts.
- **Web Agent**: Searches the internet for real-time info.
- _All these run simultaneously for maximum speed._
3. **Combiner Agent**: Synthesizes conflicting or distributed information into a single, cohesive answer.
4. **Verifier Agent**: Acts as a QA Lead, critiquing the draft and requesting improvements if needed.
5. **Streaming**: Manual orchestration allows real-time token streaming from the Combiner Agent to the UI.
## 🧠 Gen AI Best Practices
### ⚡ Semantic Caching (Latent Optimization)
To reduce costs and latency, the system implements **Semantic Caching** using Qdrant.
- **How it works**: Before querying the LLM, the system embeds the user's question and searches for similar past queries (Threshold: `0.70`).
- **Benefit**: If a similar question was asked before, the cached response is returned **instantly** (< 0.5s), avoiding expensive LLM calls.
### 🔄 RLHF Feedback Loop (Data Flywheel)
The system now supports **Reinforcement Learning from Human Feedback (RLHF)** data collection.
- **Feedback API**: `/feedback` endpoint allows users to rate responses (Thumbs Up/Down).
- **Storage**: Feedback is stored in the database (`Feedback` table) to be used for future fine-tuning or RAG evaluation.