fix: execute multica template agents

This commit is contained in:
2026-06-13 12:07:51 +08:00
parent 9632c1b4a6
commit 47da899ff3
4 changed files with 225 additions and 20 deletions
@@ -53,21 +53,12 @@ def validate_fixture(fixture: Dict[str, Any]) -> Dict[str, int]:
edges = definition.get("edges", [])
agent_codes = {agent.get("code") for agent in agents}
workflow_agent_codes = {
node.get("agent_code")
(node.get("data") or {}).get("agent_code")
for node in nodes
if isinstance(node, dict) and node.get("agent_code")
if isinstance(node, dict) and (node.get("data") or {}).get("agent_code")
}
node_types = {node.get("type") for node in nodes}
required_agent_codes = {
"multica_product_manager",
"business_requirements_analyst",
"system_architect",
"frontend_engineer",
"backend_engineer",
"qa_engineer",
"project_manager",
}
required_persona_fields = {
"role",
"skills",
@@ -75,10 +66,8 @@ def validate_fixture(fixture: Dict[str, Any]) -> Dict[str, int]:
"background",
"examples",
}
required_node_types = {"start", "end", "condition", "template", "parallel", "merge"}
required_node_types = {"start", "end", "template", "parallel", "merge"}
missing_agents = sorted(required_agent_codes - agent_codes)
extra_agents = sorted(agent_codes - required_agent_codes)
missing_workflow_agents = sorted(workflow_agent_codes - agent_codes)
missing_persona_fields = {
agent.get("code"): sorted(required_persona_fields - set((agent.get("persona") or {}).keys()))
@@ -92,17 +81,13 @@ def validate_fixture(fixture: Dict[str, Any]) -> Dict[str, int]:
)
project_manager_workflow = (project_manager or {}).get("workflow_code")
if (
missing_agents
or extra_agents
or missing_workflow_agents
missing_workflow_agents
or missing_persona_fields
or missing_node_types
or project_manager_workflow != "multica_org_collaboration_flow"
):
raise ValueError(
f"Fixture validation failed: missing_agents={missing_agents}, "
f"extra_agents={extra_agents}, "
f"missing_workflow_agents={missing_workflow_agents}, "
f"Fixture validation failed: missing_workflow_agents={missing_workflow_agents}, "
f"missing_persona_fields={missing_persona_fields}, "
f"missing_node_types={missing_node_types}, "
f"project_manager_workflow={project_manager_workflow}"
@@ -116,6 +101,24 @@ def validate_fixture(fixture: Dict[str, Any]) -> Dict[str, int]:
}
async def resolve_default_chat_model_id(session) -> str | None:
from sqlalchemy import select
from ai_platform.models.model import LLMModel
result = await session.execute(
select(LLMModel)
.where(
LLMModel.is_deleted == False,
LLMModel.is_active == True,
LLMModel.model_type == "chat",
)
.order_by(LLMModel.sort.desc(), LLMModel.sys_create_datetime.desc())
)
model = result.scalars().first()
return str(model.id) if model else None
async def upsert_workflow(session, workflow_payload: Dict[str, Any]) -> AIWorkflow:
from sqlalchemy import select
@@ -166,8 +169,15 @@ async def upsert_agents(session, fixture: Dict[str, Any], workflow_id: str) -> i
from app.base_model import generate_nanoid
count = 0
default_chat_model_id = await resolve_default_chat_model_id(session)
for agent_fixture in fixture["agents"]:
payload = build_agent_payload(agent_fixture, workflow_id)
if (
payload.get("mode", "autonomous") == "autonomous"
and not payload.get("model_id")
and default_chat_model_id
):
payload["model_id"] = default_chat_model_id
result = await session.execute(select(Agent).where(Agent.code == payload["code"]))
agent = result.scalar_one_or_none()
if agent: