feat: F-PREBUILT + F-COMM + F-WORK + G-WORK — prebuilt agents registered, agent results posted to communication, workflow results posted to communication
Check Cross-Plugin Imports / check (push) Has been cancelled
Check Cross-Plugin Imports / check (push) Has been cancelled
This commit is contained in:
@@ -369,6 +369,71 @@ async def run_agent(
|
||||
status=result_data.get("status"),
|
||||
result=result_data,
|
||||
)
|
||||
|
||||
# ── Post agent result to Communication (F-COMM) ──
|
||||
try:
|
||||
from app.plugins.builtins.contracts import get_contract_registry
|
||||
komm = get_contract_registry().get("kommunikation")
|
||||
if komm:
|
||||
async with factory() as db:
|
||||
# Find or create agent conversation room
|
||||
from app.plugins.builtins.kommunikation.models import CommConversation
|
||||
from sqlalchemy import select as sa_select
|
||||
room_title = f"Agent: {agent.name}"
|
||||
existing = await db.execute(
|
||||
sa_select(CommConversation).where(
|
||||
CommConversation.tenant_id == agent.tenant_id,
|
||||
CommConversation.title == room_title,
|
||||
CommConversation.is_locked.is_(True),
|
||||
CommConversation.locked_by == "automation",
|
||||
CommConversation.deleted_at.is_(None),
|
||||
)
|
||||
)
|
||||
conv = existing.scalar_one_or_none()
|
||||
if not conv:
|
||||
room = await komm.create_plugin_room(
|
||||
db=db,
|
||||
tenant_id=agent.tenant_id,
|
||||
user_id=agent.created_by,
|
||||
plugin_name="automation",
|
||||
title=room_title,
|
||||
participant_type="agent",
|
||||
)
|
||||
conv_id = uuid.UUID(room["conversation_id"])
|
||||
else:
|
||||
conv_id = conv.id
|
||||
|
||||
# Post result as message with action_card block
|
||||
status = result_data.get("status", "unknown")
|
||||
result_text = result_data.get("llm_response", result_data.get("error", "No result"))
|
||||
await komm.send_message(
|
||||
db=db,
|
||||
tenant_id=agent.tenant_id,
|
||||
conversation_id=conv_id,
|
||||
sender_id=agent.id,
|
||||
sender_type="agent",
|
||||
content=f"Agent '{agent.name}' completed with status: {status}",
|
||||
content_format="text",
|
||||
blocks=[
|
||||
{
|
||||
"block_type": "action_card",
|
||||
"block_data": {
|
||||
"title": f"Agent Result: {agent.name}",
|
||||
"description": result_text[:500] if result_text else "No result",
|
||||
"actions": [
|
||||
{"label": "View Details", "action": "view_agent_run", "data": {"run_id": str(run_id)}},
|
||||
],
|
||||
},
|
||||
"sort_order": 0,
|
||||
}
|
||||
],
|
||||
metadata={"agent_id": str(agent.id), "run_id": str(run_id), "status": status},
|
||||
)
|
||||
await db.commit()
|
||||
logger.info("Posted agent result to conversation %s", conv_id)
|
||||
except Exception as e:
|
||||
logger.warning("Failed to post agent result to communication: %s", e)
|
||||
|
||||
async with factory() as db:
|
||||
await enqueue_outbox_event(
|
||||
db,
|
||||
|
||||
Reference in New Issue
Block a user