Skip to content

trading_agent.skills.skill_library

The skills one desk can use: the user's installed skills and the desk's own.

There are two homes, plus the skills of installed packages:

workspace/shared/skills/installed//SKILL.md imported by the user, read-only to every desk workspace/shared/packages//skills// from packages, treated like installed skills workspace/desks//skills/agent//SKILL.md written by the desk itself

Only each skill's name and description go into the system prompt, as an index; load_skill reads a skill in full when the desk needs it. A skill whose required programs or environment variables are missing is hidden. When two skills share a name, the user's installed skill wins over a package's, and both win over the desk's own.

The library reads the folders afresh every time it is asked, so a newly imported or newly written skill shows up on the desk's next turn.

Typical usage example:

library = SkillLibrary(installed_directory, agent_directory) index = library.index_text() skill = library.find('opening-range-breakout')

INSTALLED module-attribute

INSTALLED = 'installed'

AGENT module-attribute

AGENT = 'agent'

HiddenSkill dataclass

HiddenSkill(skill, missing)

A skill that cannot be used here, and why.

Attributes:

Name Type Description
skill Skill

The skill.

missing tuple[str, ...]

The programs and environment variables it needs that are missing.

SkillLibrary

SkillLibrary(installed_directory, agent_directory, program_finder=which, environment=None, package_skill_roots=None)

Finds and checks one desk's skills.

Creates the library without reading anything.

Parameters:

Name Type Description Default
installed_directory Path

The user's installed skills.

required
agent_directory Path

The desk's own skills.

required
program_finder Callable[[str], str | None]

Returns a program's path, or None when it is not installed; replaceable in tests.

which
environment Mapping[str, str] | None

The environment to check variables in; None uses os.environ.

None
package_skill_roots Callable[[], Sequence[Path]] | None

Returns the skills/ folders of installed packages, asked afresh each time, or None for no packages.

None
Source code in src/trading_agent/skills/skill_library.py
def __init__(
    self,
    installed_directory: Path,
    agent_directory: Path,
    program_finder: Callable[[str], str | None] = shutil.which,
    environment: Mapping[str, str] | None = None,
    package_skill_roots: Callable[[], Sequence[Path]] | None = None,
):
    """Creates the library without reading anything.

    Args:
        installed_directory (Path): The user's installed skills.
        agent_directory (Path): The desk's own skills.
        program_finder (Callable[[str], str | None]): Returns a program's path, or None when it is not installed; replaceable in tests.
        environment (Mapping[str, str] | None): The environment to check variables in; None uses os.environ.
        package_skill_roots (Callable[[], Sequence[Path]] | None): Returns the skills/ folders of installed packages, asked afresh each time, or None for no packages.
    """
    self.installed_directory = installed_directory
    self.agent_directory = agent_directory
    self._program_finder = program_finder
    self._environment = environment
    self._package_skill_roots = package_skill_roots
    self._parser = skill_module.SkillParser()

available

available()

The skills the desk can use, installed ones first, each sorted by name.

Returns:

Type Description
list[Skill]

The usable skills.

Source code in src/trading_agent/skills/skill_library.py
def available(self) -> list[skill_module.Skill]:
    """The skills the desk can use, installed ones first, each sorted by name.

    Returns:
        list[skill_module.Skill]: The usable skills.
    """
    usable = []
    for skill in self._all():
        if not self._missing(skill):
            usable.append(skill)
    return usable

hidden

hidden()

The skills hidden because something they need is missing.

Returns:

Type Description
list[HiddenSkill]

The hidden skills and what each lacks.

Source code in src/trading_agent/skills/skill_library.py
def hidden(self) -> list[HiddenSkill]:
    """The skills hidden because something they need is missing.

    Returns:
        list[HiddenSkill]: The hidden skills and what each lacks.
    """
    hidden = []
    for skill in self._all():
        missing = self._missing(skill)
        if missing:
            hidden.append(HiddenSkill(skill=skill, missing=missing))
    return hidden

find

find(name)

Finds a usable skill by name.

Parameters:

Name Type Description Default
name str

The skill's name.

required

Returns:

Type Description
Skill | None

The skill, or None when there is no usable skill of that name.

Source code in src/trading_agent/skills/skill_library.py
def find(self, name: str) -> skill_module.Skill | None:
    """Finds a usable skill by name.

    Args:
        name (str): The skill's name.

    Returns:
        skill_module.Skill | None: The skill, or None when there is no usable skill of that name.
    """
    for skill in self.available():
        if skill.name == name:
            return skill
    return None

find_agent_skill

find_agent_skill(name)

Finds one of the desk's own skills by name, usable or not.

Parameters:

Name Type Description Default
name str

The skill's name.

required

Returns:

Type Description
Skill | None

The skill, or None when the desk wrote no skill of that name.

Source code in src/trading_agent/skills/skill_library.py
def find_agent_skill(self, name: str) -> skill_module.Skill | None:
    """Finds one of the desk's own skills by name, usable or not.

    Args:
        name (str): The skill's name.

    Returns:
        skill_module.Skill | None: The skill, or None when the desk wrote no skill of that name.
    """
    for skill in self._read_folder(self.agent_directory, AGENT):
        if skill.name == name:
            return skill
    return None

is_installed_name

is_installed_name(name)

Says whether one of the user's installed skills has a name.

Parameters:

Name Type Description Default
name str

The name.

required

Returns:

Type Description
bool

True when an installed skill has it.

Source code in src/trading_agent/skills/skill_library.py
def is_installed_name(self, name: str) -> bool:
    """Says whether one of the user's installed skills has a name.

    Args:
        name (str): The name.

    Returns:
        bool: True when an installed skill has it.
    """
    for skill in self._installed_skills():
        if skill.name == name:
            return True
    return False

index_text

index_text()

The skills index for the system prompt.

Returns:

Type Description
str

A titled section listing each usable skill's name and description, or saying there are none.

Source code in src/trading_agent/skills/skill_library.py
def index_text(self) -> str:
    """The skills index for the system prompt.

    Returns:
        str: A titled section listing each usable skill's name and description, or saying there are none.
    """
    lines = [
        '===== Skills =====',
        'Skills are step-by-step procedures. When a task matches one, call load_skill with its name before you start, and follow it. Yours are marked "your own"; you can improve them with skill_patch.',
    ]
    skills = self.available()
    if not skills:
        lines.append('No skills are installed yet.')
    for skill in skills:
        marker = ''
        if skill.origin == AGENT:
            marker = ' (your own)'
        lines.append(f'- {skill.name}{marker}: {skill.description}')
    return '\n'.join(lines)