Files
gcp_solution_architecture_a…/app/assembly.py
Jonathan Boniface ad371b2ec4 feat: serve Executions over A2A with a pre-approved /generate
Increment 7 of .scratch/solution-architect-agent/spec.md.

- app/assembly.py: composition root building the engine from settings
  and the provider bundle (roles, ADK runtime, MCP catalog, Terraform
  tools, checkpointer, recorder).
- app/a2a: a2a-sdk 1.1 JSON-RPC server (v0.3 compatible) mapping tasks to
  Executions; questions, Approvals and permissions pause as
  input-required; Approvals accepted only as structured data; completed
  tasks return the guide and code as artifacts; agent card derived from
  the dependency graph.
- POST /generate runs a pre-approved Execution with the legacy keys.
- Specialist exceptions are relayed to the user; Orchestrator exceptions
  fail the task. Engine accepts a caller-chosen execution id.
- Dockerfile installs checksum-verified Terraform and ships agents,
  providers and skills; add mcp and a2a-sdk requirements.
- 17 new tests; full suite 206 passed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-16 10:23:24 +01:00

93 lines
3.1 KiB
Python

"""Composition root: build the Execution engine from settings and the provider bundle.
The only place concrete runtimes, tools, checkpointers and recorders are chosen.
"""
from __future__ import annotations
from collections.abc import AsyncIterator
from contextlib import asynccontextmanager
from dataclasses import dataclass
from pathlib import Path
from app.agents.roles import load_roles
from app.agents.runtime import AgentRuntime, RoleSpec
from app.config import Settings
from app.execution.checkpointing import open_checkpointer
from app.execution.engine import ExecutionEngine
from app.execution.recorder import DatabaseRecorder, ExecutionRecorder
from app.execution.toolkit import make_tool_factory
from app.providers import ProviderBundle, load_provider
from app.tools.local import TerraformRunner, local_tools
from app.tools.mcp import McpCatalog, auth_from_config
AGENTS_DIR = Path(__file__).resolve().parent.parent / "agents"
@dataclass(frozen=True)
class Assembly:
engine: ExecutionEngine
bundle: ProviderBundle
roles: dict[str, RoleSpec]
mcp_gaps: dict[str, str]
@asynccontextmanager
async def open_assembly(
settings: Settings,
*,
runtime: AgentRuntime | None = None,
recorder: ExecutionRecorder | None = None,
output_root: Path | None = None,
) -> AsyncIterator[Assembly]:
bundle = load_provider(settings.CLOUD_PROVIDER)
roles = load_roles(
AGENTS_DIR,
bundle,
orchestrator_budget=settings.ORCHESTRATOR_BUDGET,
specialist_budget=settings.SPECIALIST_BUDGET,
include_preview_mcp=settings.MCP_ENABLE_PREVIEW,
)
if runtime is None:
from app.agents.adk_runtime import AdkAgentRuntime
runtime = AdkAgentRuntime(
skill_dirs={name: meta.path for name, meta in bundle.skills.items()}
)
catalog = McpCatalog()
if settings.MCP_ENABLED:
used = {server_id for role in roles.values() for server_id in role.mcp_servers}
catalog = await McpCatalog.load(
[bundle.mcp_servers[server_id] for server_id in sorted(used)],
auth_from_config(bundle.mcp_auth, settings.MCP_QUOTA_PROJECT),
timeout=settings.MCP_TIMEOUT_SECONDS,
)
runner = TerraformRunner(
binary=settings.TERRAFORM_BINARY,
timeout_seconds=settings.TERRAFORM_TIMEOUT_SECONDS,
plugin_cache_dir=settings.TF_PLUGIN_CACHE_DIR,
)
offered = [name for names in bundle.tools.values() for name in names]
tool_factory = make_tool_factory(
runtime,
roles,
bundle.pillar_skills,
local_tools=local_tools(offered, runner),
catalog=catalog,
)
async with open_checkpointer(settings) as checkpointer:
engine = ExecutionEngine(
runtime=runtime,
roles=roles,
recorder=recorder or DatabaseRecorder(),
checkpointer=checkpointer,
output_root=output_root or settings.BASE_DIR,
max_revisions=settings.MAX_REVISIONS,
max_orchestrator_turns=settings.MAX_ORCHESTRATOR_TURNS,
tool_factory=tool_factory,
)
yield Assembly(engine, bundle, roles, dict(catalog.gaps))