Solution architecture outcome pattern: agent and its MCP servers
Some checks failed
check agents / check (push) Failing after 13s
Some checks failed
check agents / check (push) Failing after 13s
The cp1-solution-architecture-agent and the sa-aws/azure/gcp-cloud MCP servers, a separate stream from the individual and sub-agent patterns. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
"""Builds the engine for one Cloud provider. The checkpoints, and everything an Execution
|
||||
writes, are on the shared execution volume, so any replica can take the next request.
|
||||
Nothing is read from the source's settings class: these come from the ConfigMap."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from app.core.providers import ProviderBundle, load_provider
|
||||
from app.engine.agent import AGENTS_DIR, ExecutionEngine
|
||||
from app.engine.checkpoints import VolumeSaver
|
||||
from app.engine.design_review import DesignCoverageReview
|
||||
from app.engine.local import TerraformRunner, local_tools
|
||||
from app.engine.recorder import InMemoryRecorder
|
||||
from app.engine.roles import COVERAGE_REVIEWER, REPLY_WRITER, load_roles
|
||||
from app.engine.router import Router, RuntimeReplyWriter
|
||||
from app.engine.runtime import NoDecider, RunLimiter
|
||||
from app.engine.schema_review import Reviews, SchemaReview
|
||||
from app.engine.toolkit import make_tool_factory
|
||||
from app.kab_runtime import KabRuntime
|
||||
from app.mcp_tools import McpCatalog
|
||||
from app.skills.agent_skills import discover_skills, skill_version
|
||||
|
||||
FOLDER = "solution-architecture"
|
||||
OVERLAYS = Path(__file__).resolve().parent.parent / "skills" / "overlays"
|
||||
|
||||
|
||||
def _on(name: str, default: bool = False) -> bool:
|
||||
return os.getenv(name, str(default)).strip().lower() in ("1", "true", "yes", "on")
|
||||
|
||||
|
||||
def output_root() -> Path:
|
||||
return Path(os.getenv("EXECUTION_STORAGE_ROOT") or "/tmp/executions") / FOLDER
|
||||
|
||||
|
||||
def _overlays(bundle: ProviderBundle) -> dict[str, Any]:
|
||||
folders = [OVERLAYS, *(Path(p) for p in os.getenv("OVERLAY_SKILLS_DIRS", "").split(",") if p)]
|
||||
found = discover_skills(folder for folder in folders if folder.is_dir())
|
||||
clash = sorted(set(found) & set(bundle.skills))
|
||||
if clash:
|
||||
raise ValueError(f"Overlay Skills reuse the names of provider Skills: {', '.join(clash)}")
|
||||
return found
|
||||
|
||||
|
||||
def assemble(
|
||||
provider: str,
|
||||
runtime: Any = None,
|
||||
*,
|
||||
use_scope: bool = True,
|
||||
confirm_drafts: bool | None = None,
|
||||
catalog: McpCatalog | None = None,
|
||||
) -> ExecutionEngine:
|
||||
bundle = load_provider(provider)
|
||||
overlays = _overlays(bundle)
|
||||
roles = load_roles(
|
||||
AGENTS_DIR,
|
||||
bundle,
|
||||
specialist_budget=int(os.getenv("SPECIALIST_BUDGET", "15")),
|
||||
lessons=_on("LESSONS_ENABLED", True),
|
||||
)
|
||||
root = output_root()
|
||||
runtime = runtime or KabRuntime(
|
||||
{name: meta.path for name, meta in {**bundle.skills, **overlays}.items()}
|
||||
)
|
||||
limiter = RunLimiter(int(os.getenv("MAX_PARALLEL_SPECIALISTS", "4")))
|
||||
catalog = catalog or McpCatalog(bundle, docs_search=_on("CLOUD_DOCS_SEARCH"))
|
||||
runner = TerraformRunner(
|
||||
binary=os.getenv("TERRAFORM_BINARY", "terraform"),
|
||||
timeout_seconds=float(os.getenv("TERRAFORM_TIMEOUT_SECONDS", "300")),
|
||||
providers=bundle.terraform_providers,
|
||||
module_namespaces=bundle.terraform_module_namespaces,
|
||||
)
|
||||
# `plan` needs a customer's credential, so it runs on an MCP server, not here.
|
||||
offered = [
|
||||
name
|
||||
for names in bundle.tools.values()
|
||||
for name in names
|
||||
if name != "terraform_plan"
|
||||
]
|
||||
# Each raises what it finds once and never blocks.
|
||||
reviews: list[Any] = [SchemaReview(runner)] if bundle.terraform_providers else []
|
||||
if _on("DESIGN_COVERAGE_REVIEW") and COVERAGE_REVIEWER in roles:
|
||||
reviews.append(DesignCoverageReview(runtime, roles[COVERAGE_REVIEWER]))
|
||||
return ExecutionEngine(
|
||||
runtime=runtime,
|
||||
roles=roles,
|
||||
recorder=InMemoryRecorder(),
|
||||
checkpointer=VolumeSaver(root / "checkpoints"),
|
||||
output_root=root,
|
||||
max_revisions=int(os.getenv("MAX_REVISIONS", "3")),
|
||||
tool_factory=make_tool_factory(
|
||||
runtime,
|
||||
roles,
|
||||
bundle.pillar_skills,
|
||||
local_tools=lambda working_copy: local_tools(offered, runner, working_copy),
|
||||
catalog=catalog,
|
||||
limiter=limiter,
|
||||
),
|
||||
limiter=limiter,
|
||||
skill_versions={name: skill_version(meta.path) for name, meta in bundle.skills.items()},
|
||||
orchestrator=Router(NoDecider(), RuntimeReplyWriter(runtime, roles[REPLY_WRITER])),
|
||||
submission_review=Reviews(reviews) if reviews else None,
|
||||
confirm_drafts=_on("CONFIRM_DRAFTS", True) if confirm_drafts is None else confirm_drafts,
|
||||
scope_catalogue=bundle.scope_catalogue() if use_scope and bundle.scope_skill else None,
|
||||
scope_values=bundle.scope_values,
|
||||
scope_skill=bundle.scope_skill,
|
||||
overlays={name: skill_version(meta.path) for name, meta in overlays.items()},
|
||||
modules_available=bool(bundle.terraform_module_namespaces),
|
||||
default_modules=_on("TERRAFORM_MODULES"),
|
||||
default_overlays=tuple(n for n in os.getenv("DEFAULT_OVERLAY_SKILLS", "").split(",") if n),
|
||||
contract=bundle.contract,
|
||||
)
|
||||
Reference in New Issue
Block a user