Add agent and skill system: implement Agent and Skill classes, register media and naked agents, and create media_info demo skill
Build and Push Agent API / build (push) Successful in 5s
Build and Push Agent API / build (push) Successful in 5s
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
"""
|
||||
Skill system — each skill is a piece of domain knowledge or a capability
|
||||
that can be attached to an agent to shape its behavior and system prompt.
|
||||
|
||||
A Skill is a lightweight object with:
|
||||
- name : short identifier (e.g. "media_info")
|
||||
- description : human-readable summary
|
||||
- prompt_fragment : extra text injected into the agent's system prompt
|
||||
"""
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Dict
|
||||
|
||||
|
||||
@dataclass
|
||||
class Skill:
|
||||
name: str
|
||||
description: str
|
||||
prompt_fragment: str = ""
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Global skill registry — populated at startup / import time
|
||||
# ---------------------------------------------------------------------------
|
||||
_skill_registry: Dict[str, Skill] = {}
|
||||
|
||||
|
||||
def register(skill: Skill) -> None:
|
||||
"""Register a skill so agents can look it up by name."""
|
||||
_skill_registry[skill.name] = skill
|
||||
|
||||
|
||||
def get(name: str) -> Skill | None:
|
||||
"""Return a registered skill by name, or None."""
|
||||
return _skill_registry.get(name)
|
||||
|
||||
|
||||
def list_all() -> Dict[str, Skill]:
|
||||
"""Return a shallow copy of the registry."""
|
||||
return dict(_skill_registry)
|
||||
|
||||
|
||||
def get_combined_prompt(skill_names: list[str], base_prompt: str = "") -> str:
|
||||
"""Build a system prompt from a base prompt + requested skill fragments."""
|
||||
parts = [base_prompt] if base_prompt else []
|
||||
for name in skill_names:
|
||||
s = get(name)
|
||||
if s and s.prompt_fragment:
|
||||
parts.append(s.prompt_fragment)
|
||||
return "\n\n".join(parts)
|
||||
@@ -0,0 +1,45 @@
|
||||
"""
|
||||
Demo skill: media_info
|
||||
|
||||
Gives the agent knowledge about how to respond to media-related queries
|
||||
(movie / TV / subtitle requests). This is intentionally simple — in the future
|
||||
you would add real API-calling skills here (Sonarr / Jellyfin / Seerr / etc.).
|
||||
"""
|
||||
|
||||
from skills import Skill, register
|
||||
|
||||
media_info_skill = Skill(
|
||||
name="media_info",
|
||||
description="Respond to media queries with a structured format "
|
||||
"(movie / TV show requests, subtitles, tickets).",
|
||||
prompt_fragment="""## Media Agent Instructions
|
||||
|
||||
You are a media assistant. When users ask about movies, TV shows, subtitles,
|
||||
or media library requests, follow these rules:
|
||||
|
||||
- If a user wants to **request** a movie or show, respond with a clear
|
||||
confirmation using this format:
|
||||
|
||||
```
|
||||
[MEDIA REQUEST]
|
||||
Title: <title>
|
||||
Type: <movie | show>
|
||||
Status: PENDING — this would be submitted to Seerr
|
||||
```
|
||||
|
||||
- If a user asks about **subtitles**, acknowledge the request and respond with:
|
||||
|
||||
```
|
||||
[SUBTITLE REQUEST]
|
||||
Media: <title>
|
||||
Language: <language>
|
||||
Status: PENDING — Bazarr would process this
|
||||
```
|
||||
|
||||
- Otherwise, answer normally but always remind the user that media-backend
|
||||
integrations (Seerr, Sonarr, Jellyfin) are not yet connected.
|
||||
|
||||
This is a **demo** skill. Real API calls will be added later.""",
|
||||
)
|
||||
|
||||
register(media_info_skill)
|
||||
Reference in New Issue
Block a user