feat: Enhanced Orchestrator Chat with notifications and better UX

- Add task creation notifications in Orchestrator Chat
- New messages appear at top (newest first)
- Add Clear Chat button with confirmation
- Improve timestamps: DD.MM.YYYY HH:MM:SS format
- Support for system notifications (task created, sub-agent responses)
- Add add_orchestrator_notification() helper function
- Auto-notify when agents create sub-tasks
- Clear Chat route: POST /orchestrator/clear
- Better visual distinction between messages and notifications
This commit is contained in:
pdyde 2026-02-21 18:02:01 +01:00
parent 98ff812a82
commit 7ee66397e1
2 changed files with 94 additions and 13 deletions

44
app.py
View file

@ -686,6 +686,25 @@ def get_tasks(status=None, limit=None):
return [dict(row) for row in rows]
def add_orchestrator_notification(message_type, message, agent_key=None):
"""Fügt eine System-Benachrichtigung zum Orchestrator-Chat hinzu."""
try:
if 'orchestrator_chat' not in session:
session['orchestrator_chat'] = []
session['orchestrator_chat'].insert(0, { # Insert at top (newest first)
'timestamp': datetime.now().strftime('%d.%m.%Y %H:%M:%S'),
'type': message_type,
'message': message,
'agent': AGENTS.get(agent_key, {}).get('name', agent_key) if agent_key else 'System',
'agent_key': agent_key,
'is_notification': True
})
session['orchestrator_chat'] = session['orchestrator_chat'][:50] # Keep last 50
session.modified = True
except:
pass # Session might not be available in background threads
def create_task(title, description, agent_key='orchestrator', task_type='manual', created_by='user', **kwargs):
"""Erstellt einen neuen Task in der Datenbank."""
con = sqlite3.connect(EMAIL_JOURNAL_DB)
@ -709,6 +728,15 @@ def create_task(title, description, agent_key='orchestrator', task_type='manual'
con.close()
logging.info(f"[DB] Task #{task_id} erstellt: {title[:50]}")
# Orchestrator-Notification hinzufügen
if created_by != 'user': # Nur bei Agent-erstellten Tasks
add_orchestrator_notification(
'task_created',
f'📋 Task #{task_id} erstellt: {title}',
agent_key=created_by
)
return task_id
@ -2432,14 +2460,15 @@ def orchestrator():
response = execute_agent_task(selected_agent, prompt)
orchestrator_chat = session.get('orchestrator_chat', [])
orchestrator_chat.append({
'timestamp': datetime.now().strftime('%Y-%m-%d %H:%M'),
orchestrator_chat.insert(0, { # Insert at top (newest first)
'timestamp': datetime.now().strftime('%d.%m.%Y %H:%M:%S'),
'user_prompt': prompt,
'agent': agent_name,
'agent_key': selected_agent,
'response': response
'response': response,
'is_notification': False
})
session['orchestrator_chat'] = orchestrator_chat[-30:]
session['orchestrator_chat'] = orchestrator_chat[:30] # Keep first 30
chat_display = session.get('orchestrator_chat', [])
return render_template('orchestrator.html',
@ -2447,6 +2476,13 @@ def orchestrator():
chat_history=chat_display,
knowledge_loaded=bool(session.get('orchestrator_kb')))
@app.route('/orchestrator/clear', methods=['POST'])
def orchestrator_clear():
"""Löscht den Orchestrator Chat-Verlauf."""
session['orchestrator_chat'] = []
session.modified = True
return jsonify({'success': True})
@app.route('/agents', methods=['GET', 'POST'])
def agents():
agents_dir = os.path.join(os.path.dirname(__file__), 'agents')