Skip to content

Agent Zero AI framework

Make skills cap configurable

Alessandrob337ba3db86d
diff --git a/helpers/skills.py b/helpers/skills.py
index 082f1e0ab..8a042fe58 100644
--- a/helpers/skills.py
+++ b/helpers/skills.py
@@ -581,14 +581,46 @@ def validate_skill_md(skill_md_path: Path) -> List[str]:
return validate_skill(skill)
-def get_max_active_skills() -> int:
- return MAX_ACTIVE_SKILLS
+def _normalize_max_active_skills(value: Any) -> int:
+ if isinstance(value, bool):
+ return MAX_ACTIVE_SKILLS
+
+ try:
+ normalized = int(value)
+ except (TypeError, ValueError):
+ return MAX_ACTIVE_SKILLS
+
+ return normalized if normalized >= 1 else MAX_ACTIVE_SKILLS
+
+
+def get_max_active_skills(
+ agent: Agent | None = None,
+ project_name: str | None = None,
+) -> int:
+ if agent is None and project_name is None:
+ return MAX_ACTIVE_SKILLS
+
+ config = (
+ plugin_helpers.get_plugin_config(
+ ACTIVE_SKILLS_PLUGIN_NAME,
+ agent=agent,
+ project_name=project_name or "",
+ agent_profile="",
+ )
+ or {}
+ )
+ return _normalize_max_active_skills(config.get("max_active_skills"))
def normalize_skills_config(config: dict[str, Any] | None) -> dict[str, Any]:
normalized = dict(config or {})
+ max_active_skills = _normalize_max_active_skills(
+ normalized.get("max_active_skills")
+ )
+ normalized["max_active_skills"] = max_active_skills
normalized["active_skills"] = normalize_active_skills(
- normalized.get("active_skills")
+ normalized.get("active_skills"),
+ limit=max_active_skills,
)
normalized["hidden_skills"] = normalize_hidden_skills(
normalized.get("hidden_skills")
@@ -596,8 +628,15 @@ def normalize_skills_config(config: dict[str, Any] | None) -> dict[str, Any]:
return normalized
-def normalize_active_skills(raw: Any) -> list[ActiveSkillEntry]:
- return normalize_skill_entries(raw, limit=get_max_active_skills())
+def normalize_active_skills(
+ raw: Any,
+ *,
+ limit: int | None = None,
+) -> list[ActiveSkillEntry]:
+ return normalize_skill_entries(
+ raw,
+ limit=get_max_active_skills() if limit is None else limit,
+ )
def normalize_hidden_skills(raw: Any) -> list[ActiveSkillEntry]:
@@ -686,7 +725,10 @@ def get_scope_active_skills(agent: Agent | None) -> list[ActiveSkillEntry]:
)
or {}
)
- return normalize_active_skills(config.get("active_skills"))
+ return normalize_active_skills(
+ config.get("active_skills"),
+ limit=get_max_active_skills(agent=agent, project_name=project_name),
+ )
def get_scope_hidden_skills(agent: Agent | None) -> list[ActiveSkillEntry]:
@@ -709,7 +751,11 @@ def get_scope_hidden_skills(agent: Agent | None) -> list[ActiveSkillEntry]:
def get_chat_active_skills(context: Any | None) -> list[ActiveSkillEntry]:
if not context:
return []
- return normalize_active_skills(context.get_data(CONTEXT_DATA_NAME_CHAT_ACTIVE_SKILLS))
+ agent = context.get_agent() if hasattr(context, "get_agent") else None
+ return normalize_active_skills(
+ context.get_data(CONTEXT_DATA_NAME_CHAT_ACTIVE_SKILLS),
+ limit=get_max_active_skills(agent=agent),
+ )
def get_chat_disabled_skills(context: Any | None) -> list[ActiveSkillEntry]:
@@ -752,7 +798,7 @@ def _build_active_skills(
return []
context = getattr(agent, "context", None)
- effective_limit = get_max_active_skills() if limit is None else limit
+ effective_limit = get_max_active_skills(agent=agent) if limit is None else limit
scope_entries = get_scope_active_skills(agent)
current_chat_entries = list(
chat_entries if chat_entries is not None else get_chat_active_skills(context)
@@ -781,7 +827,7 @@ def _build_active_skills(
def get_active_skills(agent: Agent | None) -> list[ActiveSkillEntry]:
- return _build_active_skills(agent, limit=get_max_active_skills())
+ return _build_active_skills(agent, limit=get_max_active_skills(agent=agent))
def get_loaded_skill_entries(agent: Agent | None) -> list[ActiveSkillEntry]:
@@ -864,9 +910,10 @@ def activate_chat_skill(agent: Agent, entry: Any) -> list[ActiveSkillEntry]:
visible_entries=visible_entries,
limit=-1,
)
- if len(merged_entries) > get_max_active_skills():
+ max_active_skills = get_max_active_skills(agent=agent)
+ if len(merged_entries) > max_active_skills:
raise ValueError(
- f"You can activate at most {get_max_active_skills()} skills."
+ f"You can activate at most {max_active_skills} skills."
)
_store_context_active_skill_entries(
@@ -1219,7 +1266,11 @@ def _store_context_active_skill_entries(
key: str,
entries: list[ActiveSkillEntry],
) -> None:
- normalized_entries = normalize_active_skills(entries)
+ agent = context.get_agent() if hasattr(context, "get_agent") else None
+ normalized_entries = normalize_active_skills(
+ entries,
+ limit=get_max_active_skills(agent=agent),
+ )
context.set_data(key, normalized_entries or None)
diff --git a/plugins/_skills/README.md b/plugins/_skills/README.md
index 4a244cd87..3266b93cf 100644
--- a/plugins/_skills/README.md
+++ b/plugins/_skills/README.md
@@ -22,7 +22,7 @@ The shared active-skill state and prompt-resolution logic live in `helpers/skill
## Notes
- keep the active list short because every active skill is injected into prompt extras every turn
-- the framework-wide cap is 20 active skills
+- the default cap is 20 active skills, and it can be raised or lowered in Skills plugin config
- hidden skills are not capped because they are stored as control data, not injected into the prompt
- selected skills are stored in normalized `/a0/...` form so configs stay portable across development and Docker-style layouts
- scope defaults can be hidden or supplemented per chat without creating a new conversation
diff --git a/plugins/_skills/api/skills_catalog.py b/plugins/_skills/api/skills_catalog.py
index aadf3d9d6..38ec23bb5 100644
--- a/plugins/_skills/api/skills_catalog.py
+++ b/plugins/_skills/api/skills_catalog.py
@@ -114,7 +114,10 @@ class SkillsCatalog(ApiHandler):
"context_id": context.id if context else "",
"project_name": project_name,
"skills": catalog,
- "max_active_skills": skills.get_max_active_skills(),
+ "max_active_skills": skills.get_max_active_skills(
+ agent=agent,
+ project_name=project_name,
+ ),
"active_skills": [
self._serialize_entry(
entry,
diff --git a/plugins/_skills/default_config.yaml b/plugins/_skills/default_config.yaml
index 956598cff..dc771079f 100644
--- a/plugins/_skills/default_config.yaml
+++ b/plugins/_skills/default_config.yaml
@@ -1,2 +1,3 @@
+max_active_skills: 20
active_skills: []
hidden_skills: []
diff --git a/plugins/_skills/webui/config-store.js b/plugins/_skills/webui/config-store.js
index 10136f3a9..71032455b 100644
--- a/plugins/_skills/webui/config-store.js
+++ b/plugins/_skills/webui/config-store.js
@@ -9,6 +9,20 @@ import {
const CATALOG_API = "/plugins/_skills/skills_catalog";
const MAX_ACTIVE_SKILLS_FALLBACK = 20;
+function normalizeMaxActiveSkills(value) {
+ if (typeof value === "boolean") return MAX_ACTIVE_SKILLS_FALLBACK;
+
+ const numeric = typeof value === "number"
+ ? value
+ : Number.parseInt(String(value ?? "").trim(), 10);
+
+ if (!Number.isFinite(numeric) || numeric < 1) {
+ return MAX_ACTIVE_SKILLS_FALLBACK;
+ }
+
+ return Math.floor(numeric);
+}
+
function normalizeEntry(entry) {
if (!entry) return null;
if (typeof entry === "string") {
@@ -48,10 +62,11 @@ function entriesMatch(left, right) {
function ensureConfig(config) {
if (!config || typeof config !== "object") return;
+ config.max_active_skills = normalizeMaxActiveSkills(config.max_active_skills);
const activeSkills = Array.isArray(config.active_skills) ? config.active_skills : [];
const hiddenSkills = Array.isArray(config.hidden_skills) ? config.hidden_skills : [];
- config.active_skills = compactEntries(activeSkills, MAX_ACTIVE_SKILLS_FALLBACK);
+ config.active_skills = compactEntries(activeSkills, config.max_active_skills);
config.hidden_skills = compactEntries(hiddenSkills);
}
@@ -87,6 +102,7 @@ window.createSkillsConfigModel = (context, config) => ({
initDefaults() {
ensureConfig(config);
+ this.maxActiveSkills = config.max_active_skills;
this.mode = this.isChatMode ? "visible" : "pinned";
this.selectedSkills = [...this.activeEntries];
this.hiddenSkills = [...this.hiddenEntries];
@@ -110,6 +126,36 @@ window.createSkillsConfigModel = (context, config) => ({
return this.selectedSkills.length;
},
+ async applyMaxActiveSkills(value, { notify = false } = {}) {
+ ensureConfig(config);
+
+ const nextLimit = normalizeMaxActiveSkills(value);
+ const previousLimit = this.maxActiveSkills;
+ const previousCount = this.selectedSkills.length;
+
+ config.max_active_skills = nextLimit;
+ this.maxActiveSkills = nextLimit;
+
+ if (previousCount > nextLimit) {
+ this._setSelectedSkills(this.selectedSkills.slice(0, nextLimit));
+
+ if (notify) {
+ await toastFrontendInfo(
+ `Trimmed ${previousCount - nextLimit} pinned skill${previousCount - nextLimit === 1 ? "" : "s"} to match the new cap of ${nextLimit}.`,
+ "Skills"
+ );
+ }
+ return;
+ }
+
+ if (notify && previousLimit !== nextLimit) {
+ await toastFrontendInfo(
+ `Pinned skill cap set to ${nextLimit}.`,
+ "Skills"
+ );
+ }
+ },
+
get catalogMap() {
const byKey = new Map();
for (const skill of this.catalog) {
@@ -346,11 +392,15 @@ window.createSkillsConfigModel = (context, config) => ({
}
this.catalog = Array.isArray(response.skills) ? response.skills : [];
- this.maxActiveSkills = Number(response.max_active_skills) || MAX_ACTIVE_SKILLS_FALLBACK;
+ this.maxActiveSkills = normalizeMaxActiveSkills(response.max_active_skills);
+ if (!this.isChatMode) {
+ config.max_active_skills = this.maxActiveSkills;
+ }
this.applyCatalogState(response);
} catch (error) {
this.catalog = [];
- this.maxActiveSkills = MAX_ACTIVE_SKILLS_FALLBACK;
+ ensureConfig(config);
+ this.maxActiveSkills = config.max_active_skills;
this.chatContextAvailable = false;
this._setSelectedSkills(this.activeEntries);
this._setHiddenSkills(this.hiddenEntries);
@@ -382,7 +432,10 @@ window.createSkillsConfigModel = (context, config) => ({
}
this.catalog = Array.isArray(response.skills) ? response.skills : this.catalog;
- this.maxActiveSkills = Number(response.max_active_skills) || this.maxActiveSkills;
+ this.maxActiveSkills = normalizeMaxActiveSkills(response.max_active_skills);
+ if (!this.isChatMode) {
+ config.max_active_skills = this.maxActiveSkills;
+ }
this.chatContextAvailable = !!response.context_available;
this.applyCatalogState(response);
return true;
diff --git a/plugins/_skills/webui/config.html b/plugins/_skills/webui/config.html
index 09afa6635..04d77faf2 100644
--- a/plugins/_skills/webui/config.html
+++ b/plugins/_skills/webui/config.html
@@ -15,6 +15,26 @@
<div class="skills-layout">
<div class="section-title">Skills</div>
+ <template x-if="!isChatMode">
+ <div class="field">
+ <div class="field-label">
+ <div class="field-title">Pinned skill cap</div>
+ <div class="field-description">
+ Maximum number of pinned skills stored in this scope. Higher values inject more instructions into every prompt.
+ </div>
+ </div>
+ <div class="field-control">
+ <input
+ type="number"
+ min="1"
+ step="1"
+ x-model.number="config.max_active_skills"
+ @change="applyMaxActiveSkills(config.max_active_skills, { notify: true })"
+ >
+ </div>
+ </div>
+ </template>
+
<div class="skills-toolbar">
<label class="skills-search">
<span class="material-symbols-outlined">search</span>
diff --git a/tests/test_skills_runtime.py b/tests/test_skills_runtime.py
index 6f3a72394..4a64e66b2 100644
--- a/tests/test_skills_runtime.py
+++ b/tests/test_skills_runtime.py
@@ -94,6 +94,7 @@ runtime = _load_skills_helper_module()
class DummyContext:
def __init__(self):
self.data = {}
+ self.agent = None
def get_data(self, key, recursive=True):
return self.data.get(key)
@@ -101,15 +102,26 @@ class DummyContext:
def set_data(self, key, value, recursive=True):
self.data[key] = value
+ def get_agent(self):
+ return self.agent
+
class DummyAgent:
def __init__(self):
self.context = DummyContext()
+ self.context.agent = self
self.data = {}
-def _scope_config(entries):
- return {"active_skills": entries}
+def _scope_config(entries=None, *, hidden_entries=None, max_active_skills=None):
+ config = {}
+ if entries is not None:
+ config["active_skills"] = entries
+ if hidden_entries is not None:
+ config["hidden_skills"] = hidden_entries
+ if max_active_skills is not None:
+ config["max_active_skills"] = max_active_skills
+ return config
def test_active_skills_cap_is_twenty():
@@ -117,6 +129,18 @@ def test_active_skills_cap_is_twenty():
assert runtime.get_max_active_skills() == 20
+def test_skills_config_can_raise_active_cap_above_default():
+ config = runtime.normalize_skills_config(
+ {
+ "max_active_skills": 25,
+ "active_skills": [{"name": f"Skill {index}"} for index in range(25)],
+ }
+ )
+
+ assert config["max_active_skills"] == 25
+ assert len(config["active_skills"]) == 25
+
+
def test_hidden_skills_are_not_capped_like_active_skills():
agent = DummyAgent()
entries = [{"name": f"Hidden {index}"} for index in range(25)]
@@ -396,6 +420,38 @@ def test_activating_new_skill_fails_once_limit_is_full(monkeypatch):
assert len(runtime.get_active_skills(agent)) == 20
+def test_chat_activation_respects_scope_configured_cap(monkeypatch):
+ monkeypatch.setattr(
+ runtime.plugin_helpers,
+ "get_plugin_config",
+ lambda *args, **kwargs: _scope_config(max_active_skills=25),
+ )
+ agent = DummyAgent()
+
+ for index in range(21):
+ runtime.activate_chat_skill(agent, {"name": f"Extra {index}"})
+
+ assert len(runtime.get_chat_active_skills(agent.context)) == 21
+ assert len(runtime.get_active_skills(agent)) == 21
+
+
+def test_activating_new_skill_uses_scope_configured_limit(monkeypatch):
+ monkeypatch.setattr(
+ runtime.plugin_helpers,
+ "get_plugin_config",
+ lambda *args, **kwargs: _scope_config(
+ [{"name": f"Pinned {index}"} for index in range(3)],
+ max_active_skills=3,
+ ),
+ )
+ agent = DummyAgent()
+
+ with pytest.raises(ValueError, match="at most 3"):
+ runtime.activate_chat_skill(agent, {"name": "Overflow"})
+
+ assert len(runtime.get_active_skills(agent)) == 3
+
+
def test_hidden_skills_filter_agent_visible_skill_catalog(monkeypatch, tmp_path: Path):
skills_root = tmp_path / "skills"
for name in ("alpha-skill", "beta-skill"):