privateGPT MCP Server
by Fujitsu-AI
- agents
- ChatBotAgent
# PrivateGPT ChatBot Agent
## Overview
The **PrivateGPT ChatBot Agent** is a crucial component of the Fujitsu PrivateGPT multi-agent system. It acts as a client that communicates with a private GPT server to respond to queries and provide information. This agent leverages both local knowledge databases and server-based responses, employing **FIPA ACL (Agent Communication Language)** to standardize communications within the system.
---
## Features
- **Multi-Agent Communication via FIPA ACL:**
- Handles structured messages with standardized fields such as `performative`, `sender`, `receiver`, `ontology`, and `content`.
- Sends FIPA ACL failure messages if a connection to the MCP server cannot be established.
- **Production WSGI Servers: Waitress & Gunicorn:**
- Manages RESTful endpoints (e.g., `/ask`, `/logs`, `/status`) using Flask.
- Uses Waitress for serving requests in Windows environments and Gunicorn for Unix-based systems, ensuring readiness for production environments.
- Implements Cross-Origin Resource Sharing (CORS) to allow requests from any domain (`origins: "*"`) for broad compatibility.
- **Authentication:**
- All endpoints, except for `OPTIONS` and `/status`, require an API key sent via the `X-API-KEY` header.
- **MCP Server Connectivity:**
- Ensures connectivity to the MCP server (as defined in `config.json`) is validated before processing requests.
- **Logging:**
- Maintains detailed logs for both the agent operations (`agent.log`) and the Flask server (`flask.log`).
## Prerequisites
- **Python:** Version 3.8 or higher
- **Dependencies:**
Install the required packages listed in the corresponding `requirements.txt` which includes Flask, waitress (for Windows), gunicorn (for Unix-based systems), flask-cors, paho-mqtt, paramiko, etc.
---
## Setup
1. **Clone the Repository:**
```bash
git clone https://github.com/pgpt-dev/MCP-Server-for-MAS-Developments.git
cd MCP-Server-for-MAS-Developments
```
2. **(Optional) Create and Activate a Virtual Environment:**
- **Windows:**
```bash
python -m venv venv
.\venv\Scripts\activate
```
- **Unix/MacOS:**
```bash
python -m venv venv
source venv/bin/activate
```
3. **Install Dependencies:**
```bash
pip install -r agents/ChatBotAgent/requirements.txt
```
4. **Configure the Agent:**
Copy the example configuration file and adjust it according to your environment:
```bash
cp agents/ChatBotAgent/config.json.example agents/ChatBotAgent/config.json
```
**Example `config.json`:**
```json
{
"email": "<YOUR EMAIL>",
"password": "<YOUR PASSWORD>",
"api_ip": "0.0.0.0",
"api_port": 5001,
"api_key": "<YOUR_API_KEY>",
"mcp_server": {
"host": "172.24.123.123",
"port": 5000
},
"language": "en",
"groups": ["<Your Group>"]
}
```
**Note:** All sensitive parameters, such as `email` and `password`, should be securely stored and managed.
## Running the Agent
- **Using Waitress (Windows):**
To start the ChatBot Agent, ensure you are in the repository's root directory and execute:
```bash
python -m agents.ChatBotAgent.Python.chatbot_agent
```
- **Using Gunicorn (Unix-based systems):**
To start the application using Gunicorn, run the following command:
```bash
gunicorn -w 4 -b 0.0.0.0:5001 agents.ChatBotAgent.Python.chatbot_agent:app
```
This command launches the Flask API server using Gunicorn on the configured `api_ip` and `api_port` and uses multiple workers to handle requests efficiently. The `fcntl` package is needed to run this under Linux, use `pip` to install it.
---
## API Endpoints
### `/ask` (POST)
- **Purpose:**
Accepts questions for the ChatBot Agent. This endpoint supports both a **FIPA ACL** structured message and a legacy JSON format.
- **Authentication:**
Requires the `X-API-KEY` header with the correct API key.
- **FIPA ACL Request Example:**
```json
{
"performative": "request",
"sender": "IoT_MQTT_Agent",
"receiver": "Chatbot_Agent",
"ontology": "fujitsu-iot-ontology",
"content": {
"question": "What is the system status?",
"usePublic": false,
"groups": ["group1"],
"language": "en"
}
}
```
- **Legacy JSON Request Example:**
```json
{
"question": "What is the system status?",
"usePublic": false,
"groups": ["group1"],
"language": "en"
}
```
- **Response:**
Returns a JSON object containing the answer generated by the PrivateGPT server. If the MCP server connection fails, a FIPA ACL failure message is returned.
### `/logs` (GET)
- **Purpose:**
Provides access to the Flask server's log file (`flask.log`) for debugging and monitoring purposes.
### `/status` (GET)
- **Purpose:**
Outputs a simple JSON message confirming that the agent is operational. This endpoint does **not** require authentication.
---
## Multi-Agent Communication & FIPA ACL
The ChatBot Agent utilizes **FIPA ACL** to structure its communications with other agents, ensuring reliable interactions within a multi-agent system. It provides standardized message fields for consistency and effective communication.
---
## Logging & Debugging
- **Agent Logs:**
Key events, errors, and status updates are logged in `agent.log`.
- **Flask Logs:**
Logs specific to the Flask server are stored in `flask.log`.
These logs are critical for troubleshooting and provide insights into the agent's operation.
---
## Example Conversation
```plaintext
π Welcome to the PrivateGPT ChatBot Agent.
You: What is your name?
Agent: I am the PrivateGPT ChatBot Agent.
You: Provide system status.
Agent: The system is running normally.
```
---