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>
This commit is contained in:
@@ -5,6 +5,7 @@ Driven entirely through ExecutionEngine.start/resume with a scripted agent runti
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from langgraph.checkpoint.memory import InMemorySaver
|
||||
from langgraph.checkpoint.sqlite.aio import AsyncSqliteSaver
|
||||
|
||||
@@ -629,3 +630,34 @@ async def test_paused_execution_resumes_from_a_durable_checkpoint(tmp_path):
|
||||
"questions": [{"from": "orchestrator", "question": "Resumed"}]
|
||||
}
|
||||
assert resumed.state["ledger"]["phases"]["requirements_discovery"] == "approved"
|
||||
|
||||
|
||||
# --- identity and failures ------------------------------------------------------------------
|
||||
|
||||
|
||||
async def test_caller_can_choose_the_execution_id_once(tmp_path):
|
||||
runtime = FakeAgentRuntime({"orchestrator": [[ask_user("Hello?")]]})
|
||||
engine = make_engine(tmp_path, runtime)
|
||||
|
||||
first = await engine.start("Ingestion", execution_id="task-123")
|
||||
|
||||
assert first.execution_id == "task-123"
|
||||
with pytest.raises(ValueError, match="task-123"):
|
||||
await engine.start("Again", execution_id="task-123")
|
||||
|
||||
|
||||
async def test_a_failing_specialist_is_relayed_to_the_user_as_a_question(tmp_path):
|
||||
class Failing(FakeAgentRuntime):
|
||||
async def run(self, role, task, tools):
|
||||
if role.name == specialist(K.REQUIREMENTS):
|
||||
raise RuntimeError("model API unavailable")
|
||||
return await super().run(role, task, tools)
|
||||
|
||||
runtime = Failing({"orchestrator": [[delegate(K.REQUIREMENTS)], [ask_user()]]})
|
||||
|
||||
result = await make_engine(tmp_path, runtime).start("Ingestion")
|
||||
|
||||
[question] = result.prompt["questions"]
|
||||
assert question["from"] == "requirements"
|
||||
assert "model API unavailable" in question["question"]
|
||||
assert result.state["ledger"]["deliverables"]["requirements"]["status"] == "pending"
|
||||
|
||||
76
tests/execution/test_presentation.py
Normal file
76
tests/execution/test_presentation.py
Normal file
@@ -0,0 +1,76 @@
|
||||
"""Prompt text for plain clients and the /generate response mapping."""
|
||||
|
||||
import json
|
||||
|
||||
from app.execution.engine import Interaction
|
||||
from app.execution.presentation import describe_prompt, to_generate_response
|
||||
|
||||
|
||||
def test_approval_prompt_explains_the_structured_reply():
|
||||
text = describe_prompt(
|
||||
{
|
||||
"approval": {
|
||||
"phase": "solution_architecture",
|
||||
"summary": "Cloud Run and Pub/Sub",
|
||||
"deliverables": ["product_selection", "architecture_diagram"],
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
reply = {"approval": {"phase": "solution_architecture", "decision": "approve"}}
|
||||
assert json.dumps(reply) in text
|
||||
assert "never approves" in text
|
||||
|
||||
|
||||
def test_questions_are_numbered_with_their_source():
|
||||
text = describe_prompt(
|
||||
{
|
||||
"questions": [
|
||||
{"from": "requirements", "question": "RTO?"},
|
||||
{"from": "orchestrator", "question": "Region?"},
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
assert text.startswith("1. (requirements) RTO?\n2. (orchestrator) Region?")
|
||||
|
||||
|
||||
def test_generate_response_maps_deliverables_onto_legacy_artifacts():
|
||||
requirements = (
|
||||
"# Requirements\n## 2.3. Current state\nThree VMs.\n### Detail\nNginx.\n"
|
||||
"## Dependencies\nNone.\n"
|
||||
)
|
||||
interaction = Interaction(
|
||||
"exec-1",
|
||||
"completed_with_warnings",
|
||||
None,
|
||||
{
|
||||
"session_id": "s-1",
|
||||
"warnings": ["revision limit"],
|
||||
"deliverables": {
|
||||
"requirements": {"content": requirements, "attachments": {}},
|
||||
"deployment_guidance": {
|
||||
"content": "# Guide",
|
||||
"attachments": {"terraform/main.tf": "resource {}"},
|
||||
},
|
||||
},
|
||||
"ledger": {
|
||||
"deliverables": {"requirements": {"revisions": 2}},
|
||||
"phases": {
|
||||
"requirements_discovery": "approved",
|
||||
"solution_architecture": "open",
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
body = to_generate_response(interaction, {})
|
||||
|
||||
assert body["status"] == "completed_with_warnings"
|
||||
assert body["validation_passed"] is False
|
||||
assert body["total_loop_iterations"] == 3
|
||||
assert body["current_phase"] == "solution_architecture"
|
||||
assert body["artifacts"]["source_discovery_doc"] == "Three VMs.\n### Detail\nNginx."
|
||||
assert body["artifacts"]["terraform_code"] == "resource {}"
|
||||
assert body["artifacts"]["solution_guide"] is None
|
||||
assert body["warnings"] == ["revision limit"]
|
||||
Reference in New Issue
Block a user