Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/en/Projects/AgentSkills.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ if __name__ == '__main__':
main()
```

- skill_id_or_dir: Path to the local skill directory or skill ID from The ModelScope hub.
- skill_id_or_dir (str): e.g. 'path/to/skill-directory', 'ms-agent/skill_examples', 'ma-agent/skill_examples/pdf' (in the form of `owner/skill_name` or `owner/skill_name/subfolder`)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There appears to be a typo in the example skill ID. It should likely be ms-agent instead of ma-agent to maintain consistency with other examples and the pull request description.

Suggested change
- skill_id_or_dir (str): e.g. 'path/to/skill-directory', 'ms-agent/skill_examples', 'ma-agent/skill_examples/pdf' (in the form of `owner/skill_name` or `owner/skill_name/subfolder`)
- skill_id_or_dir (str): e.g. 'path/to/skill-directory', 'ms-agent/skill_examples', 'ms-agent/skill_examples/pdf' (in the form of `owner/skill_name` or `owner/skill_name/subfolder`)

- Refer to [AgentSkillExamples](https://modelscope.cn/models/ms-agent/skill_examples) for more details on skill publishing and sharing.



* Local Execution
- If `use_sandbox=False`, the skill scripts are executed directly in the local environment
Expand Down
5 changes: 5 additions & 0 deletions docs/zh/Projects/智能体技能.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ if __name__ == '__main__':
main()
```

- skill_id_or_dir: 支持传入本地技能目录路径,或从ModelScope Hub加载技能ID。
- skill_id_or_dir (str): 示例: 'path/to/skill-directory', 'ms-agent/skill_examples', 'ma-agent/skill_examples/pdf' (格式为 `owner/skill_name` or `owner/skill_name/subfolder`)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There appears to be a typo in the example skill ID. It should likely be ms-agent instead of ma-agent to maintain consistency with other examples.

Suggested change
- skill_id_or_dir (str): 示例: 'path/to/skill-directory', 'ms-agent/skill_examples', 'ma-agent/skill_examples/pdf' (格式为 `owner/skill_name` or `owner/skill_name/subfolder`)
- skill_id_or_dir (str): 示例: 'path/to/skill-directory', 'ms-agent/skill_examples', 'ms-agent/skill_examples/pdf' (格式为 `owner/skill_name` or `owner/skill_name/subfolder`)

- 参考 [AgentSkillExamples](https://modelscope.cn/models/ms-agent/skill_examples)


* 本地执行
- 若 `use_sandbox=False`,技能脚本将在本地环境中直接执行
- 请确保您信任该技能脚本,以避免潜在的安全风险
Expand Down
12 changes: 11 additions & 1 deletion ms_agent/agent/agent_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,17 @@ def _preprocess_skills(

skill_cache_dirs: List[str] = []
for skill_id in skills:
skill_dir: str = snapshot_download(repo_id=skill_id)
skill_id_parts: List[str] = skill_id.split('/')
subfolder = skill_id_parts[-1] if len(
skill_id_parts) == 3 else None
allow_pattern: str = f'{subfolder}/*' if subfolder else None
skill_id = '/'.join(
skill_id_parts[:2]) if subfolder else skill_id

skill_dir: str = snapshot_download(
repo_id=skill_id,
allow_patterns=allow_pattern,
)
logger.info(
f'Downloaded skill from hub: {skill_id} to {skill_dir}')
Comment on lines +146 to 158

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current implementation reassigns the skill_id variable. This can be confusing and leads to an incorrect log message, as the modified skill_id (the repository path without the subfolder) is logged instead of the original full skill ID. It's better to use a new variable for the repository ID to improve clarity and fix the logging.

Suggested change
skill_id_parts: List[str] = skill_id.split('/')
subfolder = skill_id_parts[-1] if len(
skill_id_parts) == 3 else None
allow_pattern: str = f'{subfolder}/*' if subfolder else None
skill_id = '/'.join(
skill_id_parts[:2]) if subfolder else skill_id
skill_dir: str = snapshot_download(
repo_id=skill_id,
allow_patterns=allow_pattern,
)
logger.info(
f'Downloaded skill from hub: {skill_id} to {skill_dir}')
skill_id_parts: List[str] = skill_id.split('/')
subfolder = skill_id_parts[-1] if len(
skill_id_parts) == 3 else None
allow_pattern: str = f'{subfolder}/*' if subfolder else None
repo_id = '/'.join(
skill_id_parts[:2]) if subfolder else skill_id
skill_dir: str = snapshot_download(
repo_id=repo_id,
allow_patterns=allow_pattern,
)
logger.info(
f'Downloaded skill from hub: {skill_id} to {skill_dir}')

skill_cache_dirs.append(skill_dir)
Expand Down
4 changes: 2 additions & 2 deletions ms_agent/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ def valid_repo_id(repo_id: str) -> bool:
Validate the format of a ModelScope repository ID.

Args:
repo_id (str): The repository ID to validate. e.g. owner/model_name
repo_id (str): The repository ID to validate. e.g. owner/model_name, owner/model_name/subfolder

Returns:
bool: True if the repo_id is valid, False otherwise.
Expand All @@ -689,7 +689,7 @@ def valid_repo_id(repo_id: str) -> bool:
return False

repo_id_parts: List[str] = repo_id.split('/')
if len(repo_id_parts) == 2 and all(repo_id_parts):
if len(repo_id_parts) in (2, 3) and all(repo_id_parts):
return True

return False
9 changes: 7 additions & 2 deletions projects/agent_skills/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def main():
"""
work_dir: str = str(_PATH / 'temp_workspace')
# Refer to `https://github.com/modelscope/ms-agent/tree/main/projects/agent_skills/skills`
skills_dir: str = str(_PATH / 'skills')
skill_id_or_dir: str = str(_PATH / 'skills')
use_sandbox: bool = True

## Configuration for ModelScope API-Inference, or set your own model with OpenAI API compatible format
Expand All @@ -93,7 +93,7 @@ def main():
base_url: str = 'https://api-inference.modelscope.cn/v1/'

agent = create_agent_skill(
skills=skills_dir,
skills=skill_id_or_dir,
model=model,
api_key=os.getenv('OPENAI_API_KEY', api_key),
base_url=os.getenv('OPENAI_BASE_URL', base_url),
Expand All @@ -115,6 +115,11 @@ if __name__ == '__main__':
main()
```

- skill_id_or_dir: Path to the local skill directory or skill ID from The ModelScope hub.
- skill_id_or_dir (str): e.g. 'path/to/skill-directory', 'ms-agent/skill_examples', 'ma-agent/skill_examples/pdf' (in the form of `owner/skill_name` or `owner/skill_name/subfolder`)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There appears to be a typo in the example skill ID. It should likely be ms-agent instead of ma-agent to maintain consistency with other examples and the pull request description.

Suggested change
- skill_id_or_dir (str): e.g. 'path/to/skill-directory', 'ms-agent/skill_examples', 'ma-agent/skill_examples/pdf' (in the form of `owner/skill_name` or `owner/skill_name/subfolder`)
- skill_id_or_dir (str): e.g. 'path/to/skill-directory', 'ms-agent/skill_examples', 'ms-agent/skill_examples/pdf' (in the form of `owner/skill_name` or `owner/skill_name/subfolder`)

- Refer to [AgentSkillExamples](https://modelscope.cn/models/ms-agent/skill_examples) for more details on skill publishing and sharing.


**Result:**

<div align="center">
Expand Down
Loading