agentscope-ai/agentscope · error · TypeError
Invalid skill or loader: {_}. Must be a skill, skill loader,
Error message
Invalid skill or loader: {_}. Must be a skill, skill loader, or directory path. What it means
ToolGroup.__init__ validates each item in skills/mcps: it must be a Skill instance, a SkillLoaderBase, or a string directory path; anything else raises TypeError naming the offending object.
Source
Thrown at src/agentscope/tool/_tool_group.py:94
)
self.name = name
self.description = description or ""
self.instructions = instructions
self.tools = tools or []
self.mcps = mcps or []
# Skill
self.skills_or_loaders = []
for _ in skills_or_loaders or []:
if isinstance(_, str):
self.skills_or_loaders.append(LocalSkillLoader(directory=_))
elif isinstance(_, (Skill, SkillLoaderBase)):
self.skills_or_loaders.append(_)
else:
raise TypeError(
f"Invalid skill or loader: {_}. Must be a skill, "
f"skill loader, or directory path.",
)
async def list_skills(self) -> list[Skill]:
"""List all the skills in this tool group."""
skills = []
for skill_or_loader in self.skills_or_loaders:
if isinstance(skill_or_loader, Skill):
skills.append(skill_or_loader)
elif isinstance(skill_or_loader, SkillLoaderBase):
skills.extend(await skill_or_loader.list_skills())
return skills
View on GitHub (pinned to e90f1c7592)
Solutions
- Convert Path to str: str(path)
- Instantiate skills: Skill(...) rather than the class
- Ensure custom loaders subclass SkillLoaderBase from the installed agentscope version
Example fix
# before
ToolGroup(name='x', description='d', skills=[Path('./skills')])
# after
ToolGroup(name='x', description='d', skills=['./skills']) Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path items = [str(i) if isinstance(i, Path) else i for i in skills]
Type guard
from agentscope.tool import Skill, SkillLoaderBase
def valid_skill_item(o) -> bool:
return isinstance(o, str) or isinstance(o, (Skill, SkillLoaderBase)) Prevention
- Convert Path to str before passing
- Pass instances, not classes
- Subclass SkillLoaderBase for custom loaders
When it happens
Trigger: Passing a module, a class instead of an instance, a Path object, or an arbitrary object in the skills list.
Common situations: Passing pathlib.Path instead of str; passing Skill (class) rather than Skill(...); passing a loader from an incompatible version with a different base class.
Understand the failure class
Background: Invalid argument type errors: "must be of type string", "expected X, got Y", and ERR_INVALID_ARG_TYPE explained — this error's family across 15 libraries.
Related errors
- Input must be a list of Msg objects.
- Expected Msg object, got {type(msg)} instead.
- The tool group description is required for tool group '{name
- Invalid logging level: {level}. Must be one of 'INFO', 'DEBU
- factory must be a callable, got {type(factory).__name__}
AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28).
Data as JSON: /api/errors/d2e943960754e052.
Report an issue: GitHub.