Spaces:
Paused
Paused
【xxx】修改文件标题 符合huggingface格式,指定启动文件main.py
Browse files
README.md
CHANGED
|
@@ -1,98 +1,109 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
- **
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
```
|
| 41 |
-
|
| 42 |
-
#
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
```
|
| 65 |
-
|
| 66 |
-
```
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
``
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Python-Agent
|
| 3 |
+
emoji: 🤖
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: green
|
| 6 |
+
sdk: gradio
|
| 7 |
+
app_file: main.py # <--- 添加这一行,指定启动文件
|
| 8 |
+
pinned: false
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
# Python Agent
|
| 13 |
+
|
| 14 |
+
A modular Python-based AI agent service built with FastAPI, integrating **Nacos** for service discovery and **Model Context Protocol (MCP)** for extensible tool usage. This agent uses **LangGraph** to orchestrate agentic workflows.
|
| 15 |
+
|
| 16 |
+
## Features
|
| 17 |
+
|
| 18 |
+
- **FastAPI Framework**: High-performance, easy-to-learn web framework.
|
| 19 |
+
- **Service Discovery**: Seamless integration with Nacos for service registration and discovery.
|
| 20 |
+
- **LangGraph**: Stateful, multi-actor applications with cycles (agentic orchestration).
|
| 21 |
+
- **Model Context Protocol (MCP)**:
|
| 22 |
+
- **Stdio Client**: Connects to local CLI tools (e.g., Brave Search via Node.js).
|
| 23 |
+
- **SSE Client**: Connects to remote services (e.g., Java backend) via Server-Sent Events.
|
| 24 |
+
|
| 25 |
+
## Prerequisites
|
| 26 |
+
|
| 27 |
+
- **Python 3.10+**
|
| 28 |
+
- **Node.js**: Required for running the Brave Search MCP server (`npx`).
|
| 29 |
+
- **Nacos Server 2.x**: A running Nacos instance is required for the application to start.
|
| 30 |
+
|
| 31 |
+
## Installation
|
| 32 |
+
|
| 33 |
+
1. Clone the repository:
|
| 34 |
+
```bash
|
| 35 |
+
git clone <repository_url>
|
| 36 |
+
cd python-agent
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
2. Create and activate a virtual environment:
|
| 40 |
+
```bash
|
| 41 |
+
python -m venv .venv
|
| 42 |
+
# Windows
|
| 43 |
+
.venv\Scripts\activate
|
| 44 |
+
# Linux/Mac
|
| 45 |
+
source .venv/bin/activate
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
3. Install dependencies:
|
| 49 |
+
```bash
|
| 50 |
+
pip install -r requirements.txt
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
## Configuration
|
| 54 |
+
|
| 55 |
+
The application is configured via environment variables. You can create a `.env` file in the root directory (see `.env.example`).
|
| 56 |
+
|
| 57 |
+
| Variable | Default | Description |
|
| 58 |
+
|----------|---------|-------------|
|
| 59 |
+
| `APP_ENV` | `development` | Application environment (`development` or `production`). |
|
| 60 |
+
| `HOST` | `0.0.0.0` | Host to bind the server to. |
|
| 61 |
+
| `PORT` | `8181` | Port to listen on. |
|
| 62 |
+
| `NACOS_SERVER_ADDR` | `` | Address of the Nacos server. |
|
| 63 |
+
| `NACOS_NAMESPACE` | `public` | Nacos namespace ID. |
|
| 64 |
+
| `NACOS_USERNAME` | `` | Nacos username. |
|
| 65 |
+
| `NACOS_PASSWORD` | `` | Nacos password. |
|
| 66 |
+
| `SERVICE_NAME` | `python-agent` | Name of this service in Nacos. |
|
| 67 |
+
| `MCP_BRAVE_PATH` | (Auto-detected) | Optional override for `npx` path. |
|
| 68 |
+
| `NACOS_GATEWAY_SERVICE_NAME` | `gateway` | Name of the Java/Gateway service to discover. |
|
| 69 |
+
|
| 70 |
+
## Usage
|
| 71 |
+
|
| 72 |
+
### Running the Application
|
| 73 |
+
|
| 74 |
+
Using `python`:
|
| 75 |
+
```bash
|
| 76 |
+
python main.py
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
Using `uvicorn` (with hot reload):
|
| 80 |
+
```bash
|
| 81 |
+
uvicorn main:app --reload --port 8181
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
> **Note**: The application will fail to start if it cannot connect to the configured Nacos server.
|
| 85 |
+
|
| 86 |
+
### API Endpoints
|
| 87 |
+
|
| 88 |
+
- **Health Check**: `GET /health`
|
| 89 |
+
- **Chat**: `POST /chat`
|
| 90 |
+
```json
|
| 91 |
+
{
|
| 92 |
+
"message": "Search for the latest news on AI."
|
| 93 |
+
}
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
## Project Structure
|
| 97 |
+
|
| 98 |
+
The project follows a modular package structure:
|
| 99 |
+
|
| 100 |
+
```text
|
| 101 |
+
python-agent/
|
| 102 |
+
├── app/
|
| 103 |
+
│ ├── core/ # Core configuration & infrastructure (Nacos, Config)
|
| 104 |
+
│ ├── services/ # External service clients (MCP)
|
| 105 |
+
│ ├── agent/ # LangGraph logic (State, Graph, Nodes)
|
| 106 |
+
│ └── setup.py # Startup setup scripts
|
| 107 |
+
├── main.py # Entry point
|
| 108 |
+
└── ...
|
| 109 |
+
```
|