49 lines
1.8 KiB
Python
49 lines
1.8 KiB
Python
"""Which tools each role gets beyond the Execution tools.
|
|
|
|
A role gets the local tools its role file names, the tools of the remote MCP servers
|
|
the provider bundle assigns it, and, for the design advisor, the pillar consultation.
|
|
Cloud-read gating is applied later, per Execution, by `specialist_tools`.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Mapping, Sequence
|
|
|
|
from app.adk.roles import PILLAR_ADVISOR
|
|
from app.adk.runtime import AgentRuntime, RoleSpec, ToolFactory, ToolSpec
|
|
from app.tools.mcp import McpCatalog
|
|
from app.tools.pillars import pillar_consultation_tool
|
|
from app.workflows.deliverables import DeliverableKind
|
|
|
|
|
|
def make_tool_factory(
|
|
runtime: AgentRuntime,
|
|
roles: Mapping[str, RoleSpec],
|
|
pillar_skills: Mapping[str, str],
|
|
*,
|
|
local_tools: Sequence[ToolSpec] = (),
|
|
catalog: McpCatalog | None = None,
|
|
) -> ToolFactory:
|
|
local_by_name = {tool.name: tool for tool in local_tools}
|
|
|
|
def mcp_tools(role: RoleSpec) -> list[ToolSpec]:
|
|
return catalog.tools_for(role.mcp_servers) if catalog else []
|
|
|
|
consult = None
|
|
advisor = roles.get(PILLAR_ADVISOR)
|
|
if pillar_skills and advisor:
|
|
# Pillar advisors can't ask for permission, so they get general-tier tools only.
|
|
advisor_tools = [tool for tool in mcp_tools(advisor) if tool.tier == "general"]
|
|
consult = pillar_consultation_tool(
|
|
runtime, advisor, pillar_skills, extra_tools=advisor_tools
|
|
)
|
|
|
|
def tools_for(role: RoleSpec, deliverable: str | None) -> Sequence[ToolSpec]:
|
|
tools = [local_by_name[name] for name in role.tools if name in local_by_name]
|
|
tools += mcp_tools(role)
|
|
if consult and deliverable == DeliverableKind.DESIGN_RECOMMENDATIONS.value:
|
|
tools.append(consult)
|
|
return tools
|
|
|
|
return tools_for
|