Compare commits

...

3 Commits

Author SHA1 Message Date
a5fe899eb5 update 2025-03-02 16:12:24 +08:00
23f8c9a6a9 update 2025-03-02 16:00:42 +08:00
42038a89e5 修改readme 2025-03-02 15:54:30 +08:00
14 changed files with 211 additions and 251 deletions

3
.gitignore vendored
View File

@@ -1,6 +1,7 @@
# ---> Python
.gitignore
backend/evaluate/eval_rag_result
backend/psk-graphrag
backend/evaluate/eval_rag_dataset/*
backend/history/*
# Byte-compiled / optimized / DLL files
__pycache__/

169
README.md
View File

@@ -1,85 +1,104 @@
Ubuntu20.04 + python3.11.9 + django
#1、安装python3.11.9
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget
wget https://www.python.org/ftp/python/3.11.9/Python-3.11.9.tgz
tar zxvf Python-3.11.9.tgz
cd Python-3.11.9
./configure --enable-optimizations
make -j$(nproc)
sudo make altinstall
python3.11 -m ensurepip --upgrade
wget https://bootstrap.pypa.io/get-pip.py
python3.11 get-pip.py
#2、安装python虚拟环境和依赖
cd /opt/matagent
python3.11 -m venv pyautogen
source pyautogen/bin/activate
#安装pyautogen
pip install pyautogen==0.2.34
pip install flaml[automl]
pip install chromadb
pip install Image
#安装django
pip install django
pip install djangorestframework
pip install requests
#安装 websocket支持 channels+asgi
pip install channels
pip install asgiref # Django Channels 依赖的包
#运行服务支持http+websocket websocket接口 ws://192.168.42.130:8000/matagent/chat
DJANGO_SETTINGS_MODULE=matagent.settings uvicorn matagent.asgi:application --host 0.0.0.0 --port 8000
#安装nginx
sudo apt-get update
sudo apt-get install nginx
--查看状态
sudo systemctl status nginx
--修改配置
/etc/nginx/default
nginx配置在default
# Multi-Agent & Robotic System (MARS) for Material Science Research
This project is a comprehensive platform for material science research, consisting of a backend API server, a frontend web application, and a middleware desktop application. The platform integrates various AI agents for planning, scientific analysis, engineering tasks, and data analysis to assist in material science research.
## Project Structure
The project is divided into three main components:
#pip install autogen-agentchat[websockets]~=0.2 fastapi uvicorn
1. Backend (Python/FastAPI/Autogen)
2. Frontend (Vue.js)
3. Middleware (C#/WPF)
## Backend
# 完整agent的console版本
matagent_main.py是入口点。
安装requirements.txt里面的pyautogen然后运行即可。
.coding目录不要删除里面包含的是一个配置好的AGENT执行python代码的环境否则会报错。
如果存在问题,检查.coding/pyvenv.cfg文件配置
data目录记录了实验数据PL和UV数据不要删除否则会报错。
The backend is built with Python using the FastAPI framework. It manages the core logic of the multi-agent system, handles WebSocket connections for real-time communication, and provides API endpoints for the frontend.
代码中agent之间的状态流转逻辑通常为每个group的state_transition函数中其中return 'auto'表示自动选择合适的agent。
### Setup and Running
# 简单agent的ui版本
cd ui-simple
chainlit run --port 8989 appUI.py
1. Navigate to the backend directory:
```
cd backend
```
chainlit继承了pyautogen的AssistantAgent在这个基础上实现了chainlit的接口。
class ChainlitAssistantAgent(AssistantAgent):
class ChainlitUserProxyAgent(UserProxyAgent):
同时重载了两个方法以发送数据到前端。
2. Install dependencies (it's recommended to use a virtual environment):
```
pip install -r requirements.txt
```
"""
Wrapper for AutoGens Assistant Agent
"""
def send(
self,
message: Union[Dict, str],
recipient: Agent,
request_reply: Optional[bool] = None,
silent: Optional[bool] = False,
) -> bool:
cl.run_sync(
cl.Message(
content=f'**{self.name}** Sending message to "{recipient.name}":\n\n{message}',
author=self.name,
).send()
)
super(ChainlitAssistantAgent, self).send(
message=message,
recipient=recipient,
request_reply=request_reply,
silent=silent,
)
3. Set up environment variables:
- Copy `.env.example` to `.env`
- Fill in the required API keys and configuration settings
4. Run the backend server:
```
uvicorn api:app --host 0.0.0.0 --port 8000
```
The backend will be available at `http://localhost:8000`.
## Frontend
The frontend is a Vue.js application that provides the user interface for interacting with the multi-agent system.
### Setup and Running
1. Navigate to the frontend directory:
```
cd frontend
```
2. Install dependencies:
```
npm install
```
3. Run the development server:
```
npm run dev
```
4. For production build:
```
npm run build
```
Before building for production, ensure that the following environment variables in the `.env` file are correctly set:
- `VITE_API_URL`: The backend API URL
- `VITE_API_URL_PREFIX`: The API prefix
- `VITE_WB_BASE_URL`: The WebSocket base URL for real-time communication
## Middleware
The middleware is a C# WPF desktop application that provides additional functionality and integration with local systems.
### Setup and Running
1. Open the solution file `middleware/zdhsys.sln` in Visual Studio.
2. Build the solution in Visual Studio.
3. Run the application from Visual Studio or navigate to the build output directory and run the executable.
## Usage
1. Start the backend server.
2. Launch the frontend application (either in development mode or by serving the production build).
3. If required, run the middleware desktop application.
4. Access the web interface through your browser and begin interacting with the multi-agent material science research platform.
## Features
- Real-time communication using WebSockets
- Multi-agent system for complex task planning and execution
- Integration of scientific, engineering, and data analysis teams
- Video streaming capabilities for remote monitoring
- Customizable UI for different aspects of material science research
## Contributing
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
## License
This project is licensed under the MIT License - see the LICENSE.md file for details.

View File

@@ -1,57 +0,0 @@
PlanningAgent: >
You are a planning agent.
Your job is to break down complex Materials science research tasks into smaller, manageable subtasks.
Assign these subtasks to the appropriate sub-teams; not all sub-teams are required to participate in every task.
Your sub-teams are:
1. User: A human agent to whom you transfer information whenever you need to confirm your execution steps to a human.
2. Scientist: A professional team of material scientists who are mainly responsible for consulting on material synthesis, structure, application and properties.
- The scientist team has the following members:
2.1 Synthesis Scientist: who is good at giving perfect and correct synthesis solutions.
2.2 Structure Scientist: focusing on agents of structural topics in materials science.
2.3 Property Scientist: focuses on physical and chemistry property topics in materials science.
2.4 Application Scientist: Focus on practical applications of materials, such as devices, chips, etc.
3. Engineer: A team of professional engineers who are responsible for writing code, visualizing experimental schemes, converting experimental schemes to JSON, and more.
- The engineer team has the following members:
3.1 Structural engineer: A professional structural engineer who focus on converting natural language synthesis schemes to JSON or XML formated scheme, and then upload this JSON to S3 Storage.
3.2 Software engineer: A professional software engineers will coding with Python.
3.3 Code reviewer: A professional code reviewer will review the code written by software engineers and execute it.
3.4 Scheme Plotter: An agent responsible for converting a expriment scheme into a Mermaid flowchart.
4. Executor: A robotic platform is responsible for performing automated synthesis experiments, automated characterization experiments, and collecting experimental datas.
- The Executor team has the following members:
4.1 MobileRobot_Agent: This agent controls the mobile robot by calling the funciton sendScheme2MobileRobot to place the experimental container into the robot workstation. This agent called before RobotWorkstation_Agent.
4.2 RobotWorkstation_Agent: This agent is called by the mobile robot agent, do not plan it alone.
4.3 DataCollector_Agent: This agent collects experimental data and experimental logs from the characterization device in the robot platform and stores them.
5. Analyst: A team of data analysts who are responsible for analyzing and visualizing experimental data and logs.
- The Data Analysis team has the following members:
5.1 Expriment_Analyst: The agent of data analysts who are responsible for analyzing experimental data and logs.
5.2 Expriment_Optimizer: The agent optimizes the experimental scheme by means of component regulation and so on to make the experimental result close to the desired goal of the user.
5.3 Data_Visulizer: The agent of data visulizers who are responsible for visualizing experimental data and logs.
You only plan and delegate tasks - you do not execute them yourself.
回答时你需要初始化/更新如下任务分配表和Mermaid流程图并按顺序执行使用如下格式并利用
| Team_name | Member_name | sub-task |
| ----------- | ------------- | ------------------------------------ |
| <team_name> | <member_name> | <status: brief sub-task description> |
```mermaid
graph TD
User[User]
subgraph <team_name>
A1[<member_name>]
end
style xxx # 推荐多样的风格
...
User --> A1
...
```
每次回答时,你需要清晰明确的指出已经完成的子任务下一步子任务,使用如下格式:
**已完成子任务:**
1. <team> : <subtask>
**Next sub-task:**
n. <team> : <subtask>
You can end with "HUMAN" if you need to, which means you need human approval or other advice or instructions;
After plan and delegate tasks are complete, end with "START";
Determine if all sub-teams have completed their tasks, and if so, summarize the findings and end with "TERMINATE".

View File

@@ -0,0 +1 @@
{"splits": ["train"]}

View File

@@ -0,0 +1,58 @@
{
"citation": "",
"description": "",
"features": {
"context": {
"dtype": "string",
"_type": "Value"
},
"question": {
"dtype": "string",
"_type": "Value"
},
"answer": {
"dtype": "string",
"_type": "Value"
},
"topic": {
"dtype": "string",
"_type": "Value"
},
"source_doc": {
"dataset_id": {
"dtype": "string",
"_type": "Value"
},
"document_id": {
"dtype": "string",
"_type": "Value"
}
},
"groundedness_score": {
"dtype": "float64",
"_type": "Value"
},
"groundedness_eval": {
"dtype": "string",
"_type": "Value"
},
"relevance_score": {
"dtype": "float64",
"_type": "Value"
},
"relevance_eval": {
"dtype": "string",
"_type": "Value"
},
"standalone_score": {
"dtype": "float64",
"_type": "Value"
},
"standalone_eval": {
"dtype": "string",
"_type": "Value"
}
},
"homepage": "",
"license": ""
}

View File

@@ -0,0 +1,13 @@
{
"_data_files": [
{
"filename": "data-00000-of-00001.arrow"
}
],
"_fingerprint": "0748dad1d6b34503",
"_format_columns": null,
"_format_kwargs": {},
"_format_type": null,
"_output_all_columns": false,
"_split": "train"
}

View File

@@ -0,0 +1,30 @@
{
"citation": "",
"description": "",
"features": {
"context": {
"dtype": "string",
"_type": "Value"
},
"question": {
"dtype": "string",
"_type": "Value"
},
"answer": {
"dtype": "string",
"_type": "Value"
},
"source_doc": {
"dataset_id": {
"dtype": "string",
"_type": "Value"
},
"document_id": {
"dtype": "string",
"_type": "Value"
}
}
},
"homepage": "",
"license": ""
}

View File

@@ -0,0 +1,13 @@
{
"_data_files": [
{
"filename": "data-00000-of-00001.arrow"
}
],
"_fingerprint": "bcd109aa52b21899",
"_format_columns": null,
"_format_kwargs": {},
"_format_type": null,
"_output_all_columns": false,
"_split": null
}

View File

@@ -1,41 +0,0 @@
{
"server": {
"debug": true,
"log_level": "info",
"http_demo": true,
"http_debug": false,
"http_login": "demo",
"http_password": "demo",
"http_port": ":8083",
"ice_servers": [
"stun:stun.xten.com:3478"
],
"rtsp_port": ":5541"
},
"streams": {
"demo1": {
"name": "test video stream 1",
"channels": {
"0": {
"name": "ch1",
"url": "rtsp://admin:@192.168.1.13:554/live",
"on_demand": true,
"debug": true,
"audio": true,
"status": 0
},
"1": {
"name": "ch2",
"url": "rtsp://admin:@192.168.1.10:554/live",
"on_demand": true,
"debug": true,
"audio": true,
"status": 0
}
}
}
},
"channel_defaults": {
"on_demand": true
}
}

View File

@@ -372,55 +372,6 @@ def upload_to_s3(json_data: str):
# print(f"JSON解析错误: {e}")
return f"Error: {str(e)}, Request human/user intervention."
def get_latest_exp_log():
def get_uv_latest_file():
import os
import glob
# UV数据缓存文件夹路径 (请将此路径修改为实际的文件夹路径)
current_folder = os.path.dirname(os.path.abspath(__file__))
folder_path = os.path.join(current_folder, 'data/UV/')
# 查找文件夹中的所有 .wls 文件
uv_files = sorted(glob.glob(os.path.join(folder_path, '*.[Tt][Xx][Tt]')))
if not uv_files:
res = f"ERROR: 缓存文件夹{current_folder}中没有找到任何UV文件"
return res
# 找到最新修改的文件
latest_file = uv_files[-1]
res = f"找到最新的UV数据文件: {latest_file}"
return res
def get_pl_latest_file():
import os
import glob
current_folder = os.path.dirname(os.path.abspath(__file__))
folder_path = os.path.join(current_folder, 'data/PL/')
# 查找文件夹中的所有 .txt 或 .TXT 文件
pl_files = sorted(glob.glob(os.path.join(folder_path, '*.[Tt][Xx][Tt]')))
if not pl_files:
res = f"ERROR: 缓存文件夹{current_folder}中没有找到任何PL文件"
return res
# 找到最新修改的文件
latest_file = pl_files[-1]
res = f"找到最新的PL数据文件: {latest_file}"
return res
pl_latest = get_pl_latest_file()
uv_latest = get_uv_latest_file()
return pl_latest + "\n" + uv_latest
def read_data():
get_latest_exp_log()
def default_func():
return "Approved. Proceed as planned!"

View File

@@ -1,22 +0,0 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()

6
package-lock.json generated
View File

@@ -1,6 +0,0 @@
{
"name": "matagent",
"lockfileVersion": 3,
"requires": true,
"packages": {}
}