kin: KIN-135-backend_dev
This commit is contained in:
parent
4c01e0e4ee
commit
24be66d16c
9 changed files with 436 additions and 6 deletions
|
|
@ -70,6 +70,17 @@ def build_context(
|
|||
ctx["available_specialists"] = []
|
||||
ctx["routes"] = {}
|
||||
ctx["departments"] = {}
|
||||
# KIN-135: return history for escalation routing
|
||||
try:
|
||||
return_count = (task or {}).get("return_count") or 0
|
||||
ctx["return_count"] = return_count
|
||||
if return_count > 0:
|
||||
ctx["return_history"] = models.get_task_returns(conn, task_id, limit=5)
|
||||
else:
|
||||
ctx["return_history"] = []
|
||||
except Exception:
|
||||
ctx["return_count"] = 0
|
||||
ctx["return_history"] = []
|
||||
|
||||
elif role == "architect":
|
||||
ctx["modules"] = models.get_modules(conn, project_id)
|
||||
|
|
@ -151,6 +162,17 @@ def build_context(
|
|||
except Exception:
|
||||
pass
|
||||
|
||||
elif role == "return_analyst":
|
||||
# KIN-135: return analyst needs full return history and decisions
|
||||
ctx["decisions"] = models.get_decisions(conn, project_id)
|
||||
try:
|
||||
return_count = (task or {}).get("return_count") or 0
|
||||
ctx["return_count"] = return_count
|
||||
ctx["return_history"] = models.get_task_returns(conn, task_id, limit=20)
|
||||
except Exception:
|
||||
ctx["return_count"] = 0
|
||||
ctx["return_history"] = []
|
||||
|
||||
else:
|
||||
# Unknown role — give decisions as fallback
|
||||
ctx["decisions"] = models.get_decisions(conn, project_id, limit=20)
|
||||
|
|
@ -297,6 +319,20 @@ def format_prompt(context: dict, role: str, prompt_template: str | None = None)
|
|||
sections.append(f"- {t['id']}: {t['title']} [{t['status']}]")
|
||||
sections.append("")
|
||||
|
||||
# Return history (PM) — KIN-135
|
||||
return_count = context.get("return_count", 0)
|
||||
return_history = context.get("return_history")
|
||||
if return_count and return_count > 0:
|
||||
sections.append(f"## Return History (return_count={return_count}):")
|
||||
if return_history:
|
||||
for r in return_history:
|
||||
reason_text = f" — {r['reason_text']}" if r.get("reason_text") else ""
|
||||
sections.append(
|
||||
f"- #{r['return_number']} [{r['reason_category']}]{reason_text} "
|
||||
f"(returned_by={r.get('returned_by', 'system')}, at={r.get('returned_at', '')})"
|
||||
)
|
||||
sections.append("")
|
||||
|
||||
# Available specialists (PM)
|
||||
specialists = context.get("available_specialists")
|
||||
if specialists:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue