# sagittarius **Repository Path**: MarsBighead/sagittarius ## Basic Information - **Project Name**: sagittarius - **Description**: Sagittarius - **Primary Language**: Python - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-01-15 - **Last Updated**: 2026-01-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: AI, Agent, RAG ## README # Sagittarius - AI Agent Prototype 一个基于LangGraph和AutoGen框架的AI Agent原型,支持PGvector数据库和SSE流式返回。 ## 功能特性 - ✅ 支持PGvector数据库,用于RAG知识库调用 - ✅ 基于LangGraph框架实现Agent - ✅ 基于AutoGen框架实现Agent - ✅ 支持LLM多次循环调用 - ✅ SSE流式返回结果 - ✅ FastAPI HTTP接口 - ✅ 模块化架构设计 - ✅ 异步数据库操作 - ✅ 可配置的嵌入模型 ## 项目结构 ``` sagittarius/ ├── src/sagittarius/ │ ├── __init__.py │ ├── main.py # 应用入口和生命周期管理 │ ├── config.py # 配置管理 │ ├── client.py # 客户端工具 │ ├── agenthub/ # Agent实现模块 │ │ ├── __init__.py │ │ ├── base.py # Agent基类 │ │ ├── langgraph_agent.py │ │ └── autogen_agent.py │ ├── api/ # API层 │ │ ├── __init__.py │ │ ├── chat.py # 聊天接口路由 │ │ └── dependencies.py # 依赖注入 │ ├── core/ # 核心模块 │ │ ├── common/ # 通用工具 │ │ │ ├── __init__.py │ │ │ └── logger.py # 日志配置 │ │ └── providers/ # 服务提供者 │ │ ├── __init__.py │ │ ├── _types.py # 类型定义 │ │ ├── database.py # 数据库管理 │ │ └── embedding.py # 嵌入服务 │ ├── database/ # 数据访问层 │ │ ├── __init__.py │ │ └── retriever.py # 检索器 │ └── models/ # 数据模型 │ └── schemas/ # API Schema │ ├── __init__.py │ └── chat.py # 聊天相关Schema ├── tests/ ├── scripts/ ├── pyproject.toml ├── .env.example └── README.md ``` ## 核心模块说明 ### 1. 配置管理 (config.py) - 基于Pydantic Settings的配置管理 - 支持环境变量和.env文件 - 统一管理数据库、LLM、嵌入模型等配置 ### 2. Agent框架 (agenthub/) - **BaseAgent**: 抽象基类,提供统一的接口和通用功能 - **LangGraphAgent**: 基于LangGraph框架的Agent实现 - **AutoGenAgent**: 基于AutoGen框架的Agent实现 - 支持RAG检索和流式响应 ### 3. 核心服务 (core/providers/) - **VectorDatabaseManager**: 向量数据库管理 - **EmbeddingProvider**: 嵌入向量服务 - 异步操作支持,高性能数据库连接 ### 4. API层 (api/) - FastAPI路由定义 - SSE流式响应支持 - 依赖注入管理 - 健康检查接口 ### 5. 数据访问层 (database/) - **RetrieverHandler**: 向量检索处理器 - 相似度搜索功能 - 支持多文档检索 ## 快速开始 ### 1. 环境准备 确保已安装: - Python 3.10+ - PostgreSQL + PGvector扩展 - Ollama (本地LLM服务) ### 2. 安装依赖 ```bash # 使用uv包管理器 uv sync # 或使用pip pip install -e . ``` ### 3. 配置环境 ```bash # 复制环境变量模板 cp .env.example .env # 编辑.env文件,配置数据库和LLM vim .env ``` 环境变量配置示例: ```bash # Database Configuration DATABASE_URL=postgresql://user:password@localhost:5432/sagittarius # Ollama Configuration OLLAMA_BASE_URL=http://localhost:11434 OLLAMA_MODEL=qwen2:7b EMBEDDING_MODEL=nomic-embed-text # OpenAI Compatible API (for Ollama) OPENAI_API_KEY=ollama OPENAI_BASE_URL=http://localhost:11434/v1 ``` ### 4. 启动服务 ```bash # 开发模式启动 uv run python -m sagittarius.main # 或使用uvicorn直接启动 uvicorn sagittarius.main:app --host 0.0.0.0 --port 8000 --reload ``` 服务启动后访问: http://localhost:8000 ## API调用示例 ### 1. 健康检查 ```bash curl -X GET "http://localhost:8000/api/v1/health" \ -H "Content-Type: application/json" ``` 响应示例: ```json { "status": "healthy", "database": true, "llm": true, "version": "0.1.0" } ``` ### 2. 流式聊天 (LangGraph Agent) ```bash curl -X POST "http://localhost:8000/api/v1/chat" \ -H "Content-Type: application/json" \ -H "Accept: text/event-stream" \ -d '{ "query": "请介绍一下人工智能的发展历史", "agent_type": "langgraph", "context": {"temperature": 0.7} }' ``` ### 3. 流式聊天 (AutoGen Agent) ```bash curl -X POST "http://localhost:8000/api/v1/chat" \ -H "Content-Type: application/json" \ -H "Accept: text/event-stream" \ -d '{ "query": "帮我分析一下这个技术问题", "agent_type": "autogen", "context": {"max_tokens": 1000} }' ``` ### 4. Python客户端调用示例 ```python import asyncio import aiohttp import json async def chat_stream_example(): async with aiohttp.ClientSession() as session: async with session.post( "http://localhost:8000/api/v1/chat", json={ "query": "请解释机器学习的基本概念", "agent_type": "langgraph", "context": {"temperature": 0.7} }, headers={"Accept": "text/event-stream"} ) as response: async for line in response.content: if line.startswith(b'data: '): data = json.loads(line[6:].decode()) if 'content' in data: print(data['content'], end='', flush=True) # 运行示例 asyncio.run(chat_stream_example()) ``` ## 技术栈 - **语言**: Python 3.10+ - **包管理**: uv - **Web框架**: FastAPI - **Agent框架**: LangGraph, AutoGen - **数据库**: PostgreSQL + PGvector - **LLM服务**: Ollama (OpenAI兼容API) - **嵌入模型**: nomic-embed-text - **生成模型**: qwen2:7b - **异步支持**: asyncio, asyncpg ## 开发指南 ### 添加新的Agent类型 1. 在 `agenthub/` 目录下创建新的Agent类,继承 `BaseAgent` 2. 实现 `_generate_with_context` 方法 3. 在 `api/chat.py` 中添加Agent类型支持 4. 更新相关Schema定义 ### 自定义配置 通过修改 `.env` 文件或环境变量来自定义配置: - 数据库连接字符串 - LLM模型和参数 - 嵌入模型选择 - 日志级别和目录 ### 扩展功能 项目采用模块化设计,便于扩展: - 添加新的数据源支持 - 集成其他LLM提供商 - 实现自定义检索策略 - 添加监控和指标收集 ## 贡献指南 欢迎提交Issue和Pull Request来改进项目。 ## 许可证 MIT License