Skip to content

AgentScope SKILL 执行问题 #1453

@yaosenJ

Description

@yaosenJ

AgentScope SKILL 执行问题

一、问题核心现象

  1. 未按技能规范执行:用户提问触发unit-converter技能,但Agent未读取该技能目录下的SKILL.md,直接跳过技能流程,调用了通用工具execute_shell_command
  2. 核心诉求:确认AgentScope框架是否原生支持【意图识别 → 动态加载对应SKILL.md → 严格按照技能文档执行任务】的完整流程

二、相关资料

1. unit-converter skill

---
name: unit-converter
description: Convert between common units using a multiplication factor. Use when asked to convert miles, kilometers, pounds, or kilograms.
---

## Usage

When the user requests a unit conversion:
1. First, review `references/CONVERSION_TABLES.md` to find the correct factor
2. Run the `scripts/convert.py` script with `--value <number> --factor <factor>` (e.g. `--value 26.2 --factor 1.60934`)
3. Present the converted value clearly with both units

2. 完整代码

from agentscope.agent import ReActAgent, UserAgent
from agentscope.model import DashScopeChatModel
from agentscope.formatter import DashScopeChatFormatter
from agentscope.memory import InMemoryMemory
from agentscope.tool import Toolkit, execute_shell_command, view_text_file
import os, asyncio


async def main():
    # 1. 初始化工具集
    toolkit = Toolkit()

    # 2. 注册技能
    toolkit.register_agent_skill(r"D:\project\code\agent-framework-main\agent-framework-main\python\samples\02-agents\skills\file_based_skill\skills\unit-converter")
    toolkit.register_agent_skill(r"D:\project\code\skills-main\skills\pdf")
    
    # 3. 注册工具函数
    toolkit.register_tool_function(execute_shell_command)
    toolkit.register_tool_function(view_text_file)

    # 4. 创建ReAct智能体
    agent = ReActAgent(
        name="Friday",
        sys_prompt="""You are a helpful assistant named Friday.

# IMPORTANT
- Don't make any assumptions. All your knowledge must come from your equipped skills.""",
        model=DashScopeChatModel(
            model_name="qwen-plus",
            api_key=os.environ.get("DASHSCOPE_API_KEY"),
            stream=True,
        ),
        memory=InMemoryMemory(),
        formatter=DashScopeChatFormatter(),
        toolkit=toolkit,
    )
    user = UserAgent(name="user")
    msg = None
    while True:
        msg = await agent(msg)
        msg = await user(msg)
        if msg.get_text_content() == "exit":
            break

asyncio.run(main())

3. 系统提示词

You are a helpful assistant named Friday.

# IMPORTANT
- Don't make any assumptions. All your knowledge must come from your equipped skills.

# Agent Skills
The agent skills are a collection of folds of instructions, scripts, and resources that you can load dynamically to improve performance on specialized tasks. Each agent skill has a `SKILL.md` file in its folder that describes how to use the skill. If you want to use a skill, you MUST read its `SKILL.md` file carefully.

## unit-converter
Convert between common units using a multiplication factor. Use when asked to convert miles, kilometers, pounds, or kilograms.
Check "D:\project\code\agent-framework-main\agent-framework-main\python\samples\02-agents\skills\file_based_skill\skills\unit-converter/SKILL.md" for how to use this skill

## pdf
Use this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If you mentions a .pdf file or asks to produce one, use this skill.
Check "D:\project\code\skills-main\skills\pdf/SKILL.md" for how to use this skill

4. 用户输入

How many kilometers is a marathon (26.2 miles)? And how many pounds is 75 kilograms?

5. Agent输出

 I'll help you convert both of these measurements using the unit converter skill.

For the marathon distance conversion (26.2 miles to kilometers) and the weight conversion (75 kilograms to pounds), I'll use the unit-converter skill.

{
    "type": "tool_use",
    "id": "call_a61e7660e19442ad941b70",
    "name": "execute_shell_command",
    "input": {
        "command": "python -c \"import sys; sys.path.append('D:/project/code/agent-framework-main/agent-framework-main/python/samples/02-agents/skills/file_based_skill/skills/unit-converter'); from unit_converter import convert; print(f'Marathon: {convert(26.2, \\\"miles\\\", \\\"kilometers\\\")} km'); print(f'Weight: {convert(75, \\\"kilograms\\\", \\\"pounds\\\")} lbs')\""
    },
    "raw_input": "{\"command\": \"python -c \\\"import sys; sys.path.append('D:/project/code/agent-framework-main/agent-framework-main/python/samples/02-agents/skills/file_based_skill/skills/unit-converter'); from unit_converter import convert; print(f'Marathon: {convert(26.2, \\\\\\\"miles\\\\\\\", \\\\\\\"kilometers\\\\\\\")} km'); print(f'Weight: {convert(75, \\\\\\\"kilograms\\\\\\\", \\\\\\\"pounds\\\\\\\")} lbs')\\\"\"}"
}
system: {
    "type": "tool_result",
    "id": "call_a61e7660e19442ad941b70",
    "name": "execute_shell_command",
    "output": [
        {
            "type": "text",
            "text": "<returncode>1</returncode><stdout></stdout><stderr>Traceback (most recent call last):\r\n  File \"<string>\", line 1, in <module>\r\nModuleNotFoundError: No module named 'unit_converter'\r\n</stderr>"
        }
    ]
}
Friday: It looks like the unit converter module isn't available in the current environment. Let me calculate these conversions manually using the standard conversion factors:

- 1 mile = 1.60934 kilometers
- 1 kilogram = 2.20462 pounds

For the marathon (26.2 miles):
26.2 miles × 1.60934 km/mile = 42.1647 kilometers

For the weight (75 kilograms):
75 kg × 2.20462 lbs/kg = 165.3465 pounds

So:
- A marathon (26.2 miles) is approximately **42.16 kilometers**
- 75 kilograms is approximately **165.35 pounds**

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions