The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
perf(skills): stop inlining category descriptions in the skills index
Luis Arriaga0ace5c0e1914
diff --git a/agent/prompt_builder.py b/agent/prompt_builder.pyindex 68375dea3d4..4c4650412a2 100644--- a/agent/prompt_builder.py+++ b/agent/prompt_builder.py@@ -1280,20 +1280,6 @@ def _entry_name(entry: dict) -> str:return entry.get("frontmatter_name") or entry.get("skill_name") or ""-def _read_category_descriptions(root: Path, log_fmt: str) -> dict[str, str]:- """``description`` from every DESCRIPTION.md under *root*, keyed by category path."""- found: dict[str, str] = {}- for desc_file in iter_skill_index_files(root, "DESCRIPTION.md"):- try:- cat_desc = parse_frontmatter(desc_file.read_text(encoding="utf-8-sig"))[0].get("description")- if cat_desc:- rel = desc_file.relative_to(root)- found["/".join(rel.parts[:-1]) if len(rel.parts) > 1 else "general"] = str(cat_desc).strip().strip("'\"")- except Exception as e:- logger.debug(log_fmt, desc_file, e)- return found--def _scan_extra_root(root: Path, skill_files, tier: int, log_fmt: str) -> list[tuple[dict, bool]]:"""``(entry tagged with tier/root, is_compatible)`` for every skill under a project/create_dir/external root."""rows = []@@ -1318,7 +1304,7 @@ def _label_visible_entries(visible_entries: list[dict], skills_by_category: dictdef _render_skills_index(- skills_by_category: dict[str, list[tuple[str, str]]], category_descriptions: dict[str, str],+ skills_by_category: dict[str, list[tuple[str, str]]],compact_categories: frozenset[str] | None, available_tools: set[str] | None, unloadable: list[str] = (),) -> str:"""Render the ## Skills block; "" when there is nothing to list. *unloadable* names (different skills@@ -1345,8 +1331,7 @@ def _render_skills_index(if category in demoted:index_lines.append(f" {category} [names only]: {', '.join(sorted({n for n, _ in entries}))}")continue- cat_desc = category_descriptions.get(category, "")- index_lines.append(f" {category}: {cat_desc}" if cat_desc else f" {category}:")+ index_lines.append(f" {category}:")seen = set()for name, desc in sorted(entries, key=lambda x: x[0]): # stable: first entry per name winsif name not in seen:@@ -1426,14 +1411,12 @@ def _build_skills_system_prompt_inner(or not _skill_should_show(conditions, available_tools, available_toolsets, _platform_hint or None))skills_by_category: dict[str, list[tuple[str, str]]] = {}- category_descriptions: dict[str, str] = {}# Disk snapshot (fast path) vs. full scan: both yield (entry, is_compatible) pairs so labeling runs identically.if snapshot is not None:# Platforms and app presence are host facts that change without SKILL.md changing: re-evaluate both.candidates = [(entry, skill_matches_platform_list(entry.get("platforms") or [])and skill_matches_apps({"requires_apps": entry.get("requires_apps") or []}))for entry in snapshot.get("skills", []) if isinstance(entry, dict)]- category_descriptions = {str(k): str(v) for k, v in (snapshot.get("category_descriptions") or {}).items()}else:candidates = []for skill_file in iter_skill_index_files(skills_dir, "SKILL.md"):@@ -1450,8 +1433,6 @@ def _build_skills_system_prompt_inner(rows += [({**entry, "tier": TIER_LOCAL, "root": skills_dir}, ok) for entry, ok in candidates]for tier, root in ((t, d) for t, d in extra_roots if t != TIER_PROJECT and d.exists()):rows += _scan_extra_root(root, iter_skill_index_files(root, "SKILL.md"), tier, "Error reading external skill %s: %s")- for cat, cat_desc in _read_category_descriptions(root, "Could not read external skill description %s: %s").items():- category_descriptions.setdefault(cat, cat_desc)resolved = resolve_skill_catalog([{**entry, "name": _entry_name(entry), "path": entry["root"] / entry["rel"],"visible": ok and not hides(entry.get("skill_name") or "", entry.get("conditions") or {})}@@ -1468,17 +1449,16 @@ def _build_skills_system_prompt_inner(listed.add(name)skills_by_category.setdefault("plugin", []).append((name, desc))if snapshot is None: # persist for fast cold-start reuse (best-effort)- category_descriptions.update(_read_category_descriptions(skills_dir, "Could not read skill description %s: %s"))try:atomic_json_write(_skills_prompt_snapshot_path(), {"version": _SKILLS_SNAPSHOT_VERSION, "manifest": _build_skills_manifest(skills_dir),- "skills": [entry for entry, _ in candidates], "category_descriptions": category_descriptions,+ "skills": [entry for entry, _ in candidates],})except Exception as e:logger.debug("Could not write skills prompt snapshot: %s", e)unloadable = sorted({e["name"] for e in visible_entries if not e["load_name"]})- result = _render_skills_index(skills_by_category, category_descriptions, compact_categories, available_tools, unloadable)+ result = _render_skills_index(skills_by_category, compact_categories, available_tools, unloadable)with _SKILLS_PROMPT_CACHE_LOCK:_SKILLS_PROMPT_CACHE[cache_key] = result_SKILLS_PROMPT_CACHE.move_to_end(cache_key)