Files
gcp_solution_architecture_a…/tests/agents/test_adk_engine.py
Jonathan Boniface 545097530b
Some checks failed
validation / verify (push) Failing after 10s
feat: scoping is the first Phase, completed in conversation (iteration 9 step 2)
Every Execution now begins by agreeing the scope, before requirements.

- A new Phase and Deliverable, produced by a scope analyst with two tools:
  scope_read shows what is settled and what is not; scope_set records fields
  with where each value came from (the request, the customer's answer, or an
  assumption with its reason). Code checks each value against the catalogue.
- With someone present the analyst asks for what is missing; with nobody
  present it assumes it, visibly. With no spec it drafts one from the request.
  A value the customer stated in the file is changed only by their own answer.
- A submission cannot leave an essential field unknown. Code writes the
  completed spec, the data every later Specialist reads, and the information
  register, from what was recorded.
- The spec's status follows the Execution: under review, approved, then
  locked as a Baseline. A Change request starts from the delivered scope.
- The requirements analyst derives from the agreed scope and no longer asks
  for what it settles.

About 80 tests assumed requirements came first; tests/scoped.py runs scoping
ahead of a test's own script, and tests about order and counts are updated.
Not run with real models.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 18:17:32 +01:00

116 lines
4.1 KiB
Python

"""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
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.adk.adk_runtime import AdkAgentRuntime
from app.adk.fake_runtime import SAMPLE_DATA
from app.adk.roles import load_roles
from app.agent import ExecutionEngine
from app.providers import load_provider
from app.recorder import InMemoryRecorder
from app.tools.toolkit import make_tool_factory
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 task_context(request: LlmRequest) -> dict:
text = (request.contents[0].parts or [])[0].text or ""
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=["scope"]),
call("ask_user", questions=[]),
call("delegate", kinds=["scope"]),
call("ask_user", questions=["Anything to add?"]),
]
),
"scope-analyst": RoleScriptedLlm(
script=[
call("load_skill", skill_name="scoping"),
call(
"needs_input", questions=["What availability target do you need?"]
),
call(
"submit_deliverable",
content="# Scope\n## Scope statement\nRegional event ingestion.\n",
attachments=[
{"path": name, "content": SAMPLE_DATA[name]}
for name in ("scope.yaml", "scope.json")
],
),
]
),
}
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": "scope",
"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"]["scope"]["status"] == "submitted"
analyst_second_run = models["scope-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["scope-analyst"].requests[0].config.system_instruction
assert "## How you work" in analyst_prompt