2026-04-22 17:09:37 +08:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
import asyncio
|
|
|
|
|
|
|
|
|
|
from agentscope.agent import ReActAgent
|
|
|
|
|
from agentscope.formatter import DashScopeChatFormatter
|
|
|
|
|
from agentscope.memory import InMemoryMemory
|
|
|
|
|
|
|
|
|
|
from core.agentscope.tools.toolkit import build_toolkit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _DummyModel:
|
|
|
|
|
stream = False
|
|
|
|
|
|
|
|
|
|
async def __call__(self, *args, **kwargs):
|
|
|
|
|
raise RuntimeError("dummy model should not be called in this test")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_react_agent_sys_prompt_includes_registered_skill_prompt() -> None:
|
|
|
|
|
toolkit = build_toolkit(enabled_skill_names={"calendar", "contacts"})
|
|
|
|
|
agent = ReActAgent(
|
|
|
|
|
name="tester",
|
|
|
|
|
sys_prompt="base prompt",
|
|
|
|
|
model=_DummyModel(),
|
|
|
|
|
formatter=DashScopeChatFormatter(),
|
|
|
|
|
toolkit=toolkit,
|
|
|
|
|
memory=InMemoryMemory(),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
prompt = agent.sys_prompt
|
|
|
|
|
assert "base prompt" in prompt
|
|
|
|
|
assert "# Agent Skills" in prompt
|
|
|
|
|
assert "## calendar" in prompt
|
|
|
|
|
assert "## contacts" in prompt
|
2026-04-24 13:24:13 +08:00
|
|
|
assert "view_skill_file" in prompt
|
|
|
|
|
assert 'file_path="calendar/SKILL.md"' in prompt
|
|
|
|
|
assert 'file_path="contacts/SKILL.md"' in prompt
|
2026-04-22 17:09:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_view_skill_file_tool_reads_registered_skill_content() -> None:
|
|
|
|
|
toolkit = build_toolkit(enabled_skill_names={"calendar"})
|
|
|
|
|
tool = toolkit.tools["view_skill_file"].original_func
|
|
|
|
|
|
|
|
|
|
response = asyncio.run(
|
|
|
|
|
tool(file_path="calendar/SKILL.md", ranges=[1, 20]),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert response.content
|
|
|
|
|
block = response.content[0]
|
|
|
|
|
text = block["text"] if isinstance(block, dict) else block.text
|
|
|
|
|
assert "Calendar Skill" in text or "name: calendar" in text
|
2026-04-24 13:24:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_view_skill_file_tool_reads_calendar_action_card() -> None:
|
|
|
|
|
toolkit = build_toolkit(enabled_skill_names={"calendar"})
|
|
|
|
|
tool = toolkit.tools["view_skill_file"].original_func
|
|
|
|
|
|
|
|
|
|
response = asyncio.run(
|
|
|
|
|
tool(file_path="calendar/actions/create_event.md", ranges=[1, 20]),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert response.content
|
|
|
|
|
block = response.content[0]
|
|
|
|
|
text = block["text"] if isinstance(block, dict) else block.text
|
|
|
|
|
assert "create_event" in text
|
|
|
|
|
assert "input.title" in text
|