Skill operations
Modules concerning the skill operations of an LM invoker.
AnthropicSkillOperations(invoker)
Bases: SkillOperations
Handles skill operations for the AnthropicLMInvoker class.
Examples:
- Create a skill:
file = Attachment.from_path("path/to/file.zip")
skill = await lm_invoker.skill.create(file=file, name="My Skill")
- List skills:
skills = await lm_invoker.skill.list_skill()
- Retrieve a skill:
skill = await lm_invoker.skill.retrieve(skill_id)
- Delete a skill:
await lm_invoker.skill.delete(skill_id)
- Update a skill:
file = Attachment.from_path("path/to/file.zip")
skill = await lm_invoker.skill.update(skill_id, file=file)
- List skill versions:
versions = await lm_invoker.skill.list_versions(skill_id)
Initializes the skill operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invoker
|
AnthropicLMInvoker
|
The LM invoker to use for the skill operations. |
required |
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_skill()
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_versions(skill_id)
async
Lists all versions of a skill by ID.
Uses the Anthropic Skills Versions beta API with automatic pagination. Includes defensive check to prevent infinite pagination loops.
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. |
SkillOperations(invoker)
Handles skill operations for the BaseLMInvoker class.
Examples:
- Create a skill:
file = Attachment.from_path("path/to/file.zip")
skill = await lm_invoker.skill.create(file=file, name="My Skill")
- List skills:
skills = await lm_invoker.skill.list_skill()
- Retrieve a skill:
skill = await lm_invoker.skill.retrieve(skill_id)
- Delete a skill:
await lm_invoker.skill.delete(skill_id)
- Update a skill:
file = Attachment.from_path("path/to/file.zip")
skill = await lm_invoker.skill.update(skill_id, file=file)
- List skill versions:
versions = await lm_invoker.skill.list_versions(skill_id)
Initializes the skill operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invoker
|
BaseLMInvoker
|
The LM invoker to use for the skill operations. |
required |
__init_subclass__(**kwargs)
Wrap subclass operation methods to normalize errors.
This keeps base-class methods unchanged while ensuring provider-specific
overrides raise SkillOperationError for unexpected failures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Additional keyword arguments to initialize the subclass. |
{}
|
create(file, name=None, **kwargs)
async
Creates a new skill.
The name must be unique; the provider rejects creation if a skill with the same name already exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
Attachment
|
File attachment of the skill. |
required |
name
|
str | None
|
Display name of the skill provided by the user. Defaults to None. |
None
|
**kwargs
|
Any
|
Additional keyword arguments to create a skill. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Skill |
Skill
|
The created skill. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
The skill operation is not supported. |
delete(skill_id)
async
Deletes a skill by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skill_id
|
str
|
The ID of the skill to delete. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
The skill operation is not supported. |
list_skill()
async
Lists the skills.
Returns:
| Type | Description |
|---|---|
list[Skill]
|
list[Skill]: The list of skills. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
The skill operation is not supported. |
list_versions(skill_id)
async
Lists all versions of a skill by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skill_id
|
str
|
The ID of the skill. |
required |
Returns:
| Type | Description |
|---|---|
list[Skill]
|
list[Skill]: The list of skill versions. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
The skill operation is not supported. |
retrieve(skill_id)
async
Retrieves a skill by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skill_id
|
str
|
The ID of the skill to retrieve. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Skill |
Skill
|
The retrieved skill. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
The skill operation is not supported. |
update(skill_id, file, **kwargs)
async
Updates a skill by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skill_id
|
str
|
The ID of the skill to update. |
required |
file
|
Attachment
|
File attachment of the skill (typically a ZIP archive). |
required |
**kwargs
|
Any
|
Additional keyword arguments to update a skill. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Skill |
Skill
|
The updated skill. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
The skill operation is not supported. |