Skip to content

Commit 63eda7a

Browse files
committed
refactor: add shape_skill hook, typing imports, and interpolation warning logs
1 parent ce5913a commit 63eda7a

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

  • src/google/adk_community/plugins/taxonomy

src/google/adk_community/plugins/taxonomy/policy.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616

1717
from __future__ import annotations
1818

19-
from abc import ABC
20-
from abc import abstractmethod
19+
from abc import ABC, abstractmethod
20+
import logging
21+
from typing import Any, Optional
2122

2223
from google.adk.agents.readonly_context import ReadonlyContext
2324
from google.adk.models.llm_request import LlmRequest
2425
from google.adk.skills.models import Skill
2526

27+
logger = logging.getLogger("google_adk_community." + __name__)
2628

2729
class TaxonomyResolver(ABC):
2830
"""Abstract base class for taxonomy resolution.
@@ -190,6 +192,31 @@ def prioritize_skills(
190192
"""
191193
return skills
192194

195+
def shape_skill(
196+
self,
197+
skill: Skill,
198+
context: ReadonlyContext,
199+
shaped_description: Optional[str],
200+
) -> Skill:
201+
"""Prepares and shapes a skill representation for presentation to the agent.
202+
203+
Defaults to a secure manual reconstruction to prevent accidental leakage of
204+
internal developer/business flags to LLM prompts, but can be overridden by
205+
custom policies to use `model_copy()` or other strategies.
206+
"""
207+
assert skill is not None, "Skill instance cannot be None"
208+
209+
from google.adk.skills.models import Skill, Frontmatter
210+
extra = getattr(skill.frontmatter, "model_extra", None) or {}
211+
return Skill(
212+
frontmatter=Frontmatter(
213+
name=skill.frontmatter.name,
214+
description=shaped_description,
215+
**extra
216+
),
217+
instructions=skill.instructions
218+
)
219+
193220

194221
def _get_taxonomy_binds(skill: Skill) -> list[str]:
195222
"""Dynamically extracts taxonomy binds, supporting both modified and unmodified core SDKs.
@@ -228,6 +255,8 @@ def replace(match):
228255
variables = (term.model_extra or {}).get("variables", {})
229256
if variables and var_name in variables:
230257
return str(variables[var_name])
258+
259+
logger.warning("Taxonomy variable %r not found under active taxonomies: %s", var_name, active_taxonomies)
231260
return ""
232261

233262
return re.sub(pattern, replace, text)

0 commit comments

Comments
 (0)