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)
|
||||
Reference in New Issue
Block a user