Skip to content

Agent Zero AI framework

Expose slash commands through skills

Alessandro63a52b3a4a42
diff --git a/helpers/skills.py b/helpers/skills.py
index a2a4e29cd..87ecc9afe 100644
--- a/helpers/skills.py
+++ b/helpers/skills.py
@@ -398,6 +398,54 @@ def list_skills(
return _filter_hidden_skills(agent, result)
+def list_slash_commands(agent: Agent | None = None) -> list[dict[str, Any]]:
+ """List effective, picker-visible slash commands for the agent's project."""
+ # Local import avoids the commands helper's import of split_frontmatter above.
+ from plugins._commands.helpers import commands as commands_helper
+
+ commands, _ = commands_helper.list_effective_commands(
+ _get_agent_project_name(agent)
+ )
+ return [
+ command
+ for command in commands
+ if not bool((command.get("frontmatter_extra") or {}).get("webui_hidden"))
+ ]
+
+
+def find_slash_command(
+ command_name: str,
+ agent: Agent | None = None,
+) -> dict[str, Any] | None:
+ """Find one effective slash command by its canonical ``/name``."""
+ target = str(command_name or "").strip().lstrip("/").lower()
+ if not target:
+ return None
+ return next(
+ (command for command in list_slash_commands(agent) if command["name"] == target),
+ None,
+ )
+
+
+def format_slash_command(command: dict[str, Any]) -> str:
+ """Render a slash command definition for a skills-tool result."""
+ lines = [f"Slash command: /{command['name']}"]
+ if description := str(command.get("description") or "").strip():
+ lines.append(f"Description: {description}")
+ if argument_hint := str(command.get("argument_hint") or "").strip():
+ lines.append(f"Arguments: {argument_hint}")
+ lines.append(f"Type: {command.get('command_type') or 'text'}")
+ if scope := str(command.get("scope_label") or "").strip():
+ lines.append(f"Scope: {scope}")
+
+ body = str(command.get("body") or "").strip()
+ if body:
+ if len(body) > 24000:
+ body = body[:24000].rstrip() + "\n\n[truncated]"
+ lines.extend(["", "Definition:", body])
+ return "\n".join(lines)
+
+
def delete_skill(
skill_path: str,
) -> None:
diff --git a/helpers/skills.py.dox.md b/helpers/skills.py.dox.md
index 363edfca4..2d2a522e8 100644
--- a/helpers/skills.py.dox.md
+++ b/helpers/skills.py.dox.md
@@ -27,6 +27,9 @@
- `parse_frontmatter(frontmatter_text: str) -> Tuple[Dict[str, Any], List[str]]`: Parse YAML frontmatter with PyYAML when available,
- `skill_from_markdown(skill_md_path: Path, include_content: bool=..., validate: bool=...) -> Optional[Skill]`
- `list_skills(agent: Agent | None=..., include_content: bool=..., include_hidden: bool=...) -> List[Skill]`: List skills, optionally filtered by agent scope.
+- `list_slash_commands(agent: Agent | None=...) -> list[dict[str, Any]]`: List picker-visible effective slash commands for the agent project.
+- `find_slash_command(command_name: str, agent: Agent | None=...) -> dict[str, Any] | None`
+- `format_slash_command(command: dict[str, Any]) -> str`
- `delete_skill(skill_path: str) -> None`: Delete a skill directory.
- `find_skill(skill_name: str, agent: Agent | None=..., include_content: bool=..., include_hidden: bool=..., validate: bool=...) -> Optional[Skill]`
- `load_skill_for_agent(skill_name: str, agent: Agent | None=...) -> str`: Load skill and format it as a complete string for agent context.
@@ -60,6 +63,7 @@
- `build_active_skills_prompt()` returns empty because selected skills are loaded through history, not prompt protocol.
- `search_skills()` normalizes query words, scores normal terms against skill names, and scores only long terms against tags/triggers; descriptions match only full query phrases so generic prose does not produce irrelevant suggestions.
- `find_skill(validate=False)` lets validation tooling resolve a skill with incomplete metadata while preserving runtime validation by default.
+- Slash command discovery is delegated to the built-in `_commands` helper through a local import, preserving its project/global/bundled/plugin precedence and avoiding its `split_frontmatter` import cycle. Picker-hidden commands remain hidden from Skills; reading a command returns its definition without executing it.
- Invalid `SKILL.md` frontmatter emits a once-per-path scan warning with the skipped skill path/name and a line number when the parser can identify one directly.
- Observed side-effect areas: filesystem reads, filesystem deletion, plugin state, settings/state persistence, context data, secret handling.
- Imported dependency areas include: `__future__`, `dataclasses`, `helpers`, `os`, `pathlib`, `re`, `typing`.
diff --git a/prompts/agent.system.tool.skills.md b/prompts/agent.system.tool.skills.md
index c9e5ad4f7..01861f3f4 100644
--- a/prompts/agent.system.tool.skills.md
+++ b/prompts/agent.system.tool.skills.md
@@ -5,7 +5,7 @@ common args: action skill_name query file_path
workflow:
- action `search`: find candidate skills by keywords or trigger phrases from the current task
- action `list`: discover available skills
-- action `load`: append one skill's full instructions to chat history by `skill_name`
+- action `load`: append one skill's full instructions to chat history by `skill_name`; use `skill_name=/command` to read an effective slash-command definition without invoking it
- action `read_file`: open one file inside a loaded skill directory
if the user says "find/search a skill", call `search` before `load` even when the likely skill name seems obvious
`read_file` requires both `skill_name` and `file_path`; load the skill first, then read `SKILL.md` or the named relative file
diff --git a/tests/test_skills_runtime.py b/tests/test_skills_runtime.py
index 8228e4c36..9ae3984ee 100644
--- a/tests/test_skills_runtime.py
+++ b/tests/test_skills_runtime.py
@@ -129,6 +129,63 @@ def test_active_skills_cap_is_twenty():
assert runtime.get_max_active_skills() == 20
+def test_slash_commands_use_agent_scope_and_hide_picker_hidden(monkeypatch):
+ plugins_pkg = types.ModuleType("plugins")
+ plugins_pkg.__path__ = []
+ commands_plugin_pkg = types.ModuleType("plugins._commands")
+ commands_plugin_pkg.__path__ = []
+ commands_helpers_pkg = types.ModuleType("plugins._commands.helpers")
+ commands_helpers_pkg.__path__ = []
+ commands = types.ModuleType("plugins._commands.helpers.commands")
+ calls = []
+ commands.list_effective_commands = lambda project_name: (
+ [
+ {
+ "name": "visible",
+ "description": "Visible command.",
+ "argument_hint": "<text>",
+ "command_type": "text",
+ "scope_label": "Project",
+ "body": "Template {text}",
+ "frontmatter_extra": {},
+ },
+ {
+ "name": "hidden",
+ "frontmatter_extra": {"webui_hidden": True},
+ },
+ ],
+ {"project_name": project_name},
+ )
+ commands_helpers_pkg.commands = commands
+ for name, module in (
+ ("plugins", plugins_pkg),
+ ("plugins._commands", commands_plugin_pkg),
+ ("plugins._commands.helpers", commands_helpers_pkg),
+ ("plugins._commands.helpers.commands", commands),
+ ):
+ monkeypatch.setitem(sys.modules, name, module)
+ monkeypatch.setattr(
+ runtime,
+ "_get_agent_project_name",
+ lambda _agent: calls.append("project") or "project",
+ )
+
+ command = runtime.find_slash_command("/visible", DummyAgent())
+
+ assert calls == ["project"]
+ assert command["name"] == "visible"
+ assert runtime.find_slash_command("/hidden", DummyAgent()) is None
+ assert runtime.format_slash_command(command) == (
+ "Slash command: /visible\n"
+ "Description: Visible command.\n"
+ "Arguments: <text>\n"
+ "Type: text\n"
+ "Scope: Project\n\n"
+ "Definition:\n"
+ "Template {text}"
+ )
+
+
def test_skills_config_can_raise_active_cap_above_default():
config = runtime.normalize_skills_config(
{
diff --git a/tests/test_tool_action_contracts.py b/tests/test_tool_action_contracts.py
index 45defc0fb..3203c4d45 100644
--- a/tests/test_tool_action_contracts.py
+++ b/tests/test_tool_action_contracts.py
@@ -130,6 +130,20 @@ def _load_skills_tool(monkeypatch, skill_root: Path):
tags=[],
)
skills_stub.list_skills = lambda *args, **kwargs: [fake_skill]
+ fake_command = {
+ "name": "summarize",
+ "description": "Summarize the current work.",
+ "argument_hint": "[focus]",
+ }
+ skills_stub.list_slash_commands = lambda *args, **kwargs: [fake_command]
+ skills_stub.find_slash_command = (
+ lambda command_name, *args, **kwargs: (
+ fake_command if command_name == "/summarize" else None
+ )
+ )
+ skills_stub.format_slash_command = (
+ lambda command: f"Slash command: /{command['name']}\nDefinition: prompt"
+ )
skills_stub.search_skills = lambda *args, **kwargs: [fake_skill]
skills_stub.find_skill = lambda *args, **kwargs: fake_skill
skills_stub.load_skill_for_agent = (
@@ -336,6 +350,28 @@ def test_skills_tool_defaults_missing_action_to_list(monkeypatch, tmp_path: Path
assert "Available skills" in response.message
assert "browser-form-workflows" in response.message
+ assert "Available slash commands" in response.message
+ assert "/summarize [focus]" in response.message
+
+
+def test_skills_tool_load_reads_slash_command_without_loading_a_skill(
+ monkeypatch, tmp_path: Path
+):
+ module = _load_skills_tool(monkeypatch, tmp_path)
+ agent = _FakeAgent()
+ tool = module.SkillsTool(
+ agent,
+ "skills_tool",
+ None,
+ {"action": "load", "skill_name": "/summarize"},
+ "",
+ None,
+ )
+
+ response = asyncio.run(tool.execute(**tool.args))
+
+ assert response.message == "Slash command: /summarize\nDefinition: prompt"
+ assert agent.context.get_data("loaded_skills") is None
def test_skills_tool_load_appends_skill_instructions_as_tool_result(
diff --git a/tools/skills_tool.py b/tools/skills_tool.py
index 99628b7a0..13cfc4df7 100644
--- a/tools/skills_tool.py
+++ b/tools/skills_tool.py
@@ -18,7 +18,7 @@ class SkillsTool(Tool):
Actions (tool_args.action):
- list
- search (query)
- - load (skill_name)
+ - load (skill_name, or /command)
- read_file (skill_name, file_path)
Script execution is handled by code_execution_tool directly.
@@ -144,23 +144,38 @@ class SkillsTool(Tool):
agent=self.agent,
include_content=False,
)
- if not skills:
- return "No skills found."
-
- # Stable output: sort by name
- skills_sorted = sorted(skills, key=lambda s: s.name.lower())
+ commands = skills_helper.list_slash_commands(agent=self.agent)
+ if not skills and not commands:
+ return "No skills or slash commands found."
lines: List[str] = []
- lines.append(f"Available skills ({len(skills_sorted)}):")
- for s in skills_sorted:
- tags = f" tags={','.join(s.tags)}" if s.tags else ""
- ver = f" v{s.version}" if s.version else ""
- desc = (s.description or "").strip()
- if len(desc) > 200:
- desc = desc[:200].rstrip() + "…"
- lines.append(f"- {s.name}{ver}{tags}: {desc}")
+ if skills:
+ # Stable output: sort by name
+ skills_sorted = sorted(skills, key=lambda s: s.name.lower())
+ lines.append(f"Available skills ({len(skills_sorted)}):")
+ for s in skills_sorted:
+ tags = f" tags={','.join(s.tags)}" if s.tags else ""
+ ver = f" v{s.version}" if s.version else ""
+ desc = (s.description or "").strip()
+ if len(desc) > 200:
+ desc = desc[:200].rstrip() + "..."
+ lines.append(f"- {s.name}{ver}{tags}: {desc}")
+
+ if commands:
+ if lines:
+ lines.append("")
+ lines.append(f"Available slash commands ({len(commands)}):")
+ for command in commands:
+ arguments = str(command.get("argument_hint") or "").strip()
+ desc = str(command.get("description") or "").strip()
+ if len(desc) > 200:
+ desc = desc[:200].rstrip() + "..."
+ suffix = f" {arguments}" if arguments else ""
+ lines.append(f"- /{command['name']}{suffix}: {desc}")
lines.append("")
- lines.append("Tip: use skills_tool action=search or action=load for details.")
+ lines.append(
+ "Tip: use skills_tool action=search for skills or action=load skill_name=/name to read a slash command."
+ )
return "\n".join(lines)
def _search(self, query: str) -> str:
@@ -197,6 +212,21 @@ class SkillsTool(Tool):
break_loop=False,
)
+ if skill_name.startswith("/"):
+ command = skills_helper.find_slash_command(skill_name, agent=self.agent)
+ if not command:
+ return Response(
+ message=(
+ f"Error: slash command not found: {skill_name!r}. "
+ "Try skills_tool action=list."
+ ),
+ break_loop=False,
+ )
+ return Response(
+ message=skills_helper.format_slash_command(command),
+ break_loop=False,
+ )
+
# Verify skill exists
skill = skills_helper.find_skill(
skill_name,
diff --git a/tools/skills_tool.py.dox.md b/tools/skills_tool.py.dox.md
index 1c3e70e07..dc0473be8 100644
--- a/tools/skills_tool.py.dox.md
+++ b/tools/skills_tool.py.dox.md
@@ -3,7 +3,7 @@
## Purpose
- Own the `skills_tool.py` agent tool.
-- This module searches, loads, and lists Agent Zero skills for the agent.
+- This module searches, loads, and lists Agent Zero skills and exposes effective slash-command definitions for the agent.
- Keep this file-level DOX profile synchronized with `skills_tool.py` because this directory is intentionally flat.
## Ownership
@@ -30,6 +30,7 @@
- Loaded skill IDs are stored in chat-wide context data.
- Duplicate loads omit the full body when the same skill name remains visible in model history.
- Missing or empty `action` defaults to `list`, and legacy `method` is accepted as a deprecated alias when `action` is absent.
+- `list` includes picker-visible slash commands for the active project. `load` with `skill_name=/name` reads the effective command definition without executing it or adding it to the loaded-skill ledger.
- Observed side-effect areas: filesystem reads, filesystem deletion, settings/state persistence, chat history persistence.
- Imported dependency areas include: `__future__`, `helpers`, `helpers.print_style`, `helpers.tool`, `pathlib`, `typing`.