青戈AI小栈
会员限时8折

免费教程 / AI Agent + RAG + MCP 从零开发校园课程智能助手

AI Agent + RAG + MCP 从零开发校园课程智能助手

  • 难度 入门
  • 10节课
  • 8 小时 53 分钟
  • 396 人学过
  • 更新中

课程简介

先在通用业务脚手架上把登录、用户与权限跑通,再逐步接入 MCP、Agent 与 RAG,做出能查课表、按课程资料作答、并保存学习计划的校园课程智能助手。

开发路线:业务脚手架 → MCP 工具 → Agent 编排 → RAG 知识库 → SSE 过程可见。

%%{init: {
  "theme": "base",
  "themeVariables": {
    "fontFamily": "inherit",
    "primaryTextColor": "#1f2328",
    "lineColor": "#59636e",
    "secondaryColor": "#ddf4ff",
    "tertiaryColor": "#dafbe1"
  }
}}%%
flowchart LR
  A[业务脚手架] --> B[MCP 工具]
  B --> C[Agent 编排]
  C --> D[RAG 知识库]
  D --> E[SSE 过程可见]

  classDef c1 fill:#ddf4ff,stroke:#0969da,color:#1f2328,stroke-width:1.5px
  classDef c2 fill:#dafbe1,stroke:#1a7f37,color:#1f2328,stroke-width:1.5px
  classDef c3 fill:#fff8c5,stroke:#9a6700,color:#1f2328,stroke-width:1.5px
  classDef c4 fill:#ffebe9,stroke:#cf222e,color:#1f2328,stroke-width:1.5px
  classDef c5 fill:#fbefff,stroke:#8250df,color:#1f2328,stroke-width:1.5px
  class A c1
  class B c2
  class C c3
  class D c4
  class E c5

适合谁

  • 有一点 Python 或前端基础,想跟完一个能跑的 AI 全栈项目
  • 听过 MCP / Agent / RAG,但还没在真实业务里串起来
  • 想搞清多用户下如何防越权、如何约束模型不胡编

能学到什么

  • Vue3 + FastAPI 业务底座:登录注册、JWT、用户与菜单权限
  • FastMCP:把查课表、检索资料、存计划暴露为标准工具
  • LangChain Agent(ReAct):决定是否调工具、调哪个、调几次
  • Chroma + Embedding:课程资料 RAG 问答
  • SSE:把工具调用过程实时推到前端

环境要求

  • Node.js(建议最新 LTS)
  • Python 3.12+
  • MySQL 8.0+
  • VS Code(可选,便于跟笔记调试)

技术栈

端 技术
前端 Vue 3 · Vite · Element Plus · Axios
后端 Python · FastAPI · SQLAlchemy · JWT
数据库 MySQL
工具协议 FastMCP(独立进程)
AI LangChain · LangGraph · Chroma · RAG · SSE

大模型按 OpenAI 兼容协议接入(如 DeepSeek);Embedding 默认可用硅基流动 bge-m3。

业务场景

学生登录后向助手提问:查自己的课表、根据已上传的课程资料回答问题,并生成学习计划保存下来。管理员维护用户与资料入库;助手只能查当前用户有权限的数据,不能越权看别人的课表。

%%{init: {
  "theme": "base",
  "themeVariables": {
    "fontFamily": "inherit",
    "primaryTextColor": "#1f2328",
    "lineColor": "#59636e",
    "secondaryColor": "#ddf4ff",
    "tertiaryColor": "#fff8c5"
  }
}}%%
flowchart TD
  S[学生] --> Q[自然语言提问]
  Q --> A{助手处理}
  A -->|查课表| T[返回本人课表]
  A -->|问资料| R[RAG 检索后作答]
  A -->|要计划| P[生成并保存学习计划]
  ADM[管理员] --> M[维护用户 / 资料入库]

  classDef actor fill:#ddf4ff,stroke:#0969da,color:#1f2328,stroke-width:1.5px
  classDef step fill:#dafbe1,stroke:#1a7f37,color:#1f2328,stroke-width:1.5px
  classDef decision fill:#fbefff,stroke:#8250df,color:#1f2328,stroke-width:1.5px
  classDef admin fill:#fff8c5,stroke:#9a6700,color:#1f2328,stroke-width:1.5px
  class S,ADM actor
  class Q,T,R,P step
  class A decision
  class M admin

运行时通常同时有:前端、FastAPI(业务 + Agent)、MCP 工具进程、MySQL、Chroma;大模型与 Embedding 走第三方 API。

Agent 与 MCP

  • 业务脚手架:登录、用户、菜单,后续能力都挂在这上面
  • MCP 工具:查课表 / 检索资料 / 存计划,与业务 API 解耦、可单独演进
  • Agent:按 ReAct 决定是否调用工具、调用哪个
  • RAG:课程文档向量化,回答时先检索再生成,减少胡编
  • SSE:流式输出,工具调用过程可见
%%{init: {
  "theme": "base",
  "themeVariables": {
    "fontFamily": "inherit",
    "actorBkg": "#ddf4ff",
    "actorBorder": "#0969da",
    "actorTextColor": "#1f2328",
    "actorLineColor": "#0969da",
    "signalColor": "#1f2328",
    "signalTextColor": "#1f2328",
    "labelBoxBkgColor": "#fff8c5",
    "labelBoxBorderColor": "#9a6700",
    "labelTextColor": "#1f2328",
    "noteBkgColor": "#dafbe1",
    "noteTextColor": "#1f2328",
    "noteBorderColor": "#1a7f37",
    "activationBkgColor": "#fbefff",
    "activationBorderColor": "#8250df",
    "sequenceNumberColor": "#ffffff"
  }
}}%%
sequenceDiagram
  participant U as 用户
  participant FE as 前端
  participant API as FastAPI
  participant MCP as MCP 服务
  participant LLM as 大模型
  participant DB as MySQL
  participant VDB as Chroma

  U->>FE: 自然语言提问
  FE->>API: SSE 对话请求
  API->>LLM: 上下文 + 工具定义
  LLM-->>API: 决定调工具或直接答
  API->>MCP: 调用课表 / 检索 / 计划工具
  MCP->>DB: 查课表或写计划
  MCP->>VDB: RAG 检索资料
  DB-->>MCP: 业务数据
  VDB-->>MCP: 相关片段
  MCP-->>API: 工具结果
  API->>LLM: 工具结果续写
  LLM-->>API: 最终回复
  API-->>FE: SSE 推送过程与答案
  FE-->>U: 流式展示

课程结构

  1. 起步:项目介绍与成品演示 → 环境配置与脚手架跑通
  2. 业务与工具:课表 / 资料等业务能力 → FastMCP 工具暴露
  3. Agent 与 RAG:ReAct Agent 编排 → 知识库问答 → SSE 过程可见
%%{init: {
  "theme": "base",
  "themeVariables": {
    "fontFamily": "inherit",
    "primaryTextColor": "#1f2328",
    "lineColor": "#59636e",
    "clusterBkg": "#f7f8fa",
    "clusterBorder": "#c3c7cb",
    "titleColor": "#1f2328"
  }
}}%%
flowchart TB
  subgraph P1[起步]
    p1a[介绍与成品演示]
    p1b[环境与脚手架]
    p1a --> p1b
  end
  subgraph P2[业务与工具]
    p2a[课表 / 资料等业务]
    p2b[FastMCP 工具]
    p2a --> p2b
  end
  subgraph P3[Agent 与 RAG]
    p3a[ReAct Agent]
    p3b[RAG 知识库]
    p3c[SSE 过程可见]
    p3a --> p3b --> p3c
  end
  P1 --> P2 --> P3

  classDef start fill:#ddf4ff,stroke:#0969da,color:#1f2328,stroke-width:1.5px
  classDef biz fill:#dafbe1,stroke:#1a7f37,color:#1f2328,stroke-width:1.5px
  classDef ai fill:#fbefff,stroke:#8250df,color:#1f2328,stroke-width:1.5px
  class p1a,p1b start
  class p2a,p2b biz
  class p3a,p3b,p3c ai

图文笔记站内阅读,视频在 B 站对应分集。三连解锁后可下载脚手架;会员可下载带敲完成源码。

源码说明

  • 脚手架:登录、用户、菜单等通用地基(三连或会员可下)
  • 完成包:会员可下;含前后端完整代码(已排除 node_modules、.venv 等)与脱敏 .env 示例

知识库向量需按笔记在本地重建,包内一般不附带已训练向量目录。

设置你的昵称

在英雄榜和讨论中,使用你自己的名字。

2–12 个字符0 / 12