Skip to content

Anthropic skill operations

Defines the skill operations for the AnthropicLMInvoker class.

AnthropicSkillOperations(invoker)

Bases: SkillOperations

Handles skill operations for the AnthropicLMInvoker class.

Examples:

  1. Create a skill:
file = Attachment.from_path("path/to/file.zip")
skill = await lm_invoker.skill.create(file=file, name="My Skill")
  1. List skills:
skills = await lm_invoker.skill.list()
  1. Retrieve a skill:
skill = await lm_invoker.skill.retrieve(skill_id)
  1. Delete a skill:
await lm_invoker.skill.delete(skill_id)
  1. Create a new skill version:
file = Attachment.from_path("path/to/file.zip")
skill = await lm_invoker.skill.version.create(skill_id, file=file)
  1. List skill versions:
versions = await lm_invoker.skill.version.list(skill_id)
  1. Retrieve a specific skill version:
version = await lm_invoker.skill.version.retrieve(skill_id, version="v1")
  1. Delete a specific skill version:
await lm_invoker.skill.version.delete(skill_id, version="v1")

Initializes the skill operations.

Parameters:

Name Type Description Default
invoker AnthropicLMInvoker

The LM invoker to use for the skill operations.

required

version cached property

Lazy-initialized version operations sub-namespace.

Returns:

Name Type Description
AnthropicVersionOperations AnthropicVersionOperations

The version operations handler.

create(file, name=None, **kwargs) async

Creates a new skill.

Creates a skill via the Anthropic Skills beta API. Skill creation requires uploading files that include a SKILL.md at the root directory.

Parameters:

Name Type Description Default
file Attachment

The skill file to upload (ZIP archive or markdown file).

required
name str | None

The name of the skill. Defaults to None.

None
version str | None

The version of the skill. Defaults to None.

required
**kwargs Any

Skill creation parameters passed to Anthropic's skills.create.

{}

Returns:

Name Type Description
Skill Skill

The created skill.

delete(skill_id) async

Deletes a skill by ID.

Deletes all versions of the skill first, then deletes the skill itself. Attempting to delete a skill with existing versions will return a 400 error.

Note

The Anthropic Skills beta API may return a 500 error when deleting the latest version. This method handles that by catching server errors on version deletion and still attempting to delete the skill.

Parameters:

Name Type Description Default
skill_id str

The skill identifier to delete.

required

Raises:

Type Description
SkillOperationError

If the skill failed to be deleted.

list() async

Lists the skills.

Uses the Anthropic Skills beta API with automatic pagination via AsyncPageCursor. Includes defensive check to prevent infinite pagination loops.

Returns:

Type Description
list[Skill]

list[Skill]: List of skills.

list_skill() async

Lists the skills.

Returns:

Type Description
list[Skill]

list[Skill]: List of skills.

list_versions(skill_id) async

Lists all versions of a skill by ID.

Parameters:

Name Type Description Default
skill_id str

The skill identifier.

required

Returns:

Type Description
list[Skill]

list[Skill]: List of skill versions.

retrieve(skill_id) async

Retrieves a skill by ID.

Parameters:

Name Type Description Default
skill_id str

The skill identifier.

required

Returns:

Name Type Description
Skill Skill

The retrieved skill.

update(skill_id, file, **kwargs) async

Updates a skill by ID.

Creates a new version of the skill via the Anthropic Skills Versions beta API.

Parameters:

Name Type Description Default
skill_id str

The skill identifier.

required
file Attachment

The skill file to upload (ZIP archive or markdown file).

required
**kwargs Any

Additional keyword arguments passed to Anthropic's versions.create.

{}

Returns:

Name Type Description
Skill Skill

The updated skill with the new version.