"""System composition stage, available independently of user canvas resources.""" from sqlmodel import Session, select from ..models import Agent DEFAULT_COMPOSER_RULES = """# 组合 Agent 规则 1. 按任务单顺序组合已通过的内容段,跳过用户放弃的段落。 2. 核对五项一致性:跨段矛盾、回指断裂、时间线、情绪曲线和钩子兑现。 3. 特别检查跳过段落后的衔接,下一段必须承接最近一段已通过内容。 4. 结构性问题定位到对应内容段,给出具体修改建议;不能擅自补写事实或改动已确认内容。 5. 保留已有内容的表达风格,不引入任务导图以外的新主题。 """ def resolve_composer_agent(session: Session) -> Agent: # Preserve an existing system configuration, but never pick another user's # private Agent as a shared execution stage. configured = session.exec(select(Agent).where( Agent.role == "composer", Agent.builtin == True, # noqa: E712 Agent.status == "active", Agent.owner_user_id == 0, Agent.visibility == "global", ).order_by(Agent.id)).first() if configured: return configured # This runtime-only Agent follows the global text model. It is not a # canvas/resource record, so deleting a resource cannot remove the stage. return Agent(id=0, name="系统组合 Agent", role="composer", builtin=True, organization_id=0, owner_user_id=0, visibility="global", rules=DEFAULT_COMPOSER_RULES)