Spaces:
Sleeping
Sleeping
| from typing import Dict, List | |
| from database.db import DatabaseManager | |
| from models.model_manager import ModelManager | |
| from schemas.enums import LogicalModel | |
| from schemas.models import DebateSession, DebateTurn | |
| from telemetry.event_bus import EventBus | |
| class DebateEngine: | |
| """Orchestrates structured multi-agent debates and synthesizes consensus.""" | |
| def __init__(self, db: DatabaseManager, event_bus: EventBus, model_manager: ModelManager): | |
| self.db = db | |
| self.event_bus = event_bus | |
| self.model_manager = model_manager | |
| async def initiate_debate(self, mission_id: str, topic: str, participants: List[Dict[str, str]]) -> DebateSession: | |
| debate = DebateSession( | |
| mission_id=mission_id, | |
| topic=topic, | |
| participants=[p["name"] for p in participants], | |
| ) | |
| turns = [] | |
| for idx, p in enumerate(participants): | |
| position = "SUPPORT" if idx % 2 == 0 else "CRITIQUE" | |
| arg_prompt = f"Provide a {position} perspective on topic '{topic}' based on available evidence." | |
| resp = await self.model_manager.generate_response(LogicalModel.MDL_FST, arg_prompt) | |
| turn = DebateTurn( | |
| turn_number=idx + 1, | |
| agent_id=p["id"], | |
| agent_name=p["name"], | |
| position=position, | |
| argument=f"[{position}] {resp['content']}", | |
| evidence_claims=[f"Claim_{idx+1} for {topic}"], | |
| confidence=85.0 + (idx * 2.5), | |
| ) | |
| turns.append(turn) | |
| debate.turns = turns | |
| debate.status = "CONSENSUS_REACHED" | |
| debate.consensus_summary = f"Multi-agent debate concluded for '{topic}'. Strong alignment achieved on core evidence claims." | |
| debate.final_confidence = 91.5 | |
| await self.db.save_debate_session(debate) | |
| await self.db.save_memory( | |
| "DebateEngine", | |
| mission_id, | |
| f"Debate Summary for {topic}: {debate.consensus_summary}", | |
| ["debate", "consensus", "collective_memory"], | |
| ) | |
| await self.event_bus.emit("DebateConcluded", mission_id, "DebateEngine", {"topic": topic, "confidence": debate.final_confidence}) | |
| return debate | |