225 lines
9.2 KiB
Python
225 lines
9.2 KiB
Python
"""
|
|
Scrum Multi-Agent Orchestrator
|
|
|
|
Integrates Scrum Agile methodology with multi-agent orchestration patterns.
|
|
Provides role definitions, sprint lifecycle management, user story tracking,
|
|
and coordinated task dispatching for Antigravity agents.
|
|
"""
|
|
|
|
from dataclasses import dataclass, field
|
|
from enum import Enum
|
|
from typing import Dict, List, Optional, Any, Callable
|
|
import json
|
|
import time
|
|
|
|
try:
|
|
from .agent_communication import MessageBroker, Message, MessageType, SharedMemory
|
|
from .workflow_management import WorkflowExecutor, Workflow, Task, TaskStatus
|
|
except ImportError:
|
|
from agent_communication import MessageBroker, Message, MessageType, SharedMemory
|
|
from workflow_management import WorkflowExecutor, Workflow, Task, TaskStatus
|
|
|
|
|
|
class ScrumRole(Enum):
|
|
"""Specialized agent roles within the Scrum development team."""
|
|
PRODUCT_OWNER = "product_owner"
|
|
SCRUM_MASTER = "scrum_master"
|
|
TECH_LEAD = "tech_lead"
|
|
FRONTEND_DEV = "frontend_dev"
|
|
BACKEND_DEV = "backend_dev"
|
|
QA_ENGINEER = "qa_engineer"
|
|
CODE_REVIEWER = "code_reviewer"
|
|
|
|
|
|
class StoryStatus(Enum):
|
|
"""Status of a User Story in the Sprint."""
|
|
BACKLOG = "backlog"
|
|
PLANNING = "planning"
|
|
IN_PROGRESS = "in_progress"
|
|
IN_QA = "in_qa"
|
|
IN_REVIEW = "in_review"
|
|
DONE = "done"
|
|
BLOCKED = "blocked"
|
|
|
|
|
|
@dataclass
|
|
class UserStory:
|
|
"""Represents an Agile User Story with acceptance criteria."""
|
|
story_id: str
|
|
title: str
|
|
description: str
|
|
acceptance_criteria: List[str]
|
|
story_points: int = 1
|
|
status: StoryStatus = StoryStatus.BACKLOG
|
|
technical_spec: Optional[str] = None
|
|
qa_checklist: List[str] = field(default_factory=list)
|
|
artifacts: Dict[str, str] = field(default_factory=dict)
|
|
|
|
|
|
@dataclass
|
|
class Sprint:
|
|
"""Represents a development sprint."""
|
|
sprint_id: str
|
|
name: str
|
|
goal: str
|
|
stories: List[UserStory] = field(default_factory=list)
|
|
created_at: float = field(default_factory=time.time)
|
|
completed_at: Optional[float] = None
|
|
retrospective_notes: List[str] = field(default_factory=list)
|
|
|
|
|
|
class ScrumAgentPersona:
|
|
"""System prompts and configuration profiles for each Scrum agent."""
|
|
|
|
PROMPTS: Dict[ScrumRole, Dict[str, Any]] = {
|
|
ScrumRole.PRODUCT_OWNER: {
|
|
"title": "Product Owner Agent",
|
|
"system_prompt": (
|
|
"You are the Product Owner. Your responsibility is to define the Sprint Goal, "
|
|
"refine User Stories into precise Gherkin format (Given/When/Then), clarify business value, "
|
|
"set strict acceptance criteria, and ensure the deliverables meet user needs."
|
|
),
|
|
"tools_required": ["search_codebase", "read_file"]
|
|
},
|
|
ScrumRole.SCRUM_MASTER: {
|
|
"title": "Scrum Master / Orchestrator Agent",
|
|
"system_prompt": (
|
|
"You are the Scrum Master and Workflow Orchestrator. Your role is to break down stories into "
|
|
"actionable developer subtasks, map dependencies (sequential vs parallel), monitor execution, "
|
|
"resolve blockers, coordinate inter-agent handoffs, and facilitate sprint completion."
|
|
),
|
|
"tools_required": ["subagent_tools", "messaging_tools"]
|
|
},
|
|
ScrumRole.TECH_LEAD: {
|
|
"title": "Tech Lead / Architect Agent",
|
|
"system_prompt": (
|
|
"You are the Software Architect and Tech Lead. You design API schemas, TypeScript interfaces, "
|
|
"database schemas, component hierarchies, and enforce architectural consistency and security standards. "
|
|
"You provide technical blueprints before developers start implementation."
|
|
),
|
|
"tools_required": ["read_file", "search_codebase"]
|
|
},
|
|
ScrumRole.FRONTEND_DEV: {
|
|
"title": "Frontend Developer Agent",
|
|
"system_prompt": (
|
|
"You are the Frontend Developer. You implement responsive, accessible, high-performance UI components "
|
|
"following the Modern UI Design System, mobile-first layouts, and smooth micro-interactions. "
|
|
"You consume API contracts provided by the Tech Lead and Backend Developer."
|
|
),
|
|
"tools_required": ["write_file", "edit_file", "read_file", "run_command"]
|
|
},
|
|
ScrumRole.BACKEND_DEV: {
|
|
"title": "Backend Developer Agent",
|
|
"system_prompt": (
|
|
"You are the Backend Developer. You implement clean API routes, business services, database models, "
|
|
"input validations, and integrations. You ensure high efficiency, reliability, and security."
|
|
),
|
|
"tools_required": ["write_file", "edit_file", "read_file", "run_command"]
|
|
},
|
|
ScrumRole.QA_ENGINEER: {
|
|
"title": "QA / Test Engineer Agent",
|
|
"system_prompt": (
|
|
"You are the QA Engineer. You design and execute unit, integration, and E2E test suites. "
|
|
"You strictly verify that each acceptance criterion of the User Story passes before certifying "
|
|
"the build for review."
|
|
),
|
|
"tools_required": ["run_command", "read_file", "write_file"]
|
|
},
|
|
ScrumRole.CODE_REVIEWER: {
|
|
"title": "Code Reviewer & Auditor Agent",
|
|
"system_prompt": (
|
|
"You are the Code Reviewer and Security/A11y Auditor. You review diffs for code smells, "
|
|
"OWASP vulnerabilities, WCAG accessibility, and maintainability. You sign off on the Definition of Done."
|
|
),
|
|
"tools_required": ["read_file", "search_codebase"]
|
|
}
|
|
}
|
|
|
|
|
|
class ScrumSprintOrchestrator:
|
|
"""Coordinates a full Scrum Sprint across multi-agent roles."""
|
|
|
|
def __init__(self, sprint_name: str, sprint_goal: str):
|
|
self.sprint = Sprint(sprint_id=f"sprint_{int(time.time())}", name=sprint_name, goal=sprint_goal)
|
|
self.memory = SharedMemory()
|
|
self.broker = MessageBroker()
|
|
self.workflow_executor = WorkflowExecutor()
|
|
self.logs: List[Dict[str, Any]] = []
|
|
|
|
def add_story(self, title: str, description: str, acceptance_criteria: List[str], story_points: int = 1) -> UserStory:
|
|
story = UserStory(
|
|
story_id=f"US-{len(self.sprint.stories) + 1}",
|
|
title=title,
|
|
description=description,
|
|
acceptance_criteria=acceptance_criteria,
|
|
story_points=story_points
|
|
)
|
|
self.sprint.stories.append(story)
|
|
return story
|
|
|
|
def plan_sprint_workflow(self, story: UserStory) -> Dict[str, Any]:
|
|
"""
|
|
Creates an optimized workflow DAG (Directed Acyclic Graph) for a user story:
|
|
1. PO & Architect define technical spec & contracts (Sequential)
|
|
2. Frontend & Backend developers work in parallel against the contract (Parallel)
|
|
3. QA executes tests and validates criteria (Sequential)
|
|
4. Code Reviewer audits against Definition of Done (Sequential)
|
|
"""
|
|
story_prefix = story.story_id
|
|
plan = {
|
|
"story_id": story.story_id,
|
|
"phases": [
|
|
{
|
|
"phase": "Architecture & Contracts",
|
|
"role": ScrumRole.TECH_LEAD.value,
|
|
"task_id": f"{story_prefix}_arch",
|
|
"depends_on": []
|
|
},
|
|
{
|
|
"phase": "Backend Implementation",
|
|
"role": ScrumRole.BACKEND_DEV.value,
|
|
"task_id": f"{story_prefix}_backend",
|
|
"depends_on": [f"{story_prefix}_arch"]
|
|
},
|
|
{
|
|
"phase": "Frontend Implementation",
|
|
"role": ScrumRole.FRONTEND_DEV.value,
|
|
"task_id": f"{story_prefix}_frontend",
|
|
"depends_on": [f"{story_prefix}_arch"]
|
|
},
|
|
{
|
|
"phase": "QA & Automated Testing",
|
|
"role": ScrumRole.QA_ENGINEER.value,
|
|
"task_id": f"{story_prefix}_qa",
|
|
"depends_on": [f"{story_prefix}_backend", f"{story_prefix}_frontend"]
|
|
},
|
|
{
|
|
"phase": "Code Review & Definition of Done",
|
|
"role": ScrumRole.CODE_REVIEWER.value,
|
|
"task_id": f"{story_prefix}_review",
|
|
"depends_on": [f"{story_prefix}_qa"]
|
|
}
|
|
]
|
|
}
|
|
return plan
|
|
|
|
def get_antigravity_subagent_specs(self) -> Dict[str, Dict[str, Any]]:
|
|
"""
|
|
Returns parameters ready for Antigravity's `define_subagent` and `invoke_subagent`.
|
|
"""
|
|
specs = {}
|
|
for role, persona in ScrumAgentPersona.PROMPTS.items():
|
|
specs[role.value] = {
|
|
"name": f"scrum-{role.value}",
|
|
"role": persona["title"],
|
|
"description": f"Scrum specialist responsible for {persona['title']}",
|
|
"system_prompt": persona["system_prompt"],
|
|
"enable_write_tools": role in [
|
|
ScrumRole.FRONTEND_DEV,
|
|
ScrumRole.BACKEND_DEV,
|
|
ScrumRole.QA_ENGINEER
|
|
],
|
|
"enable_subagent_tools": role == ScrumRole.SCRUM_MASTER
|
|
}
|
|
return specs
|