fixes
This commit is contained in:
parent
7184192621
commit
70409874ef
6 changed files with 250 additions and 3 deletions
4
gwserver/_database_gateway/_system.json
Normal file
4
gwserver/_database_gateway/_system.json
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"mandates": 1,
|
||||||
|
"users": 1
|
||||||
|
}
|
||||||
|
|
@ -12,5 +12,12 @@
|
||||||
"language": "de",
|
"language": "de",
|
||||||
"mandate_id": 1,
|
"mandate_id": 1,
|
||||||
"user_id": 1
|
"user_id": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Root",
|
||||||
|
"language": "de",
|
||||||
|
"mandate_id": 0,
|
||||||
|
"user_id": 0,
|
||||||
|
"id": 3
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
@ -22,5 +22,17 @@
|
||||||
"privilege": "user",
|
"privilege": "user",
|
||||||
"hashed_password": "$argon2id$v=19$m=65536,t=3,p=4$3fufM+bc+19r7V3rvVfKmQ$CrJCc6r44jO4DxMHs8E61ayupBeUi6a+65VH0Q1cGo8",
|
"hashed_password": "$argon2id$v=19$m=65536,t=3,p=4$3fufM+bc+19r7V3rvVfKmQ$CrJCc6r44jO4DxMHs8E61ayupBeUi6a+65VH0Q1cGo8",
|
||||||
"user_id": 2
|
"user_id": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"mandate_id": 3,
|
||||||
|
"username": "admin",
|
||||||
|
"email": "admin@example.com",
|
||||||
|
"full_name": "Administrator",
|
||||||
|
"disabled": false,
|
||||||
|
"language": "de",
|
||||||
|
"privilege": "sysadmin",
|
||||||
|
"hashed_password": "$argon2id$v=19$m=65536,t=3,p=4$yzknRMi5V0qJMaaUsvaecw$2snq8pSq60BulTAOib7gtJKaT/AlO62uhncau2g3RZQ",
|
||||||
|
"user_id": 0,
|
||||||
|
"id": 3
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
3
gwserver/_database_lucydom/_system.json
Normal file
3
gwserver/_database_lucydom/_system.json
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"workspaces": 1
|
||||||
|
}
|
||||||
|
|
@ -14,7 +14,7 @@ import pathlib
|
||||||
# Import interfaces
|
# Import interfaces
|
||||||
from modules.gateway_interface import get_gateway_interface
|
from modules.gateway_interface import get_gateway_interface
|
||||||
from modules.lucydom_interface import get_lucydom_interface
|
from modules.lucydom_interface import get_lucydom_interface
|
||||||
from modules.agentservice_interface import get_agentservice_interface
|
from modules.agentservice_interface import AgentService
|
||||||
|
|
||||||
# Import auth module
|
# Import auth module
|
||||||
from auth import (
|
from auth import (
|
||||||
|
|
@ -68,7 +68,7 @@ async def root():
|
||||||
|
|
||||||
@app.get("/api/test", tags=["General"])
|
@app.get("/api/test", tags=["General"])
|
||||||
async def get_test():
|
async def get_test():
|
||||||
return "OK 1.1"
|
return "OK 1.2"
|
||||||
|
|
||||||
@app.options("/{full_path:path}", tags=["General"])
|
@app.options("/{full_path:path}", tags=["General"])
|
||||||
async def options_route(full_path: str):
|
async def options_route(full_path: str):
|
||||||
|
|
|
||||||
|
|
@ -529,3 +529,224 @@ class AgentService:
|
||||||
self._save_workflow_results(workflow_id)
|
self._save_workflow_results(workflow_id)
|
||||||
|
|
||||||
return workflow_id
|
return workflow_id
|
||||||
|
|
||||||
|
def _get_agent_instructions(self, agent_type: str) -> str:
|
||||||
|
"""
|
||||||
|
Gibt agententypspezifische Anweisungen zurück, die aus der agents.json geladen werden.
|
||||||
|
Falls die Datei nicht existiert oder der Agententyp nicht gefunden wird,
|
||||||
|
wird ein Standardagent zurückgegeben.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
# Pfad zur agents.json-Datei
|
||||||
|
agents_file = os.path.join(os.path.dirname(__file__), 'data', 'agents.json')
|
||||||
|
|
||||||
|
# Überprüfen, ob die Datei existiert
|
||||||
|
if not os.path.exists(agents_file):
|
||||||
|
logger.warning(f"Agents-Definitionen nicht gefunden: {agents_file}")
|
||||||
|
return self._get_default_agent_instructions()
|
||||||
|
|
||||||
|
# Datei lesen
|
||||||
|
with open(agents_file, 'r', encoding='utf-8') as f:
|
||||||
|
agents_data = json.load(f)
|
||||||
|
|
||||||
|
# Nach dem Agententyp suchen
|
||||||
|
for agent in agents_data:
|
||||||
|
if agent.get("type") == agent_type:
|
||||||
|
# Anweisungen zurückgeben, wenn vorhanden
|
||||||
|
instructions = agent.get("instructions")
|
||||||
|
if instructions:
|
||||||
|
logger.debug(f"Anweisungen für Agent-Typ '{agent_type}' aus agents.json geladen")
|
||||||
|
return instructions
|
||||||
|
|
||||||
|
# Wenn kein passender Agent gefunden wurde, Standardanweisungen verwenden
|
||||||
|
logger.warning(f"Keine Anweisungen für Agent-Typ '{agent_type}' in agents.json gefunden")
|
||||||
|
return self._get_default_agent_instructions()
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Fehler beim Laden der Agent-Anweisungen aus agents.json: {e}")
|
||||||
|
return self._get_default_agent_instructions()
|
||||||
|
|
||||||
|
def _get_default_agent_instructions(self) -> str:
|
||||||
|
"""
|
||||||
|
Gibt Standard-Anweisungen für einen Agenten zurück,
|
||||||
|
wenn keine spezifischen Anweisungen in der agents.json gefunden wurden.
|
||||||
|
Diese Funktion gibt generische Anweisungen zurück, unabhängig vom Agententyp.
|
||||||
|
"""
|
||||||
|
return """
|
||||||
|
Als Agent ist es deine Aufgabe, Anfragen zu analysieren und entsprechend deinen Fähigkeiten zu bearbeiten.
|
||||||
|
|
||||||
|
Folge diesen allgemeinen Anweisungen:
|
||||||
|
1. Verstehe die Anfrage gründlich
|
||||||
|
2. Analysiere relevante Daten und Informationen
|
||||||
|
3. Liefere präzise und hilfreiche Antworten
|
||||||
|
4. Strukturiere deine Antwort klar und verständlich
|
||||||
|
|
||||||
|
In deiner Antwort:
|
||||||
|
- Beginne mit einer Zusammenfassung der Anfrage
|
||||||
|
- Gib gut begründete Antworten oder Empfehlungen
|
||||||
|
- Führe wichtige Erkenntnisse klar auf
|
||||||
|
- Schließe mit konkreten nächsten Schritten oder Empfehlungen ab
|
||||||
|
"""
|
||||||
|
|
||||||
|
def _add_log(
|
||||||
|
self,
|
||||||
|
workflow_id: str,
|
||||||
|
message: str,
|
||||||
|
log_type: str,
|
||||||
|
agent_id: Optional[str] = None,
|
||||||
|
agent_name: Optional[str] = None
|
||||||
|
) -> None:
|
||||||
|
"""Fügt einen Protokolleintrag zum Workflow hinzu"""
|
||||||
|
log_entry = {
|
||||||
|
"id": f"log_{uuid.uuid4()}",
|
||||||
|
"mandate_id": self.mandate_id,
|
||||||
|
"user_id": self.user_id,
|
||||||
|
"message": message,
|
||||||
|
"type": log_type,
|
||||||
|
"timestamp": datetime.now().isoformat(),
|
||||||
|
"agent_id": agent_id,
|
||||||
|
"agent_name": agent_name
|
||||||
|
}
|
||||||
|
|
||||||
|
workflow = self.workflows.get(workflow_id)
|
||||||
|
if workflow:
|
||||||
|
workflow["logs"].append(log_entry)
|
||||||
|
logger.info(f"Workflow {workflow_id}: {message}")
|
||||||
|
|
||||||
|
def _create_agent_result(
|
||||||
|
self,
|
||||||
|
workflow_id: str,
|
||||||
|
agent: Dict[str, Any],
|
||||||
|
index: int,
|
||||||
|
prompt: str,
|
||||||
|
file_contexts: List[Dict[str, Any]],
|
||||||
|
content: str
|
||||||
|
) -> Dict[str, Any]:
|
||||||
|
"""Erstellt ein Ergebnisobjekt basierend auf dem Agententyp und der API-Antwort"""
|
||||||
|
agent_type = agent["type"]
|
||||||
|
agent_id = agent["id"]
|
||||||
|
agent_name = agent["name"]
|
||||||
|
|
||||||
|
# Grundlegende Ergebnisstruktur
|
||||||
|
result = {
|
||||||
|
"id": f"result_{workflow_id}_{index}",
|
||||||
|
"mandate_id": self.mandate_id,
|
||||||
|
"user_id": self.user_id,
|
||||||
|
"agent_id": agent_id,
|
||||||
|
"agent_name": agent_name,
|
||||||
|
"timestamp": datetime.now().isoformat(),
|
||||||
|
"type": "text", # Standardtyp
|
||||||
|
"metadata": {
|
||||||
|
"files_processed": [file["name"] for file in file_contexts],
|
||||||
|
"prompt": prompt
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Titel und Inhalt basierend auf dem Agententyp anpassen
|
||||||
|
if agent_type == "analyzer":
|
||||||
|
result.update({
|
||||||
|
"title": "Datenanalyse-Ergebnis",
|
||||||
|
"content": content,
|
||||||
|
})
|
||||||
|
elif agent_type == "visualizer":
|
||||||
|
result.update({
|
||||||
|
"title": "Visualisierungsvorschlag",
|
||||||
|
"content": content,
|
||||||
|
"type": "chart" # Auch wenn kein echtes Diagramm, markieren wir es als solches
|
||||||
|
})
|
||||||
|
elif agent_type == "writer":
|
||||||
|
result.update({
|
||||||
|
"title": "Zusammenfassung und Empfehlungen",
|
||||||
|
"content": content,
|
||||||
|
})
|
||||||
|
elif agent_type == "scraper":
|
||||||
|
result.update({
|
||||||
|
"title": "Web-Recherche Ergebnisse",
|
||||||
|
"content": content,
|
||||||
|
})
|
||||||
|
elif agent_type == "initialisierung":
|
||||||
|
result.update({
|
||||||
|
"title": "Direkte Antwort",
|
||||||
|
"content": content,
|
||||||
|
})
|
||||||
|
elif agent_type == "organisator":
|
||||||
|
result.update({
|
||||||
|
"title": "Aufgabenstrukturierung",
|
||||||
|
"content": content,
|
||||||
|
})
|
||||||
|
elif agent_type == "entwickler":
|
||||||
|
result.update({
|
||||||
|
"title": "Code und Ausführungsergebnisse",
|
||||||
|
"content": content,
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
result.update({
|
||||||
|
"title": f"Ergebnis von {agent_name}",
|
||||||
|
"content": content,
|
||||||
|
})
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
def _save_workflow_results(self, workflow_id: str) -> None:
|
||||||
|
"""Speichert die Workflow-Ergebnisse in einer Datei"""
|
||||||
|
workflow = self.workflows.get(workflow_id)
|
||||||
|
if workflow:
|
||||||
|
try:
|
||||||
|
file_path = os.path.join(self.results_dir, f"workflow_{workflow_id}.json")
|
||||||
|
with open(file_path, 'w', encoding='utf-8') as f:
|
||||||
|
json.dump(workflow, f, indent=2, ensure_ascii=False)
|
||||||
|
logger.info(f"Workflow-Ergebnisse gespeichert: {file_path}")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Fehler beim Speichern der Workflow-Ergebnisse: {e}")
|
||||||
|
|
||||||
|
def get_workflow_status(self, workflow_id: str) -> Optional[Dict[str, Any]]:
|
||||||
|
"""Gibt den Status eines Workflows zurück"""
|
||||||
|
workflow = self.workflows.get(workflow_id)
|
||||||
|
if not workflow:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return {
|
||||||
|
"id": workflow["id"],
|
||||||
|
"mandate_id": workflow.get("mandate_id"),
|
||||||
|
"user_id": workflow.get("user_id"),
|
||||||
|
"status": workflow["status"],
|
||||||
|
"progress": workflow["progress"],
|
||||||
|
"started_at": workflow["started_at"],
|
||||||
|
"completed_at": workflow["completed_at"],
|
||||||
|
"agent_statuses": workflow["agent_statuses"]
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_workflow_logs(self, workflow_id: str) -> Optional[List[Dict[str, Any]]]:
|
||||||
|
"""Gibt die Protokolle eines Workflows zurück"""
|
||||||
|
workflow = self.workflows.get(workflow_id)
|
||||||
|
if not workflow:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return workflow["logs"]
|
||||||
|
|
||||||
|
def get_workflow_results(self, workflow_id: str) -> Optional[List[Dict[str, Any]]]:
|
||||||
|
"""Gibt die Ergebnisse eines Workflows zurück"""
|
||||||
|
workflow = self.workflows.get(workflow_id)
|
||||||
|
if not workflow:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return workflow["results"]
|
||||||
|
|
||||||
|
async def close(self):
|
||||||
|
"""Schließt die HTTP-Clients beim Beenden der Anwendung"""
|
||||||
|
await self.service_aichat.close()
|
||||||
|
await self.service_aiscrap.close()
|
||||||
|
|
||||||
|
|
||||||
|
# Singleton-Factory für AgentService-Instanzen pro Kontext
|
||||||
|
_agent_service_instances = {}
|
||||||
|
|
||||||
|
def get_agentservice_interface(mandate_id: int = None, user_id: int = None) -> AgentService:
|
||||||
|
"""
|
||||||
|
Gibt eine AgentService-Instanz für den angegebenen Kontext zurück.
|
||||||
|
Wiederverwendet bestehende Instanzen.
|
||||||
|
"""
|
||||||
|
context_key = f"{mandate_id}_{user_id}"
|
||||||
|
if context_key not in _agent_service_instances:
|
||||||
|
_agent_service_instances[context_key] = AgentService(mandate_id, user_id)
|
||||||
|
return _agent_service_instances[context_key]
|
||||||
Loading…
Reference in a new issue