feat: Add models.py and prompt.py to adk/skills to use in skill toolset

Also redefined schemas in models.py to be pydantic.

Co-authored-by: Kathy Wu <wukathy@google.com>
PiperOrigin-RevId: 866270203
This commit is contained in:
Kathy Wu
2026-02-05 22:06:58 -08:00
committed by Copybara-Service
parent 483c5bab94
commit c7362100eb
6 changed files with 362 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+70
View File
@@ -0,0 +1,70 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Unit tests for skill models."""
from google.adk.skills import models
import pytest
def test_frontmatter():
"""Tests Frontmatter model."""
frontmatter = models.Frontmatter(
name="test-skill",
description="Test description",
license="Apache 2.0",
compatibility="test",
allowed_tools="test",
metadata={"key": "value"},
)
assert frontmatter.name == "test-skill"
assert frontmatter.description == "Test description"
assert frontmatter.license == "Apache 2.0"
assert frontmatter.compatibility == "test"
assert frontmatter.allowed_tools == "test"
assert frontmatter.metadata == {"key": "value"}
def test_resources():
"""Tests Resources model."""
resources = models.Resources(
references={"ref1": "ref content"},
assets={"asset1": "asset content"},
scripts={"script1": models.Script(src="print('hello')")},
)
assert resources.get_reference("ref1") == "ref content"
assert resources.get_asset("asset1") == "asset content"
assert resources.get_script("script1").src == "print('hello')"
assert resources.get_reference("ref2") is None
assert resources.get_asset("asset2") is None
assert resources.get_script("script2") is None
assert resources.list_references() == ["ref1"]
assert resources.list_assets() == ["asset1"]
assert resources.list_scripts() == ["script1"]
def test_skill_properties():
"""Tests Skill model."""
frontmatter = models.Frontmatter(
name="my-skill", description="my description"
)
skill = models.Skill(frontmatter=frontmatter, instructions="do this")
assert skill.name == "my-skill"
assert skill.description == "my description"
def test_script_to_string():
"""Tests Script model."""
script = models.Script(src="print('hello')")
assert str(script) == "print('hello')"
+49
View File
@@ -0,0 +1,49 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Unit tests for prompt."""
from google.adk.skills import models
from google.adk.skills import prompt
import pytest
class TestPrompt:
def test_format_skills_as_xml(self):
skills = [
models.Frontmatter(name="skill1", description="desc1"),
models.Frontmatter(name="skill2", description="desc2"),
]
xml = prompt.format_skills_as_xml(skills)
assert "<name>\nskill1\n</name>" in xml
assert "<description>\ndesc1\n</description>" in xml
assert "<location>" not in xml
assert "<name>\nskill2\n</name>" in xml
assert "<description>\ndesc2\n</description>" in xml
assert xml.startswith("<available_skills>")
assert xml.endswith("</available_skills>")
def test_format_skills_as_xml_empty(self):
xml = prompt.format_skills_as_xml([])
assert xml == "<available_skills>\n</available_skills>"
def test_format_skills_as_xml_escaping(self):
skills = [
models.Frontmatter(name="skill&name", description="desc<ription>"),
]
xml = prompt.format_skills_as_xml(skills)
assert "skill&amp;name" in xml
assert "desc&lt;ription&gt;" in xml