feat(orchestration): enforce corporate guardrails, domain invariant and daily publishing rate limits
Deploy Canina / deploy (push) Successful in 28s
Deploy Canina / deploy (push) Successful in 28s
This commit is contained in:
1 parent
459f8b59fe
commit
eb17c8e284
1 file changed
+40
-1
@@ -334,16 +334,55 @@ def execution_prompt(task: dict[str, Any]) -> str:
|
||||
""".strip()
|
||||
|
||||
|
||||
|
||||
def check_corporate_guardrails(task: dict[str, Any], db: Database) -> tuple[bool, str]:
|
||||
"""Enforce corporate operational constraints (Rate limits, Business domain bounds)."""
|
||||
dept = (task.get("department") or "").upper()
|
||||
title = task.get("title") or ""
|
||||
|
||||
# 1. Anti-Hallucination & Core Domain Invariant: Supplement / Veterinary only
|
||||
forbidden_terms = ["لواشک", "پوشاک", "ارز دیجیتال", "بیت کوین", "فارکس", "آرایشی انسان", "املاک"]
|
||||
for term in forbidden_terms:
|
||||
if term in title or term in (task.get("description") or ""):
|
||||
return False, f"Domain Violation: '{term}' is strictly forbidden. Canina operates exclusively in European clinical pet supplements."
|
||||
|
||||
# 2. Content Rate Limiting: Max 1 new blog post per 24h
|
||||
if dept == "CONTENT" and any(k in title for k in ["نگارش محتوای مقاله", "تولید مقاله", "انتشار پست", "پست وبلاگ"]):
|
||||
# Check how many blogs were created today
|
||||
try:
|
||||
today_count_raw = db.sql("SELECT count(*) FROM blogs WHERE created_at >= CURRENT_DATE AND is_published = true;")
|
||||
today_count = int(today_count_raw.strip().splitlines()[-1] if today_count_raw.strip() else "0")
|
||||
if today_count >= 1:
|
||||
return False, "Rate Limit Reached: Maximum 1 new blog post permitted per day. Task queued for next publishing window."
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return True, "Passed"
|
||||
|
||||
|
||||
def execute_next_task(db: Database, model: ModelClient) -> bool:
|
||||
"""Produce reviewable drafts; never publish or trust model QA assertions."""
|
||||
task = db.claim_next()
|
||||
if not task:
|
||||
return False
|
||||
allowed, reason = check_corporate_guardrails(task, db)
|
||||
if not allowed:
|
||||
# Defer task gracefully
|
||||
event = {'timestamp': utc_now(), 'status': 'RATE_LIMITED_DEFERRED', 'reason': reason}
|
||||
db.finish_claim(task, event, 'WAITING_DEPENDENCIES')
|
||||
return True
|
||||
|
||||
prompt = execution_prompt(task)
|
||||
try:
|
||||
raw = model.complete(prompt)
|
||||
result = parse_structured_response(raw)
|
||||
criteria = task.get('acceptance_criteria') or {}
|
||||
raw_criteria = task.get('acceptance_criteria')
|
||||
if isinstance(raw_criteria, dict):
|
||||
criteria = raw_criteria
|
||||
elif isinstance(raw_criteria, list):
|
||||
criteria = {'items': raw_criteria, 'depth': 0}
|
||||
else:
|
||||
criteria = {}
|
||||
children = build_child_tasks(task['code'], result, int(criteria.get('depth', 0)))
|
||||
deliverable = result.get('deliverable') or {}
|
||||
qa = verify_artifact(deliverable, result.get('verification') or {})
|
||||
|
||||
Reference in new issue
Block a user