Skip to content

Agent Zero AI framework

skills cleanup

frdelc460348549e1
diff --git a/python/api/skills.py b/python/api/skills.py
index 33d2c3345..64fcddb3b 100644
--- a/python/api/skills.py
+++ b/python/api/skills.py
@@ -1,5 +1,5 @@
from python.helpers.api import ApiHandler, Input, Output, Request, Response
-from python.helpers import skills
+from python.helpers import skills, projects, files
class Skills(ApiHandler):
@@ -25,24 +25,28 @@ class Skills(ApiHandler):
}
def list_skills(self, input: Input):
- project_name = (input.get("project_name") or "").strip() or None
- profile_name = (input.get("profile_name") or "").strip() or None
- return skills.get_skills_list(
- project_name=project_name,
- profile_name=profile_name
- )
+ skill_list = skills.list_skills()
+
+ # filter by project
+ if project_name := (input.get("project_name") or "").strip() or None:
+ project_folder = projects.get_project_folder(project_name)
+ skill_list = [
+ s for s in skill_list if files.is_in_dir(str(s.path), project_folder)
+ ]
+
+ result = []
+ for skill in skill_list:
+ result.append({
+ "name": skill.name,
+ "description": skill.description,
+ "path": str(skill.path),
+ })
+ return result
def delete_skill(self, input: Input):
- skill_id = str(input.get("skill_id") or "").strip()
- if not skill_id:
- raise Exception("skill_id is required")
-
- project_name = (input.get("project_name") or "").strip() or None
- profile_name = (input.get("profile_name") or "").strip() or None
-
- skills.delete_skill(
- skill_id,
- project_name=project_name,
- profile_name=profile_name,
- )
- return {"skill_id": skill_id}
+ skill_path = str(input.get("skill_path") or "").strip()
+ if not skill_path:
+ raise Exception("skill_path is required")
+
+ skills.delete_skill(skill_path)
+ return {"ok": True, "skill_path": skill_path}
diff --git a/python/helpers/history.py b/python/helpers/history.py
index e796d4cb8..b54eb28ad 100644
--- a/python/helpers/history.py
+++ b/python/helpers/history.py
@@ -520,11 +520,9 @@ def output_langchain(messages: list[OutputMessage]):
result = []
for m in messages:
content = _output_content_langchain(content=m["content"])
- # Skip AI messages with empty/whitespace-only content
- # (API spec requires assistant messages to have content or tool_calls)
+ if not content or (isinstance(content, str) and not content.strip()):
+ continue
if m["ai"]:
- if not content or (isinstance(content, str) and not content.strip()):
- continue
result.append(AIMessage(content)) # type: ignore
else:
result.append(HumanMessage(content)) # type: ignore
diff --git a/python/helpers/skills.py b/python/helpers/skills.py
index 884ba0196..63e256820 100644
--- a/python/helpers/skills.py
+++ b/python/helpers/skills.py
@@ -312,131 +312,21 @@ def list_skills(
return list(by_name.values())
-def _get_skill_roots_for_list(
- project_name: str | None = None,
- profile_name: str | None = None,
-) -> List[str]:
- """Get skill root directories for the specified scope."""
- roots: List[str] = []
-
- # global roots
- roots.append(files.get_abs_path("skills"))
- roots.append(files.get_abs_path("usr", "skills"))
-
- # project roots
- if project_name:
- if profile_name:
- roots.append(projects.get_project_meta_folder(project_name, "agents", profile_name, "skills"))
- roots.append(projects.get_project_meta_folder(project_name, "skills"))
-
- # agent roots
- if profile_name:
- roots.append(files.get_abs_path(subagents.USER_AGENTS_DIR, profile_name, "skills"))
- roots.append(files.get_abs_path(subagents.DEFAULT_AGENTS_DIR, profile_name, "skills"))
-
- # dedupe and filter existing
- seen: set[str] = set()
- result: List[str] = []
- for root in roots:
- if root in seen or not os.path.isdir(root):
- continue
- seen.add(root)
- result.append(root)
- return result
-
-
-def _get_scope_info(root: str, project_name: str | None, profile_name: str | None) -> Dict[str, str]:
- """Determine scope metadata for a skill root."""
- # determine origin
- origin = "default"
- if files.is_in_base_dir(root):
- rel = files.deabsolute_path(root)
- if rel.startswith("usr/") or rel.startswith("projects/"):
- origin = "user"
- if rel.startswith("projects/"):
- origin = "project"
-
- # determine scope
- scope = "global"
- scope_name = "global"
-
- if project_name and profile_name and ".a0proj" in root and "agents" in root:
- scope = "project_agent"
- scope_name = f"{project_name}:{profile_name}"
- elif project_name and ".a0proj" in root:
- scope = "project"
- scope_name = project_name
- elif profile_name and f"agents/{profile_name}" in root:
- scope = "agent"
- scope_name = profile_name
-
- return {
- "scope": scope,
- "scope_name": scope_name,
- "origin": origin,
- }
-
-
-def get_skills_list(
- project_name: str | None = None,
- profile_name: str | None = None,
-) -> List[Dict[str, Any]]:
- """Get list of all skills."""
- roots = _get_skill_roots_for_list(project_name, profile_name)
-
- entries: List[Dict[str, Any]] = []
- for root in roots:
- scope_info = _get_scope_info(root, project_name, profile_name)
-
- for skill_md in discover_skill_md_files(Path(root)):
- skill = skill_from_markdown(skill_md, include_content=False)
- if not skill:
- continue
-
- # generate skill_id
- rel_path = os.path.relpath(str(skill.path), root).replace("\\", "/")
- skill_id = f"{root}:{rel_path}"
-
- entries.append(
- {
- "skill_id": skill_id,
- "name": skill.name,
- "description": skill.description,
- "location": files.normalize_a0_path(str(skill.path)),
- "root": files.normalize_a0_path(root),
- "scope": scope_info["scope"],
- "scope_name": scope_info["scope_name"],
- "origin": scope_info["origin"],
- }
- )
- return entries
-
-
def delete_skill(
- skill_id: str,
- project_name: str | None = None,
- profile_name: str | None = None,
+ skill_path: str,
) -> None:
"""Delete a skill directory."""
- if not skill_id or ":" not in skill_id:
- raise ValueError("Invalid skill_id")
- root, rel_path = skill_id.split(":", 1)
- if not rel_path or rel_path in ("", "."):
- raise ValueError("Cannot delete root directory")
+ skill_path = files.get_abs_path(skill_path)
- allowed_roots = _get_skill_roots_for_list(project_name, profile_name)
- if root not in allowed_roots:
+ allowed_roots = get_skill_roots()
+ for root in allowed_roots:
+ if files.is_in_dir(skill_path, root):
+ break
+ else:
raise ValueError("Skill root not in current scope")
- # construct and validate path (prevent directory traversal)
- root_abs = os.path.abspath(root)
- skill_path = os.path.abspath(os.path.join(root, rel_path))
-
- # security check: ensure skill_path is within root
- if not skill_path.startswith(root_abs + os.sep) and skill_path != root_abs:
- raise ValueError("Invalid path: directory traversal detected")
-
+
if not os.path.isdir(skill_path):
raise FileNotFoundError("Skill directory not found")
diff --git a/python/tools/skills_tool.py b/python/tools/skills_tool.py
index d059e8af9..e0eff7c22 100644
--- a/python/tools/skills_tool.py
+++ b/python/tools/skills_tool.py
@@ -37,12 +37,12 @@ class SkillsTool(Tool):
if method == "load":
skill_name = str(kwargs.get("skill_name") or "").strip()
return Response(message=self._load(skill_name), break_loop=False)
- if method == "read_file":
- skill_name = str(kwargs.get("skill_name") or "").strip()
- file_path = str(kwargs.get("file_path") or "").strip()
- return Response(
- message=self._read_file(skill_name, file_path), break_loop=False
- )
+ # if method == "read_file":
+ # skill_name = str(kwargs.get("skill_name") or "").strip()
+ # file_path = str(kwargs.get("file_path") or "").strip()
+ # return Response(
+ # message=self._read_file(skill_name, file_path), break_loop=False
+ # )
return Response(
message=(
@@ -80,30 +80,30 @@ class SkillsTool(Tool):
lines.append("Tip: use skills_tool method=search or method=load for details.")
return "\n".join(lines)
- def _search(self, query: str) -> str:
- if not query:
- return "Error: 'query' is required for method=search."
-
- results = skills_helper.search_skills(
- query,
- limit=25,
- agent=self.agent,
- )
- if not results:
- return f"No skills matched query: {query!r}"
-
- lines: List[str] = []
- lines.append(f"Skills matching {query!r} ({len(results)}):")
- for s in results:
- desc = (s.description or "").strip()
- if len(desc) > 200:
- desc = desc[:200].rstrip() + "…"
- lines.append(f"- {s.name}: {desc}")
- lines.append("")
- lines.append(
- "Tip: use skills_tool method=load skill_name=<name> to load full instructions."
- )
- return "\n".join(lines)
+ # def _search(self, query: str) -> str:
+ # if not query:
+ # return "Error: 'query' is required for method=search."
+
+ # results = skills_helper.search_skills(
+ # query,
+ # limit=25,
+ # agent=self.agent,
+ # )
+ # if not results:
+ # return f"No skills matched query: {query!r}"
+
+ # lines: List[str] = []
+ # lines.append(f"Skills matching {query!r} ({len(results)}):")
+ # for s in results:
+ # desc = (s.description or "").strip()
+ # if len(desc) > 200:
+ # desc = desc[:200].rstrip() + "…"
+ # lines.append(f"- {s.name}: {desc}")
+ # lines.append("")
+ # lines.append(
+ # "Tip: use skills_tool method=load skill_name=<name> to load full instructions."
+ # )
+ # return "\n".join(lines)
def _load(self, skill_name: str) -> str:
@@ -171,35 +171,35 @@ class SkillsTool(Tool):
return "\n".join(lines)
- def _read_file(self, skill_name: str, file_path: str) -> str:
- if not skill_name:
- return "Error: 'skill_name' is required for method=read_file."
- if not file_path:
- return "Error: 'file_path' is required for method=read_file."
-
- skill = skills_helper.find_skill(
- skill_name,
- include_content=False,
- agent=self.agent,
- )
- if not skill:
- return f"Error: skill not found: {skill_name!r}."
-
- try:
- target = skills_helper.safe_path_within_dir(skill.path, file_path)
- except Exception as e:
- return f"Error: invalid file_path: {e}"
-
- if not target.exists() or not target.is_file():
- return f"Error: file not found: {file_path!r} (within skill {skill.name})"
-
- # Basic binary guard: if null byte present, do not dump
- content = target.read_bytes()
- if b"\x00" in content[:4096]:
- return f"Error: file appears to be binary; refusing to print raw bytes ({file_path})."
-
- text = content.decode("utf-8", errors="replace")
- return f"File: {file_path}\n\n{text}"
+ # def _read_file(self, skill_name: str, file_path: str) -> str:
+ # if not skill_name:
+ # return "Error: 'skill_name' is required for method=read_file."
+ # if not file_path:
+ # return "Error: 'file_path' is required for method=read_file."
+
+ # skill = skills_helper.find_skill(
+ # skill_name,
+ # include_content=False,
+ # agent=self.agent,
+ # )
+ # if not skill:
+ # return f"Error: skill not found: {skill_name!r}."
+
+ # try:
+ # target = skills_helper.safe_path_within_dir(skill.path, file_path)
+ # except Exception as e:
+ # return f"Error: invalid file_path: {e}"
+
+ # if not target.exists() or not target.is_file():
+ # return f"Error: file not found: {file_path!r} (within skill {skill.name})"
+
+ # # Basic binary guard: if null byte present, do not dump
+ # content = target.read_bytes()
+ # if b"\x00" in content[:4096]:
+ # return f"Error: file appears to be binary; refusing to print raw bytes ({file_path})."
+
+ # text = content.decode("utf-8", errors="replace")
+ # return f"File: {file_path}\n\n{text}"
def _list_skill_files(self, skill_dir: Path, *, max_files: int = 80) -> str:
if not skill_dir.exists():
diff --git a/webui/components/settings/skills/list.html b/webui/components/settings/skills/list.html
index 0639e68a9..3e93c8eb9 100644
--- a/webui/components/settings/skills/list.html
+++ b/webui/components/settings/skills/list.html
@@ -56,7 +56,7 @@
</template>
<div class="skills-list">
- <template x-for="skill in $store.skillsListStore.skills" :key="skill.skill_id">
+ <template x-for="skill in $store.skillsListStore.skills" :key="skill.path">
<div class="skill-card">
<div class="skill-header">
<div class="skill-title" x-text="skill.name || '(unnamed skill)'"></div>
@@ -74,7 +74,7 @@
<div class="skill-description" x-text="skill.description || 'No description provided.'"></div>
<div class="skill-location">
<span>Location:</span>
- <code x-text="skill.location"></code>
+ <code x-text="skill.path"></code>
</div>
</div>
</template>
diff --git a/webui/components/settings/skills/skills-list-store.js b/webui/components/settings/skills/skills-list-store.js
index dc7ff383e..40f3728ca 100644
--- a/webui/components/settings/skills/skills-list-store.js
+++ b/webui/components/settings/skills/skills-list-store.js
@@ -97,9 +97,7 @@ const model = {
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
action: "delete",
- skill_id: skill.skill_id,
- project_name: this.projectName || null,
- profile_name: this.profileName || null,
+ skill_path: skill.path,
}),
});
const result = await response.json().catch(() => ({}));