Files
social-app/backend/tests/integration/test_agentscope_skill_prompt_flow.py
qzl d060962a5f feat(agent): redesign project_cli with module/method/input protocol
- Replace command/subcommand/args with module/method/input envelope
- Calendar handler uses discriminated union (mode) for read operations
- Strict Pydantic models with extra='forbid' for all calendar methods
- Worker max_iters=7, router prompt simplified (removed project_cli_defaults)
- Skill index cards + per-action files for progressive disclosure
- Frontend/AG-UI aligned to module/method dispatch
- Protocol docs updated to module/method/input contract

WIP: action cards need envelope fix, 2 tests need update, memory
handler needs Pydantic models.
2026-04-24 13:24:13 +08:00

67 lines
2.0 KiB
Python

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
assert "view_skill_file" in prompt
assert 'file_path="calendar/SKILL.md"' in prompt
assert 'file_path="contacts/SKILL.md"' in prompt
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
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