This commit is contained in:
@@ -1,5 +1 @@
|
||||
"""Workflows package."""
|
||||
|
||||
from .gcp_architecture_graph import create_agent, create_gcp_architecture_graph
|
||||
|
||||
__all__ = ["create_agent", "create_gcp_architecture_graph"]
|
||||
"""The Execution graph and the dependency graph of Deliverables it runs."""
|
||||
|
||||
198
app/workflows/deliverables.py
Normal file
198
app/workflows/deliverables.py
Normal file
@@ -0,0 +1,198 @@
|
||||
"""The dependency graph of Deliverables, grouped into Phases.
|
||||
|
||||
This is the only place Phases, Deliverables and Dependencies are declared. Section
|
||||
names are provider-neutral; they match the numbered headings of a Cloud provider's
|
||||
solution-guide template by suffix (e.g. "Products and features mapping" matches
|
||||
"4.1. Google Cloud products and features mapping").
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from collections.abc import Mapping
|
||||
from dataclasses import dataclass
|
||||
from enum import StrEnum
|
||||
|
||||
|
||||
class PhaseId(StrEnum):
|
||||
REQUIREMENTS_DISCOVERY = "requirements_discovery"
|
||||
SOLUTION_ARCHITECTURE = "solution_architecture"
|
||||
SOLUTION_VALIDATION = "solution_validation"
|
||||
PACKAGING = "packaging"
|
||||
|
||||
|
||||
PHASE_ORDER: tuple[PhaseId, ...] = tuple(PhaseId)
|
||||
|
||||
|
||||
class DeliverableKind(StrEnum):
|
||||
REQUIREMENTS = "requirements"
|
||||
TECHNICAL_DECOMPOSITION = "technical_decomposition"
|
||||
PRODUCT_SELECTION = "product_selection"
|
||||
ARCHITECTURE_DIAGRAM = "architecture_diagram"
|
||||
ARCHITECTURE_DESCRIPTION = "architecture_description"
|
||||
DESIGN_RECOMMENDATIONS = "design_recommendations"
|
||||
DEPLOYMENT_GUIDANCE = "deployment_guidance"
|
||||
VALIDATION_RESULTS = "validation_results"
|
||||
SOLUTION_GUIDE = "solution_guide"
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class DeliverableSpec:
|
||||
kind: DeliverableKind
|
||||
phase: PhaseId
|
||||
specialist: str
|
||||
depends_on: tuple[DeliverableKind, ...] = ()
|
||||
sections: tuple[str, ...] = ()
|
||||
attachments: tuple[str, ...] = ()
|
||||
|
||||
|
||||
_K = DeliverableKind
|
||||
|
||||
DEPENDENCY_GRAPH: Mapping[DeliverableKind, DeliverableSpec] = {
|
||||
spec.kind: spec
|
||||
for spec in (
|
||||
DeliverableSpec(
|
||||
_K.REQUIREMENTS,
|
||||
PhaseId.REQUIREMENTS_DISCOVERY,
|
||||
"requirements-analyst",
|
||||
sections=(
|
||||
"Functional requirements",
|
||||
"Non-functional requirements",
|
||||
"Current state",
|
||||
"Dependencies",
|
||||
),
|
||||
),
|
||||
DeliverableSpec(
|
||||
_K.TECHNICAL_DECOMPOSITION,
|
||||
PhaseId.REQUIREMENTS_DISCOVERY,
|
||||
"decomposer",
|
||||
depends_on=(_K.REQUIREMENTS,),
|
||||
),
|
||||
DeliverableSpec(
|
||||
_K.PRODUCT_SELECTION,
|
||||
PhaseId.SOLUTION_ARCHITECTURE,
|
||||
"product-selector",
|
||||
depends_on=(_K.TECHNICAL_DECOMPOSITION,),
|
||||
sections=("Products and features mapping",),
|
||||
),
|
||||
DeliverableSpec(
|
||||
_K.ARCHITECTURE_DIAGRAM,
|
||||
PhaseId.SOLUTION_ARCHITECTURE,
|
||||
"diagrammer",
|
||||
depends_on=(_K.PRODUCT_SELECTION,),
|
||||
attachments=("architecture.mmd",),
|
||||
),
|
||||
DeliverableSpec(
|
||||
_K.ARCHITECTURE_DESCRIPTION,
|
||||
PhaseId.SOLUTION_ARCHITECTURE,
|
||||
"describer",
|
||||
depends_on=(_K.ARCHITECTURE_DIAGRAM, _K.PRODUCT_SELECTION),
|
||||
),
|
||||
DeliverableSpec(
|
||||
_K.DESIGN_RECOMMENDATIONS,
|
||||
PhaseId.SOLUTION_ARCHITECTURE,
|
||||
"design-advisor",
|
||||
depends_on=(_K.PRODUCT_SELECTION, _K.REQUIREMENTS),
|
||||
sections=(
|
||||
"Security, privacy, and compliance",
|
||||
"Reliability",
|
||||
"Operational excellence",
|
||||
"Cost optimization",
|
||||
"Performance efficiency",
|
||||
"Sustainability",
|
||||
),
|
||||
),
|
||||
DeliverableSpec(
|
||||
_K.DEPLOYMENT_GUIDANCE,
|
||||
PhaseId.SOLUTION_ARCHITECTURE,
|
||||
"iac-author",
|
||||
depends_on=(_K.PRODUCT_SELECTION, _K.DESIGN_RECOMMENDATIONS),
|
||||
sections=(
|
||||
"Deployment prerequisites",
|
||||
"Step-by-step deployment instructions",
|
||||
),
|
||||
attachments=("terraform/main.tf", "terraform/variables.tf"),
|
||||
),
|
||||
DeliverableSpec(
|
||||
_K.VALIDATION_RESULTS,
|
||||
PhaseId.SOLUTION_VALIDATION,
|
||||
"validator",
|
||||
depends_on=(_K.DEPLOYMENT_GUIDANCE,),
|
||||
sections=("Deployment dry-run", "Architecture and policy analysis"),
|
||||
),
|
||||
DeliverableSpec(
|
||||
_K.SOLUTION_GUIDE,
|
||||
PhaseId.PACKAGING,
|
||||
"packager",
|
||||
depends_on=(_K.VALIDATION_RESULTS,),
|
||||
sections=(
|
||||
"Executive summary and workload overview",
|
||||
"Requirements and current state",
|
||||
"Technical decomposition of the workload",
|
||||
"Proposed solution architecture",
|
||||
"Design and configuration recommendations",
|
||||
"Deployment guidance",
|
||||
"Validation plan",
|
||||
"References",
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
def inputs_of(kind: DeliverableKind) -> tuple[DeliverableKind, ...]:
|
||||
"""The Deliverables a Specialist works from, in graph order.
|
||||
|
||||
Every Deliverable in an earlier Phase (all approved by the time `kind` is ready),
|
||||
plus everything `kind` depends on, directly or not, within its own Phase.
|
||||
"""
|
||||
spec = DEPENDENCY_GRAPH[kind]
|
||||
earlier_phases = PHASE_ORDER[: PHASE_ORDER.index(spec.phase)]
|
||||
upstream: set[DeliverableKind] = set()
|
||||
frontier = set(DEPENDENCY_GRAPH[kind].depends_on)
|
||||
while frontier:
|
||||
upstream |= frontier
|
||||
frontier = {
|
||||
dependency
|
||||
for item in frontier
|
||||
for dependency in DEPENDENCY_GRAPH[item].depends_on
|
||||
} - upstream
|
||||
return tuple(
|
||||
candidate
|
||||
for candidate, candidate_spec in DEPENDENCY_GRAPH.items()
|
||||
if candidate in upstream or candidate_spec.phase in earlier_phases
|
||||
)
|
||||
|
||||
|
||||
def deliverables_in(phase: PhaseId) -> tuple[DeliverableKind, ...]:
|
||||
return tuple(kind for kind, spec in DEPENDENCY_GRAPH.items() if spec.phase is phase)
|
||||
|
||||
|
||||
_HEADING = re.compile(r"^ {0,3}#{1,6}\s+(.+?)\s*#*\s*$", re.MULTILINE)
|
||||
_NUMBERING = re.compile(r"^\d+(?:\.\d+)*\.?\s+")
|
||||
_TRAILING = re.compile(r"[\s:.\-–—]+$")
|
||||
|
||||
|
||||
def _normalise(text: str) -> str:
|
||||
text = _NUMBERING.sub("", text.strip().lower())
|
||||
return " ".join(_TRAILING.sub("", text).split())
|
||||
|
||||
|
||||
def check_submission(
|
||||
kind: DeliverableKind, content: str, attachments: Mapping[str, str]
|
||||
) -> tuple[str, ...]:
|
||||
"""Return what a submission lacks against its contract; empty means it's complete."""
|
||||
if not content.strip():
|
||||
return ("content: must not be empty",)
|
||||
|
||||
spec = DEPENDENCY_GRAPH[kind]
|
||||
headings = [_normalise(match) for match in _HEADING.findall(content)]
|
||||
missing = []
|
||||
for section in spec.sections:
|
||||
required = _normalise(section)
|
||||
if not any(h == required or h.endswith(" " + required) for h in headings):
|
||||
missing.append(f"section: {section}")
|
||||
for name in spec.attachments:
|
||||
if name not in attachments:
|
||||
missing.append(f"attachment: {name}")
|
||||
return tuple(missing)
|
||||
56
app/workflows/execution_graph.py
Normal file
56
app/workflows/execution_graph.py
Normal file
@@ -0,0 +1,56 @@
|
||||
"""The LangGraph that holds an Execution (ADR-0003).
|
||||
|
||||
START -> orchestrator_turn
|
||||
orchestrator_turn -> specialist_task x N (Send, parallel) -> orchestrator_turn
|
||||
orchestrator_turn -> await_user (interrupt) -> orchestrator_turn
|
||||
orchestrator_turn -> finalize -> END
|
||||
orchestrator_turn -> end_with_warnings -> END
|
||||
|
||||
The nodes live in app/nodes/execution_nodes.py; they route with Command and Send, so
|
||||
only the fixed edges are declared here.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping
|
||||
from pathlib import Path
|
||||
from typing import Any, cast
|
||||
|
||||
from langgraph.graph import END, START, StateGraph
|
||||
|
||||
from app.adk.runtime import AgentRuntime, RoleSpec, ToolFactory
|
||||
from app.nodes.execution_nodes import make_execution_nodes
|
||||
from app.recorder import ExecutionRecorder
|
||||
from app.states.execution_state import ExecutionState
|
||||
|
||||
|
||||
def build_execution_graph(
|
||||
*,
|
||||
runtime: AgentRuntime,
|
||||
roles: Mapping[str, RoleSpec],
|
||||
recorder: ExecutionRecorder,
|
||||
output_root: Path,
|
||||
max_orchestrator_turns: int = 100,
|
||||
tool_factory: ToolFactory | None = None,
|
||||
) -> StateGraph:
|
||||
nodes = make_execution_nodes(
|
||||
runtime=runtime,
|
||||
roles=roles,
|
||||
recorder=recorder,
|
||||
output_root=output_root,
|
||||
max_orchestrator_turns=max_orchestrator_turns,
|
||||
tool_factory=tool_factory,
|
||||
)
|
||||
|
||||
graph = StateGraph(ExecutionState)
|
||||
graph.add_node("orchestrator_turn", cast(Any, nodes.orchestrator_turn))
|
||||
# Specialist tasks receive their Send payload, not the Execution state.
|
||||
graph.add_node("specialist_task", cast(Any, nodes.specialist_task))
|
||||
graph.add_node("await_user", cast(Any, nodes.await_user))
|
||||
graph.add_node("finalize", cast(Any, nodes.finalize))
|
||||
graph.add_node("end_with_warnings", cast(Any, nodes.end_with_warnings))
|
||||
graph.add_edge(START, "orchestrator_turn")
|
||||
graph.add_edge("specialist_task", "orchestrator_turn")
|
||||
graph.add_edge("finalize", END)
|
||||
graph.add_edge("end_with_warnings", END)
|
||||
return graph
|
||||
@@ -1,61 +0,0 @@
|
||||
"""Dynamic LangGraph StateGraph Factory with Skill Injection."""
|
||||
|
||||
import logging
|
||||
from typing import Any, Callable
|
||||
from langgraph.graph import END, START, StateGraph
|
||||
from langgraph.graph.state import CompiledStateGraph
|
||||
|
||||
from app.config import get_settings
|
||||
from app.nodes import design_node, discover_node, package_node, source_discover_node, validate_node
|
||||
from app.skills.loader import SkillLoader
|
||||
from app.states.state import GCPArchitectureState
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def create_gcp_architecture_graph(skill_loader: SkillLoader | None = None) -> CompiledStateGraph:
|
||||
"""Creates and compiles the LangGraph StateGraph with dynamic local skill injection."""
|
||||
if skill_loader is None:
|
||||
settings = get_settings()
|
||||
skill_loader = SkillLoader(settings.SKILLS_DIR)
|
||||
skill_loader.load_skills()
|
||||
|
||||
builder = StateGraph(GCPArchitectureState)
|
||||
|
||||
# Wrap nodes with skill loader injection
|
||||
def run_source_discover(state: GCPArchitectureState) -> dict[str, Any]:
|
||||
return source_discover_node(state, skill_loader)
|
||||
|
||||
def run_discover(state: GCPArchitectureState) -> dict[str, Any]:
|
||||
return discover_node(state, skill_loader)
|
||||
|
||||
def run_design(state: GCPArchitectureState) -> dict[str, Any]:
|
||||
return design_node(state, skill_loader)
|
||||
|
||||
def run_validate(state: GCPArchitectureState) -> dict[str, Any]:
|
||||
return validate_node(state, skill_loader)
|
||||
|
||||
def run_package(state: GCPArchitectureState) -> dict[str, Any]:
|
||||
return package_node(state, skill_loader)
|
||||
|
||||
# Add graph nodes
|
||||
builder.add_node("source_discover", run_source_discover)
|
||||
builder.add_node("discover", run_discover)
|
||||
builder.add_node("design", run_design)
|
||||
builder.add_node("validate", run_validate)
|
||||
builder.add_node("package", run_package)
|
||||
|
||||
# Add sequential workflow edges
|
||||
builder.add_edge(START, "source_discover")
|
||||
builder.add_edge("source_discover", "discover")
|
||||
builder.add_edge("discover", "design")
|
||||
builder.add_edge("design", "validate")
|
||||
builder.add_edge("validate", "package")
|
||||
builder.add_edge("package", END)
|
||||
|
||||
return builder.compile()
|
||||
|
||||
|
||||
def create_agent(skill_loader: SkillLoader | None = None) -> CompiledStateGraph:
|
||||
"""Alias for create_gcp_architecture_graph to support standardized agent creation."""
|
||||
return create_gcp_architecture_graph(skill_loader)
|
||||
@@ -1,89 +0,0 @@
|
||||
"""Starlette REST Route Handlers for GCP Solution Architecture Agent.
|
||||
|
||||
Powered by Google ADK runner, PostgreSQL database persistence, and multi-agent orchestration.
|
||||
"""
|
||||
|
||||
import logging
|
||||
from typing import Any, Dict
|
||||
from starlette.requests import Request
|
||||
from starlette.responses import JSONResponse
|
||||
|
||||
from app.adk.evaluation import ADKEvaluator
|
||||
from app.adk.runners import ADKAgentRunner
|
||||
from app.adk.sessions import PostgresSessionService
|
||||
from app.card import AGENT_CARD
|
||||
from app.config import get_settings
|
||||
from app.tools.validation_tools import validate_repository_artifacts
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def health_check(request: Request) -> JSONResponse:
|
||||
"""GET /health - Operational health endpoint."""
|
||||
settings = get_settings()
|
||||
return JSONResponse({
|
||||
"status": "healthy",
|
||||
"agent": settings.AGENT_NAME,
|
||||
"version": settings.AGENT_VERSION,
|
||||
"adk_framework": "enabled",
|
||||
"database": "postgresql",
|
||||
})
|
||||
|
||||
|
||||
async def get_card(request: Request) -> JSONResponse:
|
||||
"""GET /card - Agent metadata and capability card."""
|
||||
return JSONResponse(AGENT_CARD)
|
||||
|
||||
|
||||
async def run_workflow(request: Request) -> JSONResponse:
|
||||
"""POST /generate - Execute multi-agent ADK workflow with PostgreSQL persistence."""
|
||||
try:
|
||||
body = await request.json() if request.headers.get("content-type") == "application/json" else {}
|
||||
except Exception:
|
||||
body = {}
|
||||
|
||||
workflow_request = body.get("request", "Default event-driven HTTP architecture")
|
||||
target_dir = body.get("target_dir", ".")
|
||||
session_id = body.get("session_id")
|
||||
|
||||
runner = ADKAgentRunner()
|
||||
result = runner.run_execution(
|
||||
session_id=session_id,
|
||||
request_summary=workflow_request,
|
||||
target_dir=target_dir,
|
||||
)
|
||||
|
||||
return JSONResponse(result)
|
||||
|
||||
|
||||
async def get_session_route(request: Request) -> JSONResponse:
|
||||
"""GET /sessions/{session_id} - Query session state from PostgreSQL database."""
|
||||
session_id = request.path_params.get("session_id")
|
||||
session_service = PostgresSessionService()
|
||||
session = session_service.get_session(session_id)
|
||||
|
||||
if not session:
|
||||
return JSONResponse({"error": f"Session {session_id} not found"}, status_code=404)
|
||||
|
||||
return JSONResponse({
|
||||
"session_id": session.session_id,
|
||||
"agent_name": session.agent_name,
|
||||
"state": session.state,
|
||||
})
|
||||
|
||||
|
||||
async def validate_artifacts_route(request: Request) -> JSONResponse:
|
||||
"""POST /validate - Run pre-deployment validation checks against target directory."""
|
||||
try:
|
||||
body = await request.json() if request.headers.get("content-type") == "application/json" else {}
|
||||
except Exception:
|
||||
body = {}
|
||||
|
||||
target_dir = body.get("target_dir", ".")
|
||||
result = validate_repository_artifacts.invoke({"target_dir": target_dir})
|
||||
|
||||
status_code = 200 if result.get("valid") else 400
|
||||
return JSONResponse(result, status_code=status_code)
|
||||
|
||||
status_code = 200 if result.get("valid") else 400
|
||||
return JSONResponse(result, status_code=status_code)
|
||||
Reference in New Issue
Block a user