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

58
app.py
View file

@ -1095,13 +1095,23 @@ Bitte entscheide ob dieser Agent erstellt werden soll.""",
to_clean = to_addr.strip()
subject_clean = subject.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,
triggered_by=f'agent:{agent_key}', task_id=task_id)
triggered_by=f'agent:{agent_key}', task_id=action_task_id)
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}")
else:
update_task_db(action_task_id, status='error', response=f"✗ Fehler: {message}")
logger.error(f"[AgentCmd] Email-Fehler: {message}")
# SEND_TELEGRAM: Orchestrator sendet Telegram-Nachricht
@ -1115,10 +1125,17 @@ Bitte entscheide ob dieser Agent erstellt werden soll.""",
recipient_clean = recipient.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'):
try:
# Direkte numerische ID oder Name/Email → DB-Lookup
chat_id = None
if recipient_clean.lstrip('-').isdigit():
chat_id = int(recipient_clean)
@ -1134,12 +1151,18 @@ Bitte entscheide ob dieser Agent erstellt werden soll.""",
if chat_id:
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})")
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}'")
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)}")
else:
update_task_db(action_task_id, status='error', response="✗ Telegram nicht konfiguriert")
logger.warning("[AgentCmd] Telegram nicht konfiguriert")
# 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()
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)
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})")
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}")
# UPDATE_TEAM_MEMBER: Aktualisiere Team-Mitglied
@ -1192,10 +1227,23 @@ Bitte entscheide ob dieser Agent erstellt werden soll.""",
if not kwargs:
logger.warning(f"[AgentCmd] @UPDATE_TEAM_MEMBER für '{identifier}' ohne Felder ignoriert")
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)
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())}")
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}'")
def create_new_agent(agent_key, role, skills):