Skip to content

Chaud-FS/WorkspaceSync-AI-Agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WorkspaceSync AI Agent

Python FastAPI LangGraph License Status

基于 LangGraph + Function Calling 构建的智能工作区助手

📖 项目简介

WorkspaceSync AI Agent 是一个面向日常办公场景的 AI 智能助手,支持自然语言驱动的多工具调度。它能读取 Excel、生成日报、总结 PDF、联网搜索、查询天气、计算器、执行 Python 代码、操作数据库等,并可通过 MCP (Model Context Protocol) 扩展更多能力。

🎯 核心特性

能力 描述 技术
📊 读取 Excel 读取并分析 .xlsx/.csv 文件 openpyxl, pandas
📝 生成日报 根据工作记录自动生成结构化日报 Jinja2, python-docx
📄 总结 PDF 提取 PDF 内容并生成摘要 PyMuPDF, pdfplumber
🌐 联网搜索 实时搜索互联网信息 DuckDuckGo / SerpAPI
🌤️ 天气查询 查询指定城市天气 OpenWeatherMap API
🧮 计算器 执行数学表达式计算 Python eval (安全沙箱)
🐍 执行 Python 沙箱式 Python 代码执行 RestrictedPython
🗄️ 数据库操作 连接并查询数据库 SQLAlchemy
🔌 MCP 扩展 Model Context Protocol 工具扩展 mcp

🏗️ 技术架构

┌─────────────────────────────────────────────┐
│              FastAPI Web Server              │
│          (REST API + WebSocket)             │
├─────────────────────────────────────────────┤
│              LangGraph Agent                │
│    ┌──────────┐  ┌──────────┐  ┌─────────┐ │
│    │  Router  │→ │ Function │→ │ Tool    │ │
│    │  (意图路由)│  │ Calling  │  │ Executor│ │
│    └──────────┘  └──────────┘  └─────────┘ │
├─────────────────────────────────────────────┤
│                 Tool Layer                   │
│  ┌────┐ ┌────┐ ┌────┐ ┌────┐ ┌────┐ ...   │
│  │Excel│ │PDF │ │Web │ │DB  │ │Calc│       │
│  └────┘ └────┘ └────┘ └────┘ └────┘       │
├─────────────────────────────────────────────┤
│              MCP Server (可插拔)              │
└─────────────────────────────────────────────┘

🚀 快速开始

环境要求

  • Python 3.10+
  • pip / uv

安装

git clone https://github.com/Chaud-FS/WorkspaceSync-AI-Agent.git
cd WorkspaceSync-AI-Agent

# 创建虚拟环境
python -m venv venv
source venv/bin/activate  # Linux/Mac
# 或 venv\Scripts\activate  # Windows

# 安装依赖
pip install -r requirements.txt

配置

cp .env.example .env
# 编辑 .env 填入你的 API Key

运行

# 启动 API 服务
python -m src.main

# 或使用 uvicorn
uvicorn src.api.server:app --host 0.0.0.0 --port 8000 --reload

访问 http://localhost:8000/docs 查看 Swagger API 文档。

📁 项目结构

WorkspaceSync-AI-Agent/
├── src/                        # 核心源码
│   ├── agent/                  # Agent 核心
│   │   ├── core.py             # 主 Agent 逻辑
│   │   ├── graph.py            # LangGraph 工作流定义
│   │   └── router.py           # 意图路由
│   ├── tools/                  # 工具集
│   │   ├── excel_tool.py       # Excel 处理
│   │   ├── report_tool.py      # 日报生成
│   │   ├── pdf_tool.py         # PDF 处理
│   │   ├── web_search_tool.py  # 联网搜索
│   │   ├── weather_tool.py     # 天气查询
│   │   ├── calculator_tool.py  # 计算器
│   │   ├── python_executor.py  # Python 执行器
│   │   └── database_tool.py    # 数据库操作
│   ├── api/                    # FastAPI 接口
│   │   ├── server.py           # API 服务入口
│   │   ├── routes.py           # 路由定义
│   │   └── schemas.py          # Pydantic 模型
│   └── config/                 # 配置
│       └── settings.py         # 全局配置
├── mcp/                        # MCP Server
│   └── mcp_server.py           # MCP 服务实现
├── tests/                      # 测试用例
├── requirements.txt            # Python 依赖
├── .env.example                # 环境变量模板
└── README.md                   # 项目说明

💡 使用示例

API 调用

import requests

# 发送任务
response = requests.post("http://localhost:8000/api/chat", json={
    "message": "帮我读取 sales.xlsx 并生成今日销售日报",
    "session_id": "user-001"
})

print(response.json())

自然语言交互示例

用户: 北京今天天气怎么样?
Agent: [调用天气工具] → "北京今天晴,25°C,适合出行。"

用户: 计算 (150 + 300) * 0.1 / 2
Agent: [调用计算器] → "计算结果为 22.5"

用户: 帮我看看这个月的销售数据 excel,汇总一下
Agent: [调用Excel工具] → "本月总销售额 ¥158,000,环比增长12%..."

用户: 根据我今天的工作记录生成日报
Agent: [调用日报工具] → "已生成 daily_report_2026-07-15.docx"

🛠️ 技术栈

组件 技术 说明
Agent 框架 LangGraph 有状态多步骤 Agent 工作流
Function Calling OpenAI-compatible 兼容 Qwen-Agent / GPT 等模型
API 框架 FastAPI 高性能异步 Web 框架
工具协议 MCP Model Context Protocol
数据处理 pandas, openpyxl Excel 读写分析
PDF 处理 PyMuPDF, pdfplumber PDF 文本提取
数据库 SQLAlchemy ORM 数据库抽象层
文档生成 python-docx Word 文档生成

🤝 贡献

欢迎提交 Issue 和 Pull Request!

📄 License

MIT License - 详见 LICENSE 文件

About

No description, website, or topics provided.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages