refactor(block-h): resolve CommConversation hardcoding via kommunikation contract

This commit is contained in:
Agent Zero
2026-08-23 12:02:29 +02:00
parent 1f4a621910
commit a7699d3598
4 changed files with 40 additions and 27 deletions
+7 -13
View File
@@ -394,27 +394,21 @@ async def run_react_loop(
if agent_run_id:
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_id = await komm.find_locked_room_id(
db=db,
tenant_id=tenant_id,
plugin_name="automation",
title=room_title,
)
conv = existing.scalar_one_or_none()
if conv:
if conv_id:
await komm.send_message(
db=db,
tenant_id=tenant_id,
conversation_id=conv.id,
conversation_id=conv_id,
sender_id=agent_id,
sender_type="agent",
content=f"Approval required for tool '{tool_name}'",