feat(maf): conversation-driven MAF roundtable (R1/R2) + server-owned stage-3 dispatch
Backend:
- Conversation API at /api/maf-roundtable/conversations: create/list/detail,
paginated messages, atomic send+run start, owner-only isolation,
admin read-only diagnostic access
- SSE real-time event stream (GET /conversations/{id}/stream) backed by
ConversationEventHub + conversation_events store; multi-worker deployment doc
- Deterministic server-owned stage-3 dispatch contracts (dispatch_contracts.py):
routing resolved from trusted MAF deployment config instead of manager-chosen
agent ids; config.yaml keeps stage-3 routing deployment-owned
(default_manager_agent_id / seat ids / business_routes / max_seats_per_run)
- Conversation persistence (conversations/messages stores) + v2 migration script
- Tests: conversations, conversation stream, migration, phase3 conversation dispatch
Frontend:
- Vitest test infra for MAF (vitest.maf.config.ts + test:maf script) with
component tests for ApprovalCard/RunHeader/SessionsPage and use-maf-events
- Session form lib, flow-graph dialog / run-detail / sessions page updates,
routes and nav tweaks
- Docs: R0 legacy interaction baseline mapping, updated implementation plan
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
df408831e5
commit
99642fca6c
46 files changed
+6358
-1306
No files matched your search
@@ -74,6 +74,8 @@ class RoundtableState:
|
||||
capability_snapshot: dict[str, Any] | None = None,
|
||||
seat_timeout_seconds: float = 600.0,
|
||||
schema_repair_enabled: bool = True,
|
||||
intent_type: str | None = None,
|
||||
dispatch_plan: dict[str, Any] | None = None,
|
||||
) -> None:
|
||||
self.session_id = session_id
|
||||
self.run_id = run_id
|
||||
@@ -89,6 +91,11 @@ class RoundtableState:
|
||||
self.capability_snapshot = capability_snapshot
|
||||
self.seat_timeout_seconds = seat_timeout_seconds
|
||||
self.schema_repair_enabled = schema_repair_enabled
|
||||
# Stage 3 server-validated routing metadata. The workflow may use
|
||||
# this for diagnostics/checkpoints, but it never accepts a new agent
|
||||
# id from manager model output.
|
||||
self.intent_type = intent_type
|
||||
self.dispatch_plan = dispatch_plan
|
||||
|
||||
self.current_round = 0
|
||||
self.turn_results: list[dict[str, Any]] = []
|
||||
@@ -128,6 +135,8 @@ class RoundtableState:
|
||||
"capability_snapshot": self.capability_snapshot,
|
||||
"seat_timeout_seconds": self.seat_timeout_seconds,
|
||||
"schema_repair_enabled": self.schema_repair_enabled,
|
||||
"intent_type": self.intent_type,
|
||||
"dispatch_plan": self.dispatch_plan,
|
||||
"current_round": self.current_round,
|
||||
"turn_results": self.turn_results,
|
||||
"fact_ledger": self.fact_ledger,
|
||||
@@ -159,6 +168,8 @@ class RoundtableState:
|
||||
capability_snapshot=d.get("capability_snapshot"),
|
||||
seat_timeout_seconds=float(d.get("seat_timeout_seconds") or 600.0),
|
||||
schema_repair_enabled=bool(d.get("schema_repair_enabled", True)),
|
||||
intent_type=d.get("intent_type"),
|
||||
dispatch_plan=d.get("dispatch_plan"),
|
||||
)
|
||||
state.current_round = d.get("current_round", 0)
|
||||
state.turn_results = d.get("turn_results", [])
|
||||
@@ -531,12 +542,20 @@ class SeatExecutor(Executor):
|
||||
a for a in turn_actions
|
||||
if a.get("tool_name") == tc_name and not a.get("logical_action_id")
|
||||
]
|
||||
if len(hits) != 1:
|
||||
if len(hits) > 1:
|
||||
raise RuntimeError(
|
||||
f"seat {self._agent_id} turn {self._state.current_round}: "
|
||||
f"pending tool call '{tc_name}' (id={tc_id or '<none>'}) matched "
|
||||
f"{len(hits)} waiting actions (expected exactly 1) — refusing to guess"
|
||||
)
|
||||
if len(hits) == 0:
|
||||
logger.warning(
|
||||
"seat %s turn %s: pending tool call '%s' (id=%s) classified as "
|
||||
"needing approval but matched 0 waiting actions — tool may be "
|
||||
"unclassified or executed as read by WriteGuard; skipping",
|
||||
self._agent_id, self._state.current_round, tc_name, tc_id or "<none>",
|
||||
)
|
||||
continue
|
||||
matched.append(hits[0])
|
||||
|
||||
# Merge into pending_approvals (multi-seat).
|
||||
@@ -686,12 +705,45 @@ class CrossReviewExecutor(Executor):
|
||||
if failed_seats:
|
||||
review["gaps"] = [f"席位失败: {', '.join(failed_seats)}"]
|
||||
|
||||
# The quality gate is server-owned. A manager may recommend acceptance,
|
||||
# but gaps/failures/schema degradation always become a controlled gap
|
||||
# and are carried into the final result instead of being labelled as a
|
||||
# verified fact.
|
||||
has_quality_gap = bool(
|
||||
review.get("partial_failure")
|
||||
or review.get("failed_seats")
|
||||
or review.get("gaps")
|
||||
or review.get("conflicts")
|
||||
or review.get("tool_failures")
|
||||
or review.get("schema_status") == "schema_invalid"
|
||||
)
|
||||
review["decision"] = "controlled_gap" if has_quality_gap else "accept"
|
||||
review["reason"] = (
|
||||
"required evidence or seat output is incomplete"
|
||||
if has_quality_gap
|
||||
else "required seat deliveries passed deterministic checks"
|
||||
)
|
||||
self._state.cross_review_result = review
|
||||
# Surface unresolved conflicts from review notes.
|
||||
for c in review.get("conflicts") or []:
|
||||
if c and c not in self._state.fact_ledger["conflicts"]:
|
||||
self._state.fact_ledger["conflicts"].append(c)
|
||||
|
||||
await self._adapter._emit_critical(self._state.run_id, {
|
||||
"event_type": "manager.review.decision",
|
||||
"agent_id": self._state.manager_agent_id or "",
|
||||
"turn_index": self._state.current_round,
|
||||
"payload": {
|
||||
"decision": review["decision"],
|
||||
"reason": review["reason"],
|
||||
"quality": {
|
||||
"failed_seat_count": len(review.get("failed_seats") or []),
|
||||
"gap_count": len(review.get("gaps") or []),
|
||||
"conflict_count": len(review.get("conflicts") or []),
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
self._state.mark_completed("cross_review")
|
||||
self._state.stage = "approval"
|
||||
await ctx.send_message({"decision": "reviewed", "review": review})
|
||||
@@ -937,16 +989,13 @@ class ApprovalGateExecutor(Executor):
|
||||
def _check_needs_approval(self) -> bool:
|
||||
if self._state.write_policy == "auto":
|
||||
return False
|
||||
if self._state.pending_approvals:
|
||||
return True
|
||||
for result in self._state.turn_results:
|
||||
for tc in result.get("tool_calls") or []:
|
||||
name = tc.get("name", "")
|
||||
if not name:
|
||||
continue
|
||||
if tool_needs_approval(name, self._state.write_policy, self._state.capability_snapshot):
|
||||
return True
|
||||
return False
|
||||
# pending_approvals is the authoritative source: it is populated by
|
||||
# SeatExecutor._capture_pending_approvals which only adds tool calls
|
||||
# that WriteGuard actually intercepted (i.e. have a database action).
|
||||
# Tools that were classified as needing approval but had 0 matching
|
||||
# actions (unclassified/hallucinated/read tools) are intentionally
|
||||
# skipped and must NOT re-trigger the gate here.
|
||||
return bool(self._state.pending_approvals)
|
||||
|
||||
|
||||
# ── Finalizer ───────────────────────────────────────────────────────────────
|
||||
@@ -1006,6 +1055,10 @@ async def generate_final_report(adapter: Any, state: RoundtableState) -> dict[st
|
||||
"agent_id": manager_id,
|
||||
"partial_failure": state.partial_failure,
|
||||
"degraded": state.partial_failure,
|
||||
"quality_decision": (
|
||||
(state.cross_review_result or {}).get("decision")
|
||||
or ("controlled_gap" if state.partial_failure else "accept")
|
||||
),
|
||||
}
|
||||
else:
|
||||
state.final_result = {
|
||||
@@ -1014,6 +1067,10 @@ async def generate_final_report(adapter: Any, state: RoundtableState) -> dict[st
|
||||
"note": "no_manager_thread",
|
||||
"partial_failure": state.partial_failure,
|
||||
"degraded": state.partial_failure,
|
||||
"quality_decision": (
|
||||
(state.cross_review_result or {}).get("decision")
|
||||
or ("controlled_gap" if state.partial_failure else "accept")
|
||||
),
|
||||
}
|
||||
|
||||
await adapter._emit_critical(state.run_id, make_run_completed(manager_id, state.current_round + 1, {
|
||||
|
||||
Reference in new issue
Block a user