跳到主要内容

Week 10: 完整 Agent 项目

目标:构建一个功能完整的 Agent 项目,包含多工具、错误处理、记忆、API 和 UI

学习安排

文件内容时间
Day 1day1_multi_tools.py添加多种工具:文件读写、网页摘要、代码执行45min
Day 2day2_error_handling.py错误处理:工具失败时的重试和回退30min
Day 3day3_conversation_memory.pyAgent 的对话记忆管理30min
Day 4day4_fastapi_agent.py把 Agent 包装成 FastAPI API45min
Day 5day5_react_agent_ui/index.htmlReact UI 展示 Agent 思考过程(CDN React,单 HTML)60min
Day 6-7day67_full_project.py完整项目整合 + README 模板60min

环境准备

cd docs/14-AI/week10-agent-project
python -m venv .venv && source .venv/bin/activate
pip install langchain langchain-community langchain-chroma chromadb langgraph
pip install fastapi uvicorn openai python-dotenv httpx
pip install beautifulsoup4

# Ollama 模型
ollama pull qwen2.5:7b
ollama pull nomic-embed-text

项目架构

完整 Agent 项目架构:

┌─────────────────────────────────────────────┐
│ React UI │
│ (展示思考过程 + 对话界面) │
├─────────────────────────────────────────────┤
│ FastAPI Server │
│ (HTTP API + SSE streaming) │
├─────────────────────────────────────────────┤
│ Agent Core (LangGraph) │
│ ┌─────────┐ ┌──────────┐ ┌──────────┐ │
│ │ 多工具 │ │ 错误处理 │ │ 对话记忆 │ │
│ │ 管理器 │ │ 重试回退 │ │ 管理器 │ │
│ └─────────┘ └──────────┘ └──────────┘ │
├─────────────────────────────────────────────┤
│ Ollama (LLM) │ Chroma (RAG) │
└─────────────────────────────────────────────┘