AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
refactor(backend/copilot): rename and raise per-expert skill cap to 150 (#14740)
wofiporiab4075c431be8
diff --git a/autogpt_platform/backend/backend/api/features/experts/models.py b/autogpt_platform/backend/backend/api/features/experts/models.pyindex 0080be4f52..ecae5407b9 100644--- a/autogpt_platform/backend/backend/api/features/experts/models.py+++ b/autogpt_platform/backend/backend/api/features/experts/models.py@@ -420,7 +420,10 @@ class ExpertSkillsUpdate(BaseModel):expert must be library skills (default or uploaded); names already onthe expert are kept as-is so marketplace skills survive a round-trip."""- skills: list[str] = Field(max_length=50)+ # As many names as the expert's folder can hold: MAX_SKILLS_PER_EXPERT in+ # copilot/tools/skills.py, which this module cannot import (the copilot+ # tools import these models); models_test pins the two together.+ skills: list[str] = Field(max_length=150)# Store listing versions to attach as marketplace skills; each resolves# to the listing's public name, the same way the raise flow records them.marketplace_listing_ids: list[str] = Field(default_factory=list, max_length=20)diff --git a/autogpt_platform/backend/backend/api/features/experts/models_test.py b/autogpt_platform/backend/backend/api/features/experts/models_test.pyindex 9b1489ef59..f00282fd67 100644--- a/autogpt_platform/backend/backend/api/features/experts/models_test.py+++ b/autogpt_platform/backend/backend/api/features/experts/models_test.py@@ -8,6 +8,7 @@ from backend.api.features.experts.models import (EXPERT_IDENTITY_MAX_LENGTH,Expert,ExpertDayOneItem,+ ExpertSkillsUpdate,ExpertSoulFieldsPatch,ExpertSoulUpdate,RaiseAttachment,@@ -18,6 +19,7 @@ from backend.api.features.experts.models import (encode_voice_preferences,validate_avatar_url,)+from backend.copilot.tools.skills import MAX_SKILLS_PER_EXPERTdef test_soul_update_strips_optional_fields():@@ -268,3 +270,14 @@ def test_validate_avatar_url_accepts_https_and_relative_paths(def test_validate_avatar_url_rejects_unsafe_values(value: str):with pytest.raises(ValueError):validate_avatar_url(value)+++def test_skill_list_bound_matches_the_per_expert_cap():+ """``ExpertSkillsUpdate`` cannot import the cap (circular import), so the+ literal it carries is pinned here to the constant the folder enforces."""+ bound = next(+ m.max_length+ for m in ExpertSkillsUpdate.model_fields["skills"].metadata+ if getattr(m, "max_length", None) is not None+ )+ assert bound == MAX_SKILLS_PER_EXPERTdiff --git a/autogpt_platform/backend/backend/api/features/skills/routes.py b/autogpt_platform/backend/backend/api/features/skills/routes.pyindex 634dfeab91..617f0145f4 100644--- a/autogpt_platform/backend/backend/api/features/skills/routes.py+++ b/autogpt_platform/backend/backend/api/features/skills/routes.py@@ -114,7 +114,7 @@ async def upload_copilot_skill(Parses the canonical frontmatter + body, then reuses:func:`backend.copilot.tools.skills.store_user_skill` so an uploaded skillis validated, capped, and persisted exactly like one the copilot distils- via ``store_skill``. Malformed files return 400, the per-user cap returns+ via ``store_skill``. Malformed files return 400, the per-expert cap returns409, and an existing slug is overwritten (upsert)."""await _require_skill_owner(user_id, expert_id)@@ -194,7 +194,7 @@ async def _store_uploaded_skill(files: list[SkillFile] | None = None,) -> ParsedSkill:"""Persist a parsed upload, mapping each refusal to its status: 409 at the- per-user cap, 413 over a package limit, 400 for anything malformed."""+ per-expert cap, 413 over a package limit, 400 for anything malformed."""try:return await store_user_skill(user_id,diff --git a/autogpt_platform/backend/backend/api/features/skills/routes_test.py b/autogpt_platform/backend/backend/api/features/skills/routes_test.pyindex 799d06e6c2..485965c0a0 100644--- a/autogpt_platform/backend/backend/api/features/skills/routes_test.py+++ b/autogpt_platform/backend/backend/api/features/skills/routes_test.py@@ -282,10 +282,10 @@ def test_upload_copilot_skill_rejects_malformed_markdown() -> None:def test_upload_copilot_skill_returns_409_when_at_cap(mocker: pytest_mock.MockFixture,) -> None:- """The per-user cap surfaces as 409 so the UI can prompt a delete."""+ """The per-expert cap surfaces as 409 so the UI can prompt a delete."""mocker.patch("backend.api.features.skills.routes.store_user_skill",- AsyncMock(side_effect=SkillLimitError("Skill limit reached (50).")),+ AsyncMock(side_effect=SkillLimitError("Skill limit reached (150).")),)response = client.post("/skills", json={"content": _VALID_SKILL_MD})diff --git a/autogpt_platform/backend/backend/copilot/prompting.py b/autogpt_platform/backend/backend/copilot/prompting.pyindex 70da9a4c78..6561f9028c 100644--- a/autogpt_platform/backend/backend/copilot/prompting.py+++ b/autogpt_platform/backend/backend/copilot/prompting.py@@ -307,7 +307,7 @@ generalise (e.g. "what's the user's email?"), or a procedure alreadycovered by an existing skill — check `<available_skills>` first andprefer extending an existing skill via re-writing (re-run`tool:store_skill` with the same `name`) over creating a near-duplicate.-The index is a finite resource (~50 slots/user); use `tool:list_skills`+The index is a finite resource (~150 slots per expert); use `tool:list_skills`to inspect the current registry and `tool:delete_skill` to remove staleentries.diff --git a/autogpt_platform/backend/backend/copilot/tools/skills.py b/autogpt_platform/backend/backend/copilot/tools/skills.pyindex 4ced28f5df..38edf7ce10 100644--- a/autogpt_platform/backend/backend/copilot/tools/skills.py+++ b/autogpt_platform/backend/backend/copilot/tools/skills.py@@ -69,13 +69,13 @@ logger = logging.getLogger(__name__)# Limits — keep the per-turn <available_skills> index small enough that it# does not strain Anthropic prompt caches and does not crowd out the user's# turn budget. A typical user skill line lands around 150-200 chars-# (~50 tok), so 50 entries ≈ 2.5k tokens. Filling every description and-# trigger to the per-field caps below is roughly 22k tokens under the same+# (~50 tok), so 150 entries ≈ 7.5k tokens. Filling every description and+# trigger to the per-field caps below is roughly 66k tokens under the same# estimate; actual token cost varies by content and tokenizer.# Built-in seeded skills are tiny so first-touch users see well under# 200 tokens of overhead.# ----------------------------------------------------------------------------MAX_USER_SKILLS = 50+MAX_SKILLS_PER_EXPERT = 150MAX_NAME_CHARS = 64MAX_DESCRIPTION_CHARS = 1024# Loaded only on activation, so it costs nothing per turn; 50k clears@@ -387,7 +387,7 @@ async def resolve_skill_owner(# Redis lock key for serialising store_skill writes per user. A per-user# distributed lock turns the otherwise-racy "count existing skills, then# write a new one" into an atomic critical section so two concurrent-# ``store_skill`` calls cannot both pass the MAX_USER_SKILLS check.+# ``store_skill`` calls cannot both pass the MAX_SKILLS_PER_EXPERT check.# Held only for the duration of the count + write; skill reads stay# lock-free._SKILL_WRITE_LOCK_KEY_PREFIX = "copilot:skill_write:"@@ -558,7 +558,7 @@ class BuiltInSkillError(Exception):class SkillLimitError(Exception):- """Raised by :func:`store_user_skill` when the per-user cap is reached."""+ """Raised by :func:`store_user_skill` when the per-expert cap is reached."""async def delete_user_skill(@@ -673,7 +673,7 @@ async def store_user_skill(``None``) and becomes that owner's skill. Shared by the ``store_skill``copilot tool and the REST ``POST /skills`` upload endpoint so both honourthe same validation, per-owner cap, and write-lock semantics. Raises :class:`ValueError` for any validation- failure, :class:`SkillLimitError` when the per-user cap is reached, and+ failure, :class:`SkillLimitError` when the per-expert cap is reached, andpropagates ``VirusDetectedError`` / ``VirusScanError`` (and any otherworkspace write error) to the caller.@@ -717,7 +717,7 @@ async def store_user_skill(validate_package(SkillPackage(skill_md=rendered, files=files))# Serialise the count-then-write critical section per-user so two- # concurrent writers cannot both pass the MAX_USER_SKILLS check.+ # concurrent writers cannot both pass the MAX_SKILLS_PER_EXPERT check.# ``AsyncClusterLock.try_acquire`` is non-blocking, so poll for up to# ~1s before falling back to the strict-cap unlocked path below — without# the wait, two near-simultaneous calls at MAX-1 both proceed unlocked,@@ -756,7 +756,7 @@ async def store_user_skill(# the copy would need, so it would stall on itself for every name.existing = await list_user_skills(user_id, expert_id, scope, heal_missing=False)existing_slugs = {s.name for s in existing}- at_cap = len(existing_slugs) >= MAX_USER_SKILLS+ at_cap = len(existing_slugs) >= MAX_SKILLS_PER_EXPERTis_new = name not in existing_slugsif at_cap and (is_new or not lock_held):if not lock_held:@@ -768,7 +768,7 @@ async def store_user_skill(is_new,)raise SkillLimitError(- f"Skill limit reached ({MAX_USER_SKILLS}). "+ f"Skill limit reached ({MAX_SKILLS_PER_EXPERT}). ""Delete an unused skill first.")@@ -2166,7 +2166,7 @@ class ListSkillsTool(BaseTool):# the query but depth cannot, so a page of newest-first rows can be entirely# nested SKILL.md files and yield no roots at all; the bound is the most a# compliant folder can hold, every allowed skill carrying a full package.-_MAX_ROOT_SCAN = MAX_USER_SKILLS * (MAX_PACKAGE_FILES + 1)+_MAX_ROOT_SCAN = MAX_SKILLS_PER_EXPERT * (MAX_PACKAGE_FILES + 1)async def _list_skill_roots(@@ -2179,10 +2179,10 @@ async def _list_skill_roots(the page and hide older skills, which is the defect this listing existsto avoid."""- page = MAX_USER_SKILLS * 4 # over-fetch in case of strays+ page = MAX_SKILLS_PER_EXPERT * 4 # over-fetch in case of straysroots: list[tuple[Any, str]] = []offset = 0- while offset < _MAX_ROOT_SCAN and len(roots) <= MAX_USER_SKILLS:+ while offset < _MAX_ROOT_SCAN and len(roots) <= MAX_SKILLS_PER_EXPERT:rows = await manager.list_files(path=f"{folder}/",limit=page,diff --git a/autogpt_platform/backend/backend/copilot/tools/skills_test.py b/autogpt_platform/backend/backend/copilot/tools/skills_test.pyindex a071b44023..fbafaa377f 100644--- a/autogpt_platform/backend/backend/copilot/tools/skills_test.py+++ b/autogpt_platform/backend/backend/copilot/tools/skills_test.py@@ -23,9 +23,9 @@ from backend.copilot.tools.skills import (MAX_PACKAGE_BYTES,MAX_PACKAGE_FILE_BYTES,MAX_PACKAGE_FILES,+ MAX_SKILLS_PER_EXPERT,MAX_TRIGGER_CHARS,MAX_TRIGGERS,- MAX_USER_SKILLS,BuiltInSkillError,DeleteSkillResponse,DeleteSkillTool,@@ -60,6 +60,16 @@ from backend.copilot.tools.skills import ()from backend.util.exceptions import ConflictError+# ---------------------------------------------------------------------------+# Constants+# ---------------------------------------------------------------------------+++def test_max_skills_per_expert_cap_constant():+ """The cap #14692 asked for: room for a 50-skill bundle and the owner's own."""+ assert MAX_SKILLS_PER_EXPERT == 150++# ---------------------------------------------------------------------------# Round-trip# ---------------------------------------------------------------------------@@ -562,13 +572,13 @@ async def test_store_skill_strips_server_injected_tags_from_body():@pytest.mark.asyncio-async def test_store_skill_enforces_max_user_skills_cap():- """Hitting the per-user cap returns ErrorResponse instead of- silently appending the (MAX_USER_SKILLS+1)-th skill."""+async def test_store_skill_enforces_max_skills_per_expert_cap():+ """Hitting the per-expert cap returns ErrorResponse instead of+ silently appending the (MAX_SKILLS_PER_EXPERT+1)-th skill."""tool = StoreSkillTool()fake_manager = _FakeWorkspaceManager()- # Pre-fill the workspace with MAX_USER_SKILLS distinct slugs.- for i in range(MAX_USER_SKILLS):+ # Pre-fill the workspace with MAX_SKILLS_PER_EXPERT distinct slugs.+ for i in range(MAX_SKILLS_PER_EXPERT):slug = f"skill_{i}"fake_manager.files[f"/skills/{slug}/SKILL.md"] = render_skill_markdown(ParsedSkill(name=slug, description="desc", body="body")@@ -590,11 +600,11 @@ async def test_store_skill_at_cap_refuses_when_lock_not_held():"""When ``AsyncClusterLock.try_acquire`` returns a DIFFERENT owner(i.e. contention or Redis hiccup) the fallback path is unlocked.In that branch the cap check must be treated strictly — refuse the- write at-or-above MAX_USER_SKILLS even on an upsert, otherwise two+ write at-or-above MAX_SKILLS_PER_EXPERT even on an upsert, otherwise twoconcurrent writers could both see N==cap and both commit."""tool = StoreSkillTool()fake_manager = _FakeWorkspaceManager()- for i in range(MAX_USER_SKILLS):+ for i in range(MAX_SKILLS_PER_EXPERT):slug = f"skill_{i}"fake_manager.files[f"/skills/{slug}/SKILL.md"] = render_skill_markdown(ParsedSkill(name=slug, description="old", body="old")@@ -645,10 +655,10 @@ async def test_store_skill_at_cap_refuses_when_lock_not_held():@pytest.mark.asyncioasync def test_store_skill_upsert_does_not_trip_cap():"""Overwriting an existing skill must NOT count toward the cap —- re-storing the same name when already at MAX_USER_SKILLS is fine."""+ re-storing the same name when already at MAX_SKILLS_PER_EXPERT is fine."""tool = StoreSkillTool()fake_manager = _FakeWorkspaceManager()- for i in range(MAX_USER_SKILLS):+ for i in range(MAX_SKILLS_PER_EXPERT):slug = f"skill_{i}"fake_manager.files[f"/skills/{slug}/SKILL.md"] = render_skill_markdown(ParsedSkill(name=slug, description="old", body="old")@@ -2370,7 +2380,7 @@ async def test_nested_skill_md_files_cannot_hide_a_root_skill():"""A package shipping its own example SKILL.md files fills the capped,newest-first page; the listing must page past them to the real roots."""fake = _package_manager(slug="aaa-oldest")- for i in range(MAX_USER_SKILLS * 4 + 10):+ for i in range(MAX_SKILLS_PER_EXPERT * 4 + 10):fake.files[f"/skills/aaa-oldest/references/e{i:04d}/SKILL.md"] = b"example"with _patch_skills_path(fake):skills = await _list_user_skills_from_workspace("user-1")diff --git a/autogpt_platform/backend/backend/copilot/tools/workspace_files.py b/autogpt_platform/backend/backend/copilot/tools/workspace_files.pyindex 387f8f2ff8..d087897021 100644--- a/autogpt_platform/backend/backend/copilot/tools/workspace_files.py+++ b/autogpt_platform/backend/backend/copilot/tools/workspace_files.py@@ -671,7 +671,7 @@ class ReadWorkspaceFileTool(BaseTool):# Paths under ``/skills/`` and ``/experts/<id>/skills/`` are managed by the# skills registry — the ``store_skill`` / ``delete_skill`` tools enforce-# frontmatter validation, the per-user cap, name regex, and content+# frontmatter validation, the per-expert cap, name regex, and content# sanitisation. Allowing plain write_workspace_file / delete_workspace_file# there would bypass all of that and let the model accidentally (or# maliciously) corrupt the registry. Reads stay open so the model can stilldiff --git a/autogpt_platform/backend/backend/copilot/tools/workspace_files_test.py b/autogpt_platform/backend/backend/copilot/tools/workspace_files_test.pyindex c6ad5be81e..3bc91f6664 100644--- a/autogpt_platform/backend/backend/copilot/tools/workspace_files_test.py+++ b/autogpt_platform/backend/backend/copilot/tools/workspace_files_test.py@@ -862,7 +862,7 @@ class TestSkillsRegistryACL:"""Writes and deletes targeting either skills folder — Otto's``/skills/`` or an expert's ``/experts/<id>/skills/`` — must go throughthe skills registry (``store_skill`` / ``delete_skill``) which enforces- frontmatter validation, the per-user cap, and content sanitisation.+ frontmatter validation, the per-expert cap, and content sanitisation.A direct workspace write would bypass all of that."""@pytest.mark.asynciodiff --git a/autogpt_platform/frontend/src/app/api/openapi.json b/autogpt_platform/frontend/src/app/api/openapi.jsonindex ad4f11b35d..039616c059 100644--- a/autogpt_platform/frontend/src/app/api/openapi.json+++ b/autogpt_platform/frontend/src/app/api/openapi.json@@ -14023,7 +14023,7 @@"post": {"tags": ["v1", "skills"],"summary": "Upload a copilot skill from a SKILL.md file",- "description": "Create a user-distilled skill from an uploaded ``SKILL.md`` file.\n\nParses the canonical frontmatter + body, then reuses\n:func:`backend.copilot.tools.skills.store_user_skill` so an uploaded skill\nis validated, capped, and persisted exactly like one the copilot distils\nvia ``store_skill``. Malformed files return 400, the per-user cap returns\n409, and an existing slug is overwritten (upsert).",+ "description": "Create a user-distilled skill from an uploaded ``SKILL.md`` file.\n\nParses the canonical frontmatter + body, then reuses\n:func:`backend.copilot.tools.skills.store_user_skill` so an uploaded skill\nis validated, capped, and persisted exactly like one the copilot distils\nvia ``store_skill``. Malformed files return 400, the per-expert cap returns\n409, and an existing slug is overwritten (upsert).","operationId": "uploadCopilotSkill","security": [{ "HTTPBearerJWT": [] }],"parameters": [@@ -21971,7 +21971,7 @@"skills": {"items": { "type": "string" },"type": "array",- "maxItems": 50,+ "maxItems": 150,"title": "Skills"},"marketplace_listing_ids": {