169 lines
6.1 KiB
Markdown
169 lines
6.1 KiB
Markdown
# AISE AI Code Editor
|
|
|
|
AI-Supported Lightweight Code Editor built with Streamlit (AISE501 Spring 2026)
|
|
|
|
## Projektstruktur
|
|
|
|
```
|
|
AISE_AIAgent/
|
|
├── frontend/ # Streamlit UI-Komponenten
|
|
│ ├── app.py # Haupteinstiegspunkt der Streamlit-App
|
|
│ ├── state.py # Session-State-Verwaltung
|
|
│ ├── sidebar.py # Datei-Navigation (Sidebar)
|
|
│ ├── editor.py # Code-Editor-Pane
|
|
│ └── chat.py # Chat-Interface
|
|
│
|
|
├── backend/ # Backend-Logik
|
|
│ ├── managers/ # Business-Logik für UI-Operationen
|
|
│ │ ├── file_manager.py # Datei-CRUD (lesen, schreiben, listen)
|
|
│ │ ├── chat_manager.py # AI-Chat-Verwaltung und -History
|
|
│ │ ├── system_prompter.py # System-Prompts und Kontext-Injektion
|
|
│ │ ├── search_manager.py # Web-Suche (DuckDuckGo)
|
|
│ │ ├── execution_engine.py # Code-Ausführung und Sandboxing
|
|
│ │ └── debug_logger.py # Logging, Fehlerbehandlung, Debug-Ausgaben
|
|
│ │
|
|
│ └── agent/ # Autonomes AI-Agent-System (MCP-basiert)
|
|
│ ├── coding_agent.py # Haupt-Agent-Loop (Plan-Act-Observe)
|
|
│ ├── mcp_server_adapter.py # MCP-Adapter: verbindet Agent mit MCP-Servern
|
|
│ ├── mcp_server_adapter_RAG.py # MCP-Adapter mit RAG-basierter Tool-Auswahl
|
|
│ ├── mcp_server_config.json # Konfiguration der MCP-Server (Startbefehle)
|
|
│ └── servers/ # MCP-Server-Implementierungen
|
|
│ ├── mcp_server_code_execution.py # Tool: Python-Code ausführen
|
|
│ ├── mcp_server_file_search.py # Tool: Dateien suchen und lesen
|
|
│ └── mcp_server_web_search.py # Tool: Web-Suche via DuckDuckGo
|
|
│
|
|
├── tests/ # Unit-Tests (pytest)
|
|
│ ├── conftest.py # Globale Test-Fixtures und MCP-Mocks
|
|
│ ├── test_file_manager.py
|
|
│ ├── test_chat_manager.py
|
|
│ ├── test_execution_engine.py
|
|
│ ├── test_coding_agent.py
|
|
│ ├── test_debug_logger.py
|
|
│ ├── test_system_prompter.py
|
|
│ ├── test_mcp_server_code_execution.py
|
|
│ ├── test_mcp_server_file_search.py
|
|
│ └── test_mcp_server_web_search.py
|
|
│
|
|
├── workspace/ # Agent-Sandbox (isoliertes Arbeitsverzeichnis)
|
|
├── run_agent.py # CLI-Einstiegspunkt für den Coding-Agent
|
|
└── .env.example # Vorlage für Umgebungsvariablen
|
|
```
|
|
|
|
## Komponenten
|
|
|
|
### Frontend (`frontend/`)
|
|
- **app.py**: Streamlit-Applikation, Layout-Orchestrierung
|
|
- **state.py**: Zentralisierte Session-State-Verwaltung
|
|
- **sidebar.py**: Datei-Browser und Projekt-Navigation
|
|
- **editor.py**: Code-Editor mit Syntax-Highlighting
|
|
- **chat.py**: AI-Assistent Chat-Interface
|
|
|
|
### Backend Manager (`backend/managers/`)
|
|
Werden direkt vom Frontend für UI-Operationen genutzt:
|
|
- **file_manager.py**: CRUD-Operationen auf Projektdateien
|
|
- **chat_manager.py**: Chat-History, Nachrichten-Verwaltung
|
|
- **system_prompter.py**: System-Prompt-Generierung und Datei-Kontext
|
|
- **execution_engine.py**: Sichere Code-Ausführung mit Output-Capture
|
|
- **debug_logger.py**: Fehler-Tracking und Log-Formatierung
|
|
- **search_manager.py**: Web-Suche via DuckDuckGo (`ddgs`-Bibliothek)
|
|
|
|
### Backend Agent (`backend/agent/`)
|
|
Autonomes AI-Agent-System für komplexe Coding-Aufgaben:
|
|
- **coding_agent.py**: Agent-Loop (Plan → Act → Observe → Wiederholen)
|
|
- **mcp_server_adapter.py**: Verbindet den Agent mit MCP-Servern via Konfigurationsdatei
|
|
- **mcp_server_adapter_RAG.py**: Erweiterter Adapter mit semantischer Tool-Auswahl (RAG)
|
|
- **mcp_server_config.json**: Definiert welche MCP-Server gestartet werden und mit welchen Argumenten
|
|
- **servers/**: Die eigentlichen MCP-Tool-Server (Code-Ausführung, Datei-Suche, Web-Suche)
|
|
|
|
### Workspace (`workspace/`)
|
|
- Sandbox-Verzeichnis, in dem der Agent Dateien erstellt und ausführt
|
|
- Verhindert, dass der Agent auf Dateien ausserhalb dieses Verzeichnisses zugreift
|
|
|
|
## Features
|
|
|
|
- **Datei-Verwaltung**: Dateien im Workspace durchsuchen und bearbeiten
|
|
- **Chat-Interface**: KI-gestützter Code-Assistent
|
|
- **Code-Ausführung**: Python-Code sicher ausführen mit Debug-Output
|
|
- **Web-Suche**: Dokumentation und Beispiele via DuckDuckGo abrufen
|
|
- **Autonomer Agent**: MCP-basierter Coding-Agent mit Plan-Act-Observe-Loop
|
|
- **RAG Tool-Auswahl**: Semantische Tool-Selektion via Sentence Transformers
|
|
|
|
## Setup
|
|
|
|
### 1. Repository klonen
|
|
|
|
```bash
|
|
git clone https://gitea.fhgr.ch/meulilivio/AISE1_Project.git
|
|
cd AISE1_Project
|
|
```
|
|
|
|
### 2. Virtuelle Umgebung aktivieren
|
|
|
|
```bash
|
|
# Windows
|
|
.\.venv\Scripts\Activate.ps1
|
|
|
|
# macOS/Linux
|
|
source .venv/bin/activate
|
|
```
|
|
|
|
### 3. Abhängigkeiten installieren
|
|
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
### 4. Umgebungsvariablen konfigurieren
|
|
|
|
```bash
|
|
cp .env.example .env
|
|
# .env mit API-Keys befüllen
|
|
```
|
|
|
|
### 5. Applikation starten
|
|
|
|
```bash
|
|
streamlit run frontend/app.py
|
|
```
|
|
|
|
### 6. Tests ausführen
|
|
|
|
```bash
|
|
pytest tests/ -v
|
|
```
|
|
|
|
## Konfiguration: `mcp_server_config.json`
|
|
|
|
Die Datei `backend/agent/mcp_server_config.json` definiert, welche MCP-Server der Agent starten soll. Jeder Eintrag enthält den Servernamen, den Startbefehl (`command`) und optionale Argumente (`args`) sowie Umgebungsvariablen (`env`):
|
|
|
|
```json
|
|
{
|
|
"FileSearchServer": {
|
|
"command": "py",
|
|
"args": ["servers/mcp_server_file_search.py"]
|
|
},
|
|
"WebSearchServer": {
|
|
"command": "py",
|
|
"args": ["servers/mcp_server_web_search.py"],
|
|
"env": { "DDGS_API_KEY": "your_key_here" }
|
|
}
|
|
}
|
|
```
|
|
|
|
## Architektur
|
|
|
|
```
|
|
Frontend (Streamlit) ──► Backend Manager ──► AI API
|
|
│
|
|
└──► Coding Agent ──► MCP-Adapter ──► MCP-Server
|
|
(Code / File / Web)
|
|
```
|
|
|
|
## Entwicklung
|
|
|
|
```bash
|
|
git add .
|
|
git commit -m "Deine Nachricht"
|
|
git push origin main
|
|
```
|