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:
@@ -140,6 +140,30 @@ DEPENDENCY_GRAPH: Mapping[DeliverableKind, DeliverableSpec] = {
|
||||
}
|
||||
|
||||
|
||||
def inputs_of(kind: DeliverableKind) -> tuple[DeliverableKind, ...]:
|
||||
"""The Deliverables a Specialist works from, in graph order.
|
||||
|
||||
Every Deliverable in an earlier Phase (all approved by the time `kind` is ready),
|
||||
plus everything `kind` depends on, directly or not, within its own Phase.
|
||||
"""
|
||||
spec = DEPENDENCY_GRAPH[kind]
|
||||
earlier_phases = PHASE_ORDER[: PHASE_ORDER.index(spec.phase)]
|
||||
upstream: set[DeliverableKind] = set()
|
||||
frontier = set(DEPENDENCY_GRAPH[kind].depends_on)
|
||||
while frontier:
|
||||
upstream |= frontier
|
||||
frontier = {
|
||||
dependency
|
||||
for item in frontier
|
||||
for dependency in DEPENDENCY_GRAPH[item].depends_on
|
||||
} - upstream
|
||||
return tuple(
|
||||
candidate
|
||||
for candidate, candidate_spec in DEPENDENCY_GRAPH.items()
|
||||
if candidate in upstream or candidate_spec.phase in earlier_phases
|
||||
)
|
||||
|
||||
|
||||
def deliverables_in(phase: PhaseId) -> tuple[DeliverableKind, ...]:
|
||||
return tuple(kind for kind, spec in DEPENDENCY_GRAPH.items() if spec.phase is phase)
|
||||
|
||||
|
||||
@@ -31,7 +31,12 @@ from app.agents.runtime import (
|
||||
ToolSpec,
|
||||
TurnEnded,
|
||||
)
|
||||
from app.execution.deliverables import DEPENDENCY_GRAPH, PHASE_ORDER, DeliverableKind
|
||||
from app.execution.deliverables import (
|
||||
DEPENDENCY_GRAPH,
|
||||
PHASE_ORDER,
|
||||
DeliverableKind,
|
||||
inputs_of,
|
||||
)
|
||||
from app.execution.ledger import Ledger, LedgerRefusal
|
||||
from app.execution.recorder import ExecutionRecorder
|
||||
from app.execution.state import ExecutionState
|
||||
@@ -392,7 +397,7 @@ def _specialist_input(
|
||||
"pre_approved": bool(state.get("pre_approved")),
|
||||
"dependencies": {
|
||||
dependency.value: dict(deliverables[dependency.value])
|
||||
for dependency in spec.depends_on
|
||||
for dependency in inputs_of(kind)
|
||||
},
|
||||
"feedback": list(ledger.feedback(kind)),
|
||||
"answers": list(state.get("answers", {}).get(kind.value, [])),
|
||||
|
||||
103
app/execution/pillars.py
Normal file
103
app/execution/pillars.py
Normal file
@@ -0,0 +1,103 @@
|
||||
"""The design advisor's fan-out to one advisor per architecture-framework pillar.
|
||||
|
||||
Pillar advice is working material for the design recommendations Deliverable, not a
|
||||
Deliverable itself, so it never touches the Ledger.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import dataclasses
|
||||
from collections.abc import Mapping, Sequence
|
||||
|
||||
from app.agents.runtime import (
|
||||
AgentRuntime,
|
||||
AgentTask,
|
||||
RoleSpec,
|
||||
Submitted,
|
||||
ToolResult,
|
||||
ToolSpec,
|
||||
)
|
||||
|
||||
CONSULT_TOOL = "consult_pillar_advisors"
|
||||
|
||||
|
||||
def pillar_consultation_tool(
|
||||
runtime: AgentRuntime,
|
||||
advisor: RoleSpec,
|
||||
pillar_skills: Mapping[str, str],
|
||||
) -> ToolSpec:
|
||||
"""A tool that runs one pillar advisor per pillar, in parallel, each with its Skill."""
|
||||
|
||||
async def consult(brief: str, pillars: Sequence[str] | None = None) -> ToolResult:
|
||||
chosen = list(pillars) if pillars else list(pillar_skills)
|
||||
unknown = [pillar for pillar in chosen if pillar not in pillar_skills]
|
||||
if unknown:
|
||||
return ToolResult(
|
||||
f"Refused: unknown pillars {', '.join(unknown)}; "
|
||||
f"choose from {', '.join(pillar_skills)}"
|
||||
)
|
||||
results = await asyncio.gather(
|
||||
*(
|
||||
_advise(runtime, advisor, pillar, pillar_skills[pillar], brief)
|
||||
for pillar in chosen
|
||||
)
|
||||
)
|
||||
return ToolResult("\n\n".join(results))
|
||||
|
||||
return ToolSpec(
|
||||
CONSULT_TOOL,
|
||||
"Get guidance from one advisor per architecture-framework pillar, in parallel. "
|
||||
"Give a brief with the workload, its requirements and the selected products.",
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"brief": {"type": "string"},
|
||||
"pillars": {
|
||||
"type": "array",
|
||||
"items": {"type": "string", "enum": list(pillar_skills)},
|
||||
},
|
||||
},
|
||||
"required": ["brief"],
|
||||
},
|
||||
consult,
|
||||
)
|
||||
|
||||
|
||||
async def _advise(
|
||||
runtime: AgentRuntime, advisor: RoleSpec, pillar: str, skill: str, brief: str
|
||||
) -> str:
|
||||
role = dataclasses.replace(advisor, skills=(skill,))
|
||||
task = AgentTask(
|
||||
role=advisor.name,
|
||||
prompt=f"Advise on the {pillar} pillar for this workload.",
|
||||
context={"pillar": pillar, "brief": brief},
|
||||
)
|
||||
try:
|
||||
outcome = await runtime.run(role, task, [_submit_advice_tool()])
|
||||
except Exception as exc: # noqa: BLE001 - one failed advisor must not lose the others
|
||||
return f"## {pillar}\n\nNo guidance: the advisor failed ({exc})."
|
||||
if isinstance(outcome, Submitted):
|
||||
return f"## {pillar}\n\n{outcome.content.strip()}"
|
||||
return (
|
||||
f"## {pillar}\n\nNo guidance: the advisor ended with {type(outcome).__name__}."
|
||||
)
|
||||
|
||||
|
||||
def _submit_advice_tool() -> ToolSpec:
|
||||
async def submit_advice(content: str) -> ToolResult:
|
||||
if not content.strip():
|
||||
return ToolResult("Not submitted: the advice is empty.")
|
||||
return ToolResult("Advice submitted.", Submitted(content))
|
||||
|
||||
return ToolSpec(
|
||||
"submit_advice",
|
||||
"Submit your pillar recommendations as markdown. Ends your turn.",
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {"content": {"type": "string"}},
|
||||
"required": ["content"],
|
||||
},
|
||||
submit_advice,
|
||||
tier="execution",
|
||||
)
|
||||
33
app/execution/toolkit.py
Normal file
33
app/execution/toolkit.py
Normal file
@@ -0,0 +1,33 @@
|
||||
"""Which extra tools each role gets beyond the Execution tools.
|
||||
|
||||
Increment 6 adds the local general and cloud-read tools and remote MCP servers here.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping, Sequence
|
||||
|
||||
from app.agents.roles import PILLAR_ADVISOR
|
||||
from app.agents.runtime import AgentRuntime, RoleSpec, ToolSpec
|
||||
from app.execution.deliverables import DeliverableKind
|
||||
from app.execution.graph import ToolFactory
|
||||
from app.execution.pillars import pillar_consultation_tool
|
||||
|
||||
|
||||
def make_tool_factory(
|
||||
runtime: AgentRuntime,
|
||||
roles: Mapping[str, RoleSpec],
|
||||
pillar_skills: Mapping[str, str],
|
||||
) -> ToolFactory:
|
||||
consult = (
|
||||
pillar_consultation_tool(runtime, roles[PILLAR_ADVISOR], pillar_skills)
|
||||
if pillar_skills and PILLAR_ADVISOR in roles
|
||||
else None
|
||||
)
|
||||
|
||||
def tools_for(role: RoleSpec, deliverable: str | None) -> Sequence[ToolSpec]:
|
||||
if consult and deliverable == DeliverableKind.DESIGN_RECOMMENDATIONS.value:
|
||||
return [consult]
|
||||
return []
|
||||
|
||||
return tools_for
|
||||
Reference in New Issue
Block a user