feat: run role files on the ADK runtime with scoped Skills

Increment 5 of .scratch/solution-architect-agent/spec.md, test-first.

- agents/*.md: provider-neutral role files for the Orchestrator, nine
  Specialists and the pillar advisor, with a shared Specialist protocol.
- app/agents/roles.py: load and validate role files; Skills, MCP
  servers and models come from the provider bundle.
- app/agents/adk_runtime.py: AgentRuntime on google-adk 2.9 with a
  per-run LlmAgent, role-scoped SkillToolset (no run_skill_script),
  step budgets, early stop on turn-ending tools, LiteLLM models.
- app/execution/pillars.py + toolkit.py: design advisor fans out to one
  advisor per WAF pillar in parallel.
- Specialists receive every earlier-Phase Deliverable as input.
- Bundle gains role_skills, pillar_skills and -latest Gemini aliases;
  pin google-adk[extensions]==2.9.0.
- 37 new tests; full suite 158 passed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-16 09:51:02 +01:00
parent d9214c671a
commit f040493583
31 changed files with 1431 additions and 17 deletions

View File

@@ -0,0 +1,121 @@
"""The Execution engine running real role files on the ADK runtime, with scripted models."""
import json
from collections.abc import AsyncGenerator
from pathlib import Path
import pytest
from google.adk.models.base_llm import BaseLlm
from google.adk.models.llm_request import LlmRequest
from google.adk.models.llm_response import LlmResponse
from google.genai import types
from langgraph.checkpoint.memory import InMemorySaver
from pydantic import Field
from app.agents.adk_runtime import AdkAgentRuntime
from app.agents.roles import load_roles
from app.execution.deliverables import DEPENDENCY_GRAPH, DeliverableKind
from app.execution.engine import ExecutionEngine
from app.execution.recorder import InMemoryRecorder
from app.execution.toolkit import make_tool_factory
from app.providers import load_provider
pytestmark = pytest.mark.asyncio
AGENTS_DIR = Path(__file__).parents[2] / "agents"
class RoleScriptedLlm(BaseLlm):
"""One scripted response per model call, keyed by the agent's role."""
model: str = "scripted"
script: list = Field(default_factory=list)
requests: list = Field(default_factory=list)
async def generate_content_async(
self, llm_request: LlmRequest, stream: bool = False
) -> AsyncGenerator[LlmResponse, None]:
self.requests.append(llm_request)
parts = self.script.pop(0)
yield LlmResponse(content=types.Content(role="model", parts=parts))
def call(tool: str, **args) -> list[types.Part]:
return [types.Part(function_call=types.FunctionCall(name=tool, args=args))]
def requirements_markdown() -> str:
sections = DEPENDENCY_GRAPH[DeliverableKind.REQUIREMENTS].sections
return "\n".join(f"## {section}\nDetails." for section in sections)
def task_context(request: LlmRequest) -> dict:
text = request.contents[0].parts[0].text
return json.loads(text.split("```json\n", 1)[1].rsplit("\n```", 1)[0])
async def test_engine_runs_role_files_through_adk_with_one_voice(tmp_path):
bundle = load_provider("gcp")
roles = load_roles(AGENTS_DIR, bundle)
models = {
"orchestrator": RoleScriptedLlm(
script=[
call("delegate", kinds=["requirements"]),
call("ask_user", questions=[]),
call("delegate", kinds=["requirements"]),
call("ask_user", questions=["Anything to add?"]),
]
),
"requirements-analyst": RoleScriptedLlm(
script=[
call("load_skill", skill_name="google-cloud-solution-architecture"),
call(
"needs_input", questions=["What availability target do you need?"]
),
call("submit_deliverable", content=requirements_markdown()),
]
),
}
runtime = AdkAgentRuntime(
skill_dirs={name: meta.path for name, meta in bundle.skills.items()},
model_factory=lambda role: models[role.name],
)
engine = ExecutionEngine(
runtime=runtime,
roles=roles,
recorder=InMemoryRecorder(),
checkpointer=InMemorySaver(),
output_root=tmp_path,
tool_factory=make_tool_factory(runtime, roles, bundle.pillar_skills),
)
asked = await engine.start("Regional event ingestion")
assert asked.prompt == {
"questions": [
{
"from": "requirements",
"question": "What availability target do you need?",
}
]
}
answered = await engine.resume(asked.execution_id, {"reply": "99.9% in one region"})
assert (
answered.state["ledger"]["deliverables"]["requirements"]["status"]
== "submitted"
)
analyst_second_run = models["requirements-analyst"].requests[-1]
assert task_context(analyst_second_run)["answers"] == [
{
"questions": ["What availability target do you need?"],
"reply": "99.9% in one region",
}
]
orchestrator_prompt = models["orchestrator"].requests[0].config.system_instruction
assert "You coordinate one solution-architecture Execution" in orchestrator_prompt
analyst_prompt = (
models["requirements-analyst"].requests[0].config.system_instruction
)
assert "## How you work" in analyst_prompt