Backend:
- agents_registry: five AIGC roles (剧本创作/视觉设计/分镜设计/素材资产/镜头脚本)
with zh personas, agent-chat mode text, and llm_role mapping onto the
models-page five-role binding surface (story/style/script/assets/video)
- agent_sessions.agent_key column + migration; sessions filter/exclusion;
named replies stamped with the owner agent's display name
- prompt assembly: per-agent persona + AGENT CHAT mode section replace the
generic sandbox text; mentions section suppressed for agent chats
- main loop routes the LLM through the agent's bound role
- skill admin surface: skill_overrides/skill_bindings/skill_versions tables,
PUT/PATCH/DELETE /api/agent/skills/{name} + bindings + versions/restore;
effective rule = global enable ∩ enabled per-agent binding; builtin skills
seeded to all five agents at upgrade; read_skill/list_skills gated for
named-agent sessions
Frontend:
- /agents is now the three-column A-darkroom page (agent list + skill library
/ chat with reused AgentChat / skill manager with editor, assignment
capsules, version history + rollback); per-agent model select synced with
the models page; narrow breakpoint turns the manager into a drawer
- legacy ?project=&task= deep links still route into the canvas flow
- i18n keys added to all 7 locales
Tests: tests/test_agent_roles.py + tests/test_skill_admin.py (27 cases)
Co-authored-by: multica-agent <github@multica.ai>
119 lines
4.2 KiB
Python
119 lines
4.2 KiB
Python
"""Skills agent plugin: list/read tools + prompt discovery section.
|
|
|
|
Thin tool wrappers over `agent.skills_store` (the shared home for
|
|
SKILLS-directory primitives — also used by the Settings API). See that
|
|
module for the layout, containment guards, and builtin seeding rules.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from typing import Any
|
|
|
|
from calliope.agent.harness.registry import ToolContext, ToolDefinition, ToolRegistry
|
|
from calliope.agent.skills_store import (
|
|
effective_skill_dirs,
|
|
ensure_builtin_skills,
|
|
list_skills as store_list_skills,
|
|
read_skill_file,
|
|
skills_prompt_lines,
|
|
)
|
|
|
|
logger = logging.getLogger("calliope.harness.plugins.skills")
|
|
|
|
_PROMPT_CAP = 24
|
|
|
|
|
|
async def t_list_skills(ctx: ToolContext, args: dict[str, Any]) -> dict[str, Any]:
|
|
agent_key = getattr(ctx, "agent_key", None)
|
|
if agent_key:
|
|
effective = effective_skill_dirs(agent_key)
|
|
skills = [s for s in store_list_skills(cap=None) if s["dir"] in effective]
|
|
else:
|
|
skills = store_list_skills()
|
|
return {"ok": True, "skills": skills, "count": len(skills)}
|
|
|
|
|
|
async def t_read_skill(ctx: ToolContext, args: dict[str, Any]) -> dict[str, Any]:
|
|
ensure_builtin_skills()
|
|
name = str(args.get("name") or "").strip()
|
|
rel = str(args.get("path") or "SKILL.md").strip()
|
|
agent_key = getattr(ctx, "agent_key", None)
|
|
if agent_key:
|
|
# Named-agent sessions may only load skills assigned to them AND
|
|
# enabled (HEL-613 gating — the discovery list matches this rule).
|
|
effective = effective_skill_dirs(agent_key)
|
|
known = {
|
|
d for d in effective
|
|
} | {s["name"] for s in store_list_skills(cap=None) if s["dir"] in effective}
|
|
if name not in known:
|
|
return {
|
|
"ok": False,
|
|
"error": (
|
|
f"skill '{name}' is not assigned to this agent or is disabled"
|
|
),
|
|
}
|
|
return read_skill_file(name, rel)
|
|
|
|
|
|
def skills_prompt_text(ctx: ToolContext) -> str | None:
|
|
"""Discovery section: names + descriptions only (cheap; bodies load via
|
|
read_skill). None when there are no skills."""
|
|
lines = skills_prompt_lines(agent_key=getattr(ctx, "agent_key", None))
|
|
if not lines:
|
|
return None
|
|
return (
|
|
"## Skills\nReusable expertise you can load with read_skill(name) — "
|
|
"call it BEFORE applying a skill, and follow its internal file "
|
|
"references via read_skill(name, path=...):\n" + "\n".join(lines[:_PROMPT_CAP])
|
|
)
|
|
|
|
|
|
async def _skills_section(ctx: ToolContext):
|
|
return skills_prompt_text(ctx)
|
|
|
|
|
|
def register(registry: ToolRegistry) -> None:
|
|
try:
|
|
ensure_builtin_skills()
|
|
except OSError:
|
|
logger.exception("builtin skill seeding failed")
|
|
|
|
registry.register(
|
|
ToolDefinition(
|
|
name="list_skills",
|
|
description=(
|
|
"List available skills (name + description + tags). Read one with "
|
|
"read_skill before applying it. Skills live in data_dir/skills/ — "
|
|
"users can add their own by dropping in a folder with a SKILL.md."
|
|
),
|
|
parameters={"type": "object", "properties": {}},
|
|
executor=t_list_skills,
|
|
category="skills",
|
|
requires_project=False,
|
|
)
|
|
)
|
|
registry.register(
|
|
ToolDefinition(
|
|
name="read_skill",
|
|
description=(
|
|
"Read a skill's full content. path defaults to SKILL.md; pass a "
|
|
'relative path for referenced files (e.g. path="references/'
|
|
'ref2va-format.md") when the skill body points at one.'
|
|
),
|
|
parameters={
|
|
"type": "object",
|
|
"properties": {
|
|
"name": {"type": "string", "description": "Skill directory name"},
|
|
"path": {
|
|
"type": "string",
|
|
"description": 'Relative file inside the skill dir (default "SKILL.md")',
|
|
},
|
|
},
|
|
"required": ["name"],
|
|
},
|
|
executor=t_read_skill,
|
|
category="skills",
|
|
requires_project=False,
|
|
)
|
|
)
|