feat: I-WORK-HANDOFF + I-WORK-PROACTIVE — approval requests posted to communication with approval_request block, proactive suggestions posted to communication with action_card block
Check Cross-Plugin Imports / check (push) Has been cancelled

This commit is contained in:
Agent Zero
2026-08-21 00:05:13 +02:00
parent b540f4b2ab
commit 62793a001c
2 changed files with 112 additions and 10 deletions
+44 -9
View File
@@ -390,16 +390,51 @@ async def run_react_loop(
requested_by_type="agent",
)
# Post approval request to workstream
# Post approval request to Communication (I-WORK-HANDOFF)
if agent_run_id:
await post_approval_request(
db=db,
tenant_id=tenant_id,
agent_id=getattr(agent_definition, "id", uuid.uuid4()),
approval_id=approval.id,
action=f"Tool '{tool_name}' requires approval",
details={"tool_name": tool_name, "arguments": args},
)
try:
from app.plugins.builtins.contracts import get_contract_registry
from app.plugins.builtins.kommunikation.models import CommConversation
from sqlalchemy import select as sa_select
komm = get_contract_registry().get("kommunikation")
if komm:
agent_id = getattr(agent_definition, "id", uuid.uuid4())
room_title = f"Agent: {getattr(agent_definition, 'name', 'Agent')}"
existing = await db.execute(
sa_select(CommConversation).where(
CommConversation.tenant_id == 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 conv:
await komm.send_message(
db=db,
tenant_id=tenant_id,
conversation_id=conv.id,
sender_id=agent_id,
sender_type="agent",
content=f"Approval required for tool '{tool_name}'",
content_format="text",
blocks=[
{
"block_type": "approval_request",
"block_data": {
n "title": f"Approval: {tool_name}",
"description": f"Agent wants to execute tool '{tool_name}' with arguments: {json.dumps(args)[:300]}",
"approval_id": str(approval.id),
"status": "pending",
},
"sort_order": 0,
}
],
metadata={"approval_id": str(approval.id), "agent_run_id": str(agent_run_id)},
)
except Exception:
logger.warning("Failed to post approval request to communication", exc_info=True)
# Pause the loop — return with waiting_for_approval status
result.status = "waiting_for_approval"