# agent **Repository Path**: kenithcai/agent ## Basic Information - **Project Name**: agent - **Description**: 123 - **Primary Language**: Python - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-07-11 - **Last Updated**: 2026-07-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Finance AI Agent Server 基于 FastAPI + LangGraph 的多 Agent 财务智能问答服务,支持本地/云端 LLM、RAG 知识库(SQLite + 向量检索)、OCR 票据识别和 AI 图像生成(文生图 / 图生图)。 ## 功能特性 - **多 Agent 智能问答**:Planner → Researcher → Writer 三级流水线,自动拆解问题、检索资料、生成回答 - **RAG 知识库**:SQLite FTS5 结构化检索 + Ollama bge-m3 向量语义检索 + PaddleOCR 票据识别 - **多 LLM 支持**:DeepSeek Chat(云端)/ Qwen2.5:7B(Ollama 本地),通过 `USE_LOCAL_LLM` 切换 - **AI 图像生成**:文生图 + 图生图,支持智谱 CogView / OpenAI DALL-E 3 / 阿里通义万相 - **流式 SSE 输出**:支持实时流式响应,打字机效果 - **文件导出**:自动检测导出意图,生成 Excel / CSV / HTML / PDF ## 快速开始 ```bash # 安装依赖 python3 -m venv .venv && source .venv/bin/activate python -m pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple # OCR(处理 PDF 扫描件/图片) python -m pip install paddlepaddle paddleocr -i https://pypi.tuna.tsinghua.edu.cn/simple # 启动服务 cd server uvicorn app:app --reload --port 8000 # 验证 curl http://localhost:8000/health ``` ## API 端点 | 方法 | 路径 | 说明 | |------|------|------| | GET | `/health` | 健康检查 | | POST | `/agent` | 非流式智能问答 | | GET | `/agent/stream?input=...` | 流式智能问答(SSE) | | POST | `/agent/stream` | 流式智能问答(JSON body,支持多轮对话) | | POST | `/image/generate` | 文生图:`{"prompt": "描述"}` | | POST | `/image/edit` | 图生图:base64 或文件上传 | | GET | `/rag/status` | RAG 数据库状态 | | GET | `/download/{path}` | 下载导出的文件 | ## 图像生成 支持文生图(Text-to-Image)和图生图(Image-to-Image),通过对话或独立 API 调用: ```bash # 独立 API:文生图 curl -X POST localhost:8000/image/generate \ -H 'Content-Type: application/json' \ -d '{"prompt": "一只可爱的橘猫坐在草地上,阳光下"}' # 独立 API:图生图(文件上传) curl -X POST localhost:8000/image/edit \ -F "prompt=添加一顶帽子" \ -F "image=@input.png" # 对话中生成:Agent 自动识别意图 curl "localhost:8000/agent/stream?input=帮我画张图:财务数据概览仪表盘" ``` **支持的 Provider**(在 `image_gen.py` 中切换 `IMAGE_PROVIDER`): | Provider | 说明 | |----------|------| | `zhipu`(默认) | 智谱 CogView,中文文字生成最佳 | | `openai` | OpenAI DALL-E 3 / gpt-image-1 | | `dashscope` | 阿里云通义万相 | > **注意**:DeepSeek 不支持图像生成,请使用上述 Provider。 ## 项目结构 ``` server/ ├── app.py # FastAPI 应用入口 ├── core.py # 共享配置、LLM 抽象、SSE 工具 ├── llm_cloud.py # DeepSeek 云端 LLM ├── llm_local.py # Ollama 本地 LLM ├── image_gen.py # 图像生成模块 ├── web_search.py # 网页搜索 ├── config/ │ ├── agents.yaml # Agent 角色配置 │ └── tasks.yaml # 任务路由规则 ├── agent/ │ ├── state.py # LangGraph AgentState │ ├── graph.py # LangGraph 图定义 + Agent 函数 │ ├── research.py # 检索 Agent │ └── tool_runner.py # 工具调用(文件导出) ├── rag/ # RAG 知识库子系统 └── tools/ # 文件导出工具 ``` ## 开发指南 详见 `server/CLAUDE.md`。