Some checks failed
check agents / check (push) Failing after 13s
The cp1-solution-architecture-agent and the sa-aws/azure/gcp-cloud MCP servers, a separate stream from the individual and sub-agent patterns. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
64 lines
2.5 KiB
Python
64 lines
2.5 KiB
Python
"""A role's Skills as tools. KAB sub-agents can't hold Skills, so these give each role what
|
|
ADK's SkillToolset gave it in the source: progressive loading, of its own Skills only."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Mapping
|
|
from pathlib import Path
|
|
|
|
from app.engine.runtime import ToolResult, ToolSpec
|
|
|
|
_READABLE = (".md", ".txt", ".yaml", ".yml", ".json", ".tf", ".mmd")
|
|
|
|
|
|
def skill_tools(skills: Mapping[str, Path], allowed: tuple[str, ...]) -> list[ToolSpec]:
|
|
if not allowed:
|
|
return []
|
|
|
|
def folder(name: str) -> Path | None:
|
|
return skills.get(name) if name in allowed else None
|
|
|
|
async def load_skill(skill_name: str) -> ToolResult:
|
|
path = folder(skill_name)
|
|
if path is None:
|
|
return ToolResult(f"Refused: {skill_name} is not one of your Skills: {', '.join(allowed)}.")
|
|
files = sorted(
|
|
item.relative_to(path).as_posix()
|
|
for item in path.rglob("*")
|
|
if item.is_file() and item.name != "SKILL.md"
|
|
)
|
|
text = (path / "SKILL.md").read_text(encoding="utf-8")
|
|
return ToolResult(f"{text}\n\nFiles you can read with load_skill_resource: {', '.join(files) or 'none'}")
|
|
|
|
async def load_skill_resource(skill_name: str, path: str) -> ToolResult:
|
|
root = folder(skill_name)
|
|
if root is None:
|
|
return ToolResult(f"Refused: {skill_name} is not one of your Skills: {', '.join(allowed)}.")
|
|
target = (root / path).resolve()
|
|
if not target.is_relative_to(root.resolve()) or target.suffix not in _READABLE:
|
|
return ToolResult(f"Refused: {path} is not a file of {skill_name} you can read.")
|
|
if not target.is_file():
|
|
return ToolResult(f"Refused: {skill_name} has no file {path}.")
|
|
return ToolResult(target.read_text(encoding="utf-8"))
|
|
|
|
return [
|
|
ToolSpec(
|
|
"load_skill",
|
|
f"Read one of your Skills: {', '.join(allowed)}.",
|
|
{"type": "object", "properties": {"skill_name": {"type": "string"}}, "required": ["skill_name"]},
|
|
load_skill,
|
|
tier="execution",
|
|
),
|
|
ToolSpec(
|
|
"load_skill_resource",
|
|
"Read a reference or asset of one of your Skills.",
|
|
{
|
|
"type": "object",
|
|
"properties": {"skill_name": {"type": "string"}, "path": {"type": "string"}},
|
|
"required": ["skill_name", "path"],
|
|
},
|
|
load_skill_resource,
|
|
tier="execution",
|
|
),
|
|
]
|