Skip to content

Commit 55e2793

Browse files
feat(routing): surface priority and routingConfidence in routing decisions
- Extend frontend RoutingDecision type with priority and routingConfidence fields - Pass priority and routing_confidence through SSE in pipeline.py (live events) - Pass priority and routing_confidence through agent_events.py (state snapshots)
1 parent aa42b4b commit 55e2793

File tree

3 files changed

+40
-19
lines changed

3 files changed

+40
-19
lines changed

backend/app/services/agent_events.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@ async def publish_agent_event(
161161
if "type" not in data_to_send:
162162
data_to_send["type"] = event_type.value
163163

164-
event: SSEEvent = {"event": event_type.value, "data": json.dumps(data_to_send)}
164+
event: SSEEvent = {
165+
"event": event_type.value,
166+
"data": json.dumps(data_to_send),
167+
}
165168
_event_buffer[case_id].append(event)
166169
subscribers = _agent_subscribers.get(case_id, [])
167170
for queue in subscribers:
@@ -539,7 +542,9 @@ def build_execution_metadata(
539542
"inputTokens": execution.input_tokens or 0,
540543
"outputTokens": execution.output_tokens or 0,
541544
"durationMs": duration_ms or 0,
542-
"startedAt": execution.started_at.isoformat() if execution.started_at else None,
545+
"startedAt": (
546+
execution.started_at.isoformat() if execution.started_at else None
547+
),
543548
"completedAt": (
544549
execution.completed_at.isoformat() if execution.completed_at else None
545550
),
@@ -583,10 +588,10 @@ def build_agent_result(
583588
{
584589
"type": "triage-results",
585590
"data": {
586-
"fileCount": len(file_results)
587-
if isinstance(file_results, list)
588-
else 0,
589-
"groupings": len(groupings) if isinstance(groupings, list) else 0,
591+
"fileCount": (
592+
len(file_results) if isinstance(file_results, list) else 0
593+
),
594+
"groupings": (len(groupings) if isinstance(groupings, list) else 0),
590595
},
591596
}
592597
]
@@ -597,9 +602,9 @@ def build_agent_result(
597602
{
598603
"type": "routing-decisions",
599604
"data": {
600-
"routingCount": len(decisions)
601-
if isinstance(decisions, list)
602-
else 0,
605+
"routingCount": (
606+
len(decisions) if isinstance(decisions, list) else 0
607+
),
603608
"parallelAgents": output.get("parallel_agents", []),
604609
"researchTriggered": (output.get("research_trigger") or {}).get(
605610
"should_trigger", False
@@ -627,6 +632,8 @@ def build_agent_result(
627632
"targetAgent": agent,
628633
"reason": rd.get("reasoning", ""),
629634
"domainScore": score,
635+
"priority": rd.get("priority", "medium"),
636+
"routingConfidence": rd.get("routing_confidence"),
630637
}
631638
)
632639
result["routingDecisions"] = routing_decisions_camel
@@ -637,7 +644,9 @@ def build_agent_result(
637644
{
638645
"type": "strategy-findings",
639646
"data": {
640-
"findingCount": len(findings) if isinstance(findings, list) else 0,
647+
"findingCount": (
648+
len(findings) if isinstance(findings, list) else 0
649+
),
641650
},
642651
}
643652
]
@@ -665,8 +674,10 @@ def build_agent_result(
665674
{
666675
"type": f"{agent_name}-findings",
667676
"data": {
668-
"findingCount": len(findings) if isinstance(findings, list) else 0,
669-
"entityCount": len(entities) if isinstance(entities, list) else 0,
677+
"findingCount": (
678+
len(findings) if isinstance(findings, list) else 0
679+
),
680+
"entityCount": (len(entities) if isinstance(entities, list) else 0),
670681
"groupLabel": group_label,
671682
},
672683
}

backend/app/services/pipeline.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ async def _ensure_case_not_stuck(
6060
current = result.scalar_one_or_none()
6161
if current == CaseStatus.PROCESSING:
6262
logger.warning(
63-
"Safety net: forcing case %s from PROCESSING to ERROR", case_id
63+
"Safety net: forcing case %s from PROCESSING to ERROR",
64+
case_id,
6465
)
6566
await db.execute(
6667
update(Case)
@@ -312,7 +313,7 @@ async def run_analysis_workflow(
312313
triage_output=triage_output,
313314
db_session=db,
314315
publish_event=publish_fn,
315-
parent_execution_id=triage_execution.id if triage_execution else None,
316+
parent_execution_id=(triage_execution.id if triage_execution else None),
316317
)
317318

318319
orch_execution: AgentExecution | None = None
@@ -370,6 +371,8 @@ async def run_analysis_workflow(
370371
"targetAgent": agent,
371372
"reason": rd.reasoning,
372373
"domainScore": getattr(rd.domain_scores, agent, 0),
374+
"priority": rd.priority,
375+
"routingConfidence": rd.routing_confidence,
373376
}
374377
for rd in orchestrator_output.routing_decisions
375378
for agent in rd.target_agents
@@ -458,7 +461,10 @@ async def run_analysis_workflow(
458461
threshold = settings.get_routing_hitl_threshold(agent_type)
459462
if rd.routing_confidence < threshold:
460463
item_id = str(uuid4())
461-
item_mapping[item_id] = (rd.file_id, agent_type)
464+
item_mapping[item_id] = (
465+
rd.file_id,
466+
agent_type,
467+
)
462468
batch_items.append(
463469
BatchConfirmationItem(
464470
item_id=item_id,
@@ -563,9 +569,9 @@ async def run_analysis_workflow(
563569
hypotheses=[], # Empty until hypothesis system exists (Phase 7)
564570
db_session_factory=session_factory,
565571
publish_event=publish_fn,
566-
orchestrator_execution_id=orch_execution.id
567-
if orch_execution
568-
else None,
572+
orchestrator_execution_id=(
573+
orch_execution.id if orch_execution else None
574+
),
569575
)
570576

571577
# Emit agent-complete/error for each agent instance
@@ -774,7 +780,7 @@ async def run_analysis_workflow(
774780
hypotheses=[],
775781
db_session=db,
776782
publish_event=publish_fn,
777-
parent_execution_id=orch_execution.id if orch_execution else None,
783+
parent_execution_id=(orch_execution.id if orch_execution else None),
778784
context_injection=strategy_context_injection,
779785
)
780786

frontend/src/types/command-center.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ export interface RoutingDecision {
3333
targetAgent: AgentType;
3434
reason: string;
3535
domainScore: number; // Confidence score 0-100 (percentage)
36+
/** Routing priority assigned by the orchestrator. */
37+
priority?: "high" | "medium" | "low";
38+
/** Overall routing confidence (0-100). Low values may trigger HITL review. */
39+
routingConfidence?: number | null;
3640
}
3741

3842
export interface AgentResult {

0 commit comments

Comments
 (0)