Some checks failed
validation / verify (push) Failing after 10s
A scope spec is a YAML file of what the customer wants and the facts a design depends on, complete or partly filled. It sits beside the Intent, which stays in the customer's words. - skills/scoping holds a provider-neutral catalogue of 63 fields; the Cloud provider's bundle supplies the values it allows for the fields left to it. - app/scope.py reads a spec against the catalogue with no model: it refuses an unknown field or a value of the wrong type, and yields what is stated, what is left to the agent, what is unknown and how pressing each gap is. A field may say ask, decide or not_applicable. - ExecutionEngine.start(scope=...), /generate, A2A metadata and evaluation cases accept one. Its statement is the request, its engagement reference names the Customer case, and its run options apply. A pre-approved start is refused when an essential field is not settled. - The spec as supplied is kept unaltered beside a completed copy with assumptions, gaps, provenance, readiness and a status. - Every Specialist is shown the spec and given the Skill: a stated choice binds, exclusions are out of scope. - Covers workloads and platform foundations; case-08-landing-zone starts from a benchmark spec. Plans for scoping (iteration 9) and the work breakdown structure (iteration 10, nothing built), and the design spec they come from. Not run with real models. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
137 lines
4.9 KiB
Python
137 lines
4.9 KiB
Python
"""The A2A server: JSON-RPC at /a2a, the agent card, health, and pre-approved /generate.
|
|
|
|
Run with: python -m app.main
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from collections.abc import AsyncIterator, Callable
|
|
from contextlib import AbstractAsyncContextManager, asynccontextmanager
|
|
|
|
import click
|
|
import uvicorn
|
|
from a2a.server.request_handlers.default_request_handler_v2 import (
|
|
DefaultRequestHandlerV2,
|
|
)
|
|
from a2a.server.routes.agent_card_routes import create_agent_card_routes
|
|
from a2a.server.routes.jsonrpc_routes import create_jsonrpc_routes
|
|
from a2a.server.tasks import InMemoryTaskStore
|
|
from a2a.utils.constants import AGENT_CARD_WELL_KNOWN_PATH
|
|
from starlette.applications import Starlette
|
|
from starlette.requests import Request
|
|
from starlette.responses import JSONResponse
|
|
from starlette.routing import Route
|
|
|
|
from app.a2a_server import SolutionArchitectExecutor
|
|
from app.agent import Assembly, open_assembly
|
|
from app.card import A2A_PATH, build_agent_card
|
|
from app.config import Settings, get_settings
|
|
from app.presentation import to_generate_response
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
AssemblyFactory = Callable[[Settings], AbstractAsyncContextManager[Assembly]]
|
|
LEGACY_CARD_PATH = "/.well-known/agent.json"
|
|
|
|
|
|
def create_app(
|
|
settings: Settings | None = None,
|
|
assembly_factory: AssemblyFactory = open_assembly,
|
|
) -> Starlette:
|
|
settings = settings or get_settings()
|
|
card = build_agent_card(settings)
|
|
|
|
async def health(request: Request) -> JSONResponse:
|
|
assembly: Assembly = request.app.state.assembly
|
|
return JSONResponse(
|
|
{
|
|
"status": "healthy",
|
|
"agent": settings.AGENT_NAME,
|
|
"version": settings.AGENT_VERSION,
|
|
"cloud_provider": assembly.bundle.name,
|
|
"mcp_discovery_gaps": assembly.mcp_gaps,
|
|
}
|
|
)
|
|
|
|
async def generate(request: Request) -> JSONResponse:
|
|
"""Pre-approved, one-shot Execution for batch and evaluation callers."""
|
|
assembly: Assembly = request.app.state.assembly
|
|
try:
|
|
body = await request.json()
|
|
except ValueError:
|
|
body = {}
|
|
workflow_request = str(body.get("request") or "").strip()
|
|
if not workflow_request and not body.get("scope"):
|
|
return JSONResponse(
|
|
{"error": "'request' or a 'scope' spec is required"}, status_code=400
|
|
)
|
|
try:
|
|
interaction = await assembly.engine.start(
|
|
workflow_request,
|
|
session_id=body.get("session_id"),
|
|
customer_case=body.get("customer_case"),
|
|
baseline=body.get("baseline"),
|
|
overlay_skills=body.get("overlay_skills") or (),
|
|
terraform_modules=body.get("terraform_modules"),
|
|
scope=body.get("scope"),
|
|
pre_approved=True,
|
|
allow_cloud_read=bool(body.get("allow_cloud_read", False)),
|
|
)
|
|
except ValueError as exc:
|
|
return JSONResponse({"error": str(exc)}, status_code=400)
|
|
except Exception as exc:
|
|
logger.exception("/generate failed")
|
|
return JSONResponse(
|
|
{"error": f"{type(exc).__name__}: {exc}"}, status_code=500
|
|
)
|
|
return JSONResponse(to_generate_response(interaction, assembly.roles))
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: Starlette) -> AsyncIterator[None]:
|
|
async with assembly_factory(settings) as assembly:
|
|
handler = DefaultRequestHandlerV2(
|
|
agent_executor=SolutionArchitectExecutor(
|
|
assembly.engine, assembly.intake, assembly.answers
|
|
),
|
|
task_store=InMemoryTaskStore(),
|
|
agent_card=card,
|
|
)
|
|
app.state.assembly = assembly
|
|
app.state.request_handler = handler
|
|
app.router.routes.extend(
|
|
create_jsonrpc_routes(handler, A2A_PATH, enable_v0_3_compat=True)
|
|
)
|
|
try:
|
|
yield
|
|
finally:
|
|
await handler.aclose()
|
|
|
|
return Starlette(
|
|
routes=[
|
|
Route("/health", health, methods=["GET"]),
|
|
Route("/generate", generate, methods=["POST"]),
|
|
*create_agent_card_routes(card, card_url=AGENT_CARD_WELL_KNOWN_PATH),
|
|
*create_agent_card_routes(card, card_url=LEGACY_CARD_PATH),
|
|
],
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
|
|
@click.command()
|
|
@click.option("--host", default=None, help="Host to bind (default A2A_HOST)")
|
|
@click.option("--port", default=None, type=int, help="Port (default A2A_PORT)")
|
|
def main(host: str | None, port: int | None) -> None:
|
|
"""Serve the solution architect agent over A2A."""
|
|
settings = get_settings()
|
|
logging.basicConfig(level=settings.LOG_LEVEL.upper())
|
|
uvicorn.run(
|
|
create_app(settings),
|
|
host=host or settings.A2A_HOST,
|
|
port=port or settings.A2A_PORT,
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|