feat: Log all agent actions (@SEND_EMAIL, @SEND_TELEGRAM, @ADD/UPDATE_TEAM_MEMBER) as tasks

Every parsed agent command now creates a task entry with type action_email /
action_telegram / action_team, parent_task_id pointing to the originating task,
and status completed/error reflecting the actual outcome.

Tasks UI gets matching badges for all new types plus a parent-task indicator
(↳ #N) so the full chain from trigger to action is visible at a glance.
This commit is contained in:
eric 2026-02-21 19:06:33 +00:00
parent f13860f38d
commit d3800ac792
2 changed files with 69 additions and 10 deletions

56
app.py
View file

@ -1096,12 +1096,22 @@ Bitte entscheide ob dieser Agent erstellt werden soll.""",
subject_clean = subject.strip() subject_clean = subject.strip()
body_clean = body.strip() body_clean = body.strip()
# Versuche Email zu senden action_task_id = create_task(
title=f"Email an {to_clean}: {subject_clean[:60]}",
description=f"**An:** {to_clean}\n**Betreff:** {subject_clean}\n\n{body_clean}",
agent_key=agent_key,
task_type='action_email',
created_by=agent_key,
parent_task_id=task_id,
)
success, message = send_email(to_clean, subject_clean, body_clean, success, message = send_email(to_clean, subject_clean, body_clean,
triggered_by=f'agent:{agent_key}', task_id=task_id) triggered_by=f'agent:{agent_key}', task_id=action_task_id)
if success: if success:
update_task_db(action_task_id, status='completed',
response=f"✓ Email erfolgreich versendet an {to_clean}")
logger.info(f"[AgentCmd] Email gesendet an {to_clean}: {subject_clean}") logger.info(f"[AgentCmd] Email gesendet an {to_clean}: {subject_clean}")
else: else:
update_task_db(action_task_id, status='error', response=f"✗ Fehler: {message}")
logger.error(f"[AgentCmd] Email-Fehler: {message}") logger.error(f"[AgentCmd] Email-Fehler: {message}")
# SEND_TELEGRAM: Orchestrator sendet Telegram-Nachricht # SEND_TELEGRAM: Orchestrator sendet Telegram-Nachricht
@ -1115,10 +1125,17 @@ Bitte entscheide ob dieser Agent erstellt werden soll.""",
recipient_clean = recipient.strip() recipient_clean = recipient.strip()
message_clean = message.strip() message_clean = message.strip()
# Telegram-Integration (wenn aktiviert) action_task_id = create_task(
title=f"Telegram an {recipient_clean}: {message_clean[:60]}",
description=f"**An:** {recipient_clean}\n\n{message_clean}",
agent_key=agent_key,
task_type='action_telegram',
created_by=agent_key,
parent_task_id=task_id,
)
if TELEGRAM_CONFIG.get('bot_token') and TELEGRAM_CONFIG.get('telegram_bot'): if TELEGRAM_CONFIG.get('bot_token') and TELEGRAM_CONFIG.get('telegram_bot'):
try: try:
# Direkte numerische ID oder Name/Email → DB-Lookup
chat_id = None chat_id = None
if recipient_clean.lstrip('-').isdigit(): if recipient_clean.lstrip('-').isdigit():
chat_id = int(recipient_clean) chat_id = int(recipient_clean)
@ -1134,12 +1151,18 @@ Bitte entscheide ob dieser Agent erstellt werden soll.""",
if chat_id: if chat_id:
send_telegram_message(chat_id, message_clean) send_telegram_message(chat_id, message_clean)
update_task_db(action_task_id, status='completed',
response=f"✓ Telegram gesendet an {recipient_clean} (chat_id={chat_id})")
logger.info(f"[AgentCmd] Telegram gesendet an {recipient_clean} (chat_id={chat_id})") logger.info(f"[AgentCmd] Telegram gesendet an {recipient_clean} (chat_id={chat_id})")
else: else:
update_task_db(action_task_id, status='error',
response=f"✗ Keine Telegram-ID für '{recipient_clean}' gefunden")
logger.warning(f"[AgentCmd] Keine Telegram Chat-ID für '{recipient_clean}'") logger.warning(f"[AgentCmd] Keine Telegram Chat-ID für '{recipient_clean}'")
except Exception as e: except Exception as e:
update_task_db(action_task_id, status='error', response=f"✗ Fehler: {str(e)}")
logger.error(f"[AgentCmd] Telegram-Fehler: {str(e)}") logger.error(f"[AgentCmd] Telegram-Fehler: {str(e)}")
else: else:
update_task_db(action_task_id, status='error', response="✗ Telegram nicht konfiguriert")
logger.warning("[AgentCmd] Telegram nicht konfiguriert") logger.warning("[AgentCmd] Telegram nicht konfiguriert")
# ADD_TEAM_MEMBER: Füge neues Team-Mitglied hinzu # ADD_TEAM_MEMBER: Füge neues Team-Mitglied hinzu
@ -1155,10 +1178,22 @@ Bitte entscheide ob dieser Agent erstellt werden soll.""",
resp_clean = resp.strip() resp_clean = resp.strip()
email_clean = email.strip() email_clean = email.strip()
action_task_id = create_task(
title=f"Team-Member hinzugefügt: {name_clean}",
description=f"**Name:** {name_clean}\n**Rolle:** {role_clean}\n**Email:** {email_clean}\n**Verantwortlichkeiten:** {resp_clean}",
agent_key=agent_key,
task_type='action_team',
created_by=agent_key,
parent_task_id=task_id,
)
success = add_team_member(name_clean, role_clean, resp_clean, email_clean) success = add_team_member(name_clean, role_clean, resp_clean, email_clean)
if success: if success:
update_task_db(action_task_id, status='completed',
response=f"✓ Team-Member '{name_clean}' ({role_clean}) hinzugefügt")
logger.info(f"[AgentCmd] Team-Member hinzugefügt: {name_clean} ({role_clean})") logger.info(f"[AgentCmd] Team-Member hinzugefügt: {name_clean} ({role_clean})")
else: else:
update_task_db(action_task_id, status='error',
response=f"✗ Konnte '{name_clean}' nicht hinzufügen")
logger.warning(f"[AgentCmd] Team-Member konnte nicht hinzugefügt werden: {name_clean}") logger.warning(f"[AgentCmd] Team-Member konnte nicht hinzugefügt werden: {name_clean}")
# UPDATE_TEAM_MEMBER: Aktualisiere Team-Mitglied # UPDATE_TEAM_MEMBER: Aktualisiere Team-Mitglied
@ -1192,10 +1227,23 @@ Bitte entscheide ob dieser Agent erstellt werden soll.""",
if not kwargs: if not kwargs:
logger.warning(f"[AgentCmd] @UPDATE_TEAM_MEMBER für '{identifier}' ohne Felder ignoriert") logger.warning(f"[AgentCmd] @UPDATE_TEAM_MEMBER für '{identifier}' ohne Felder ignoriert")
continue continue
fields_summary = ", ".join(f"{k}={v}" for k, v in kwargs.items())
action_task_id = create_task(
title=f"Team-Member aktualisiert: {identifier}",
description=f"**Identifier:** {identifier}\n**Felder:** {fields_summary}",
agent_key=agent_key,
task_type='action_team',
created_by=agent_key,
parent_task_id=task_id,
)
success = update_team_member(identifier, **kwargs) success = update_team_member(identifier, **kwargs)
if success: if success:
update_task_db(action_task_id, status='completed',
response=f"{identifier} aktualisiert: {fields_summary}")
logger.info(f"[AgentCmd] Team-Member aktualisiert: {identifier} - {list(kwargs.keys())}") logger.info(f"[AgentCmd] Team-Member aktualisiert: {identifier} - {list(kwargs.keys())}")
else: else:
update_task_db(action_task_id, status='error',
response=f"✗ Update fehlgeschlagen für '{identifier}'")
logger.error(f"[AgentCmd] Update fehlgeschlagen für '{identifier}'") logger.error(f"[AgentCmd] Update fehlgeschlagen für '{identifier}'")
def create_new_agent(agent_key, role, skills): def create_new_agent(agent_key, role, skills):

View file

@ -35,13 +35,24 @@
<td> <td>
<strong>{{ task.title }}</strong> <strong>{{ task.title }}</strong>
{% if task.type == 'email' %} {% if task.type == 'email' %}
<span class="badge bg-info ms-1" title="Von: {{ task.reply_to }}">Email</span> <span class="badge bg-info ms-1">📧 Email</span>
{% endif %} {% elif task.type == 'telegram' %}
{% if task.type == 'orchestrated' %} <span class="badge ms-1" style="background-color:#229ed9;">✈ Telegram</span>
{% elif task.type == 'action_email' %}
<span class="badge bg-info ms-1">📤 Email gesendet</span>
{% elif task.type == 'action_telegram' %}
<span class="badge ms-1" style="background-color:#229ed9;">📤 Telegram gesendet</span>
{% elif task.type == 'action_team' %}
<span class="badge bg-secondary ms-1">👤 Team</span>
{% elif task.type == 'orchestrated' %}
<span class="badge ms-1" style="background-color:#9333ea;">Orchestriert</span> <span class="badge ms-1" style="background-color:#9333ea;">Orchestriert</span>
{% endif %} {% elif task.type == 'agent_created' or task.type == 'agent_subtask' %}
{% if task.type == 'agent_created' %}
<span class="badge bg-warning ms-1">Agent</span> <span class="badge bg-warning ms-1">Agent</span>
{% elif task.type == 'agent_question' %}
<span class="badge bg-warning ms-1">❓ Frage</span>
{% endif %}
{% if task.parent_task_id %}
<span class="badge bg-dark ms-1" title="Sub-Task von #{{ task.parent_task_id }}">↳ #{{ task.parent_task_id }}</span>
{% endif %} {% endif %}
{% if task.description %} {% if task.description %}
<div style="font-size:.75rem;color:var(--text-muted);"> <div style="font-size:.75rem;color:var(--text-muted);">