Skip to content

trading_agent.skills.skill_importer

Imports skills into the user's installed skills, from a folder, a zip file or a git repository.

Every folder in the source that holds a SKILL.md is imported as one skill, so a whole collection, such as a Hermes skills folder, can be imported at once. Each skill is checked before it is copied, and an existing skill of the same name is kept unless replacing is asked for.

Typical usage example:

results = SkillImporter(installed_directory).import_source('~/.hermes/skills/research', replace=False)

SkillImportError

Bases: RuntimeError

The source could not be read, cloned or unpacked.

ImportResult dataclass

ImportResult(source, name, outcome, detail, warnings=())

What happened to one skill folder in the source.

Attributes:

Name Type Description
source Path

The folder in the source.

name str | None

The skill's name, or None when its SKILL.md could not be read.

outcome str

"imported", "replaced", "skipped" or "invalid".

detail str

Why it was skipped or invalid, or an empty string.

warnings tuple[str, ...]

Passages that look like prompt injection, as "file, line: what it looks like".

SkillImporter

SkillImporter(installed_directory)

Copies skills into the installed skills folder.

Creates the importer.

Parameters:

Name Type Description Default
installed_directory Path

workspace/shared/skills/installed.

required
Source code in src/trading_agent/skills/skill_importer.py
def __init__(self, installed_directory: Path):
    """Creates the importer.

    Args:
        installed_directory (Path): workspace/shared/skills/installed.
    """
    self._installed_directory = installed_directory
    self._parser = skill_module.SkillParser()
    self._scanner = injection_scanner.InjectionScanner()

import_source

import_source(source, replace)

Imports every skill found in a folder, zip file or git URL.

Parameters:

Name Type Description Default
source str

The folder, the .zip file, or a git URL.

required
replace bool

Whether to replace installed skills of the same name.

required

Returns:

Type Description
list[ImportResult]

One result per skill folder found.

Raises:

Type Description
SkillImportError

The source does not exist, cannot be unpacked or cloned, or holds no SKILL.md.

Source code in src/trading_agent/skills/skill_importer.py
def import_source(self, source: str, replace: bool) -> list[ImportResult]:
    """Imports every skill found in a folder, zip file or git URL.

    Args:
        source (str): The folder, the .zip file, or a git URL.
        replace (bool): Whether to replace installed skills of the same name.

    Returns:
        list[ImportResult]: One result per skill folder found.

    Raises:
        SkillImportError: The source does not exist, cannot be unpacked or cloned, or holds no SKILL.md.
    """
    with tempfile.TemporaryDirectory(prefix='skill-import-') as scratch:
        try:
            root = source_fetcher.SourceFetcher().local_folder(
                source,
                Path(scratch),
            )
        except source_fetcher.SourceError as error:
            raise SkillImportError(str(error)) from error
        folders = self._skill_folders(root)
        if not folders:
            raise SkillImportError(f'No SKILL.md found in {source}')
        results = []
        for folder in folders:
            results.append(self._import_folder(folder, replace))
        return results