Skip to main content

createSkill()

Creates an inline skill that can be passed directly to an agent's skills config without a filesystem or workspace.

The returned object implements the Skill interface and works anywhere a filesystem-discovered skill works.

Usage example
Direct link to Usage example

src/mastra/skills.ts
import { createSkill } from '@mastra/core/skills'

const reviewSkill = createSkill({
name: 'code-review',
description: 'Use when reviewing code changes.',
instructions: `
When reviewing code:
1. Check for correctness
2. Check for style consistency
3. Look for potential bugs
`,
references: {
'checklist.md': '# Review Checklist\n- No unused imports\n- Error handling present',
'languages/typescript.md': '# TypeScript\n- No `any` without a comment',
},
scripts: {
'lint.sh': '#!/bin/sh\npnpm lint',
},
assets: {
'badge.svg':
'<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8"><circle cx="4" cy="4" r="4"/></svg>',
},
})

The agent reads bundled files with the skill_read tool using paths like references/languages/typescript.md, scripts/lint.sh, or assets/badge.svg. Keys containing / become nested directories.

note

The skill holds every bundled file in memory for as long as it exists. A filesystem skill reads its scripts/ and assets/ files from disk only when the agent opens them, so keep large scripts and binary files there. It reads references/ when the skill loads, to index them for search. To load skills from a database, return them from an async skills resolver, which runs per request.

Parameters
Direct link to Parameters

name:

string
Unique skill name. Used as the identifier when agents activate the skill. Must be a valid slug (lowercase, hyphens allowed).

description:

string
Short description shown to the agent in the system message. Helps the agent decide when to use the skill.

instructions:

string
The full skill instructions in markdown. Loaded into the conversation when the agent activates the skill.

references?:

Record<string, string>
Supporting documents the agent can read with the skill_read tool. Keys are paths inside references/, values are file contents.

scripts?:

Record<string, string>
Scripts the agent can read with the skill_read tool. Keys are paths inside scripts/, values are file contents.

assets?:

Record<string, string | Uint8Array>
Templates, images, or other files the agent can read with the skill_read tool. Keys are paths inside assets/. Values can be text or binary. skill_read returns supported images and PDFs up to 10 MiB to the model as media. Other binary files, such as ZIP archives, and media over 10 MiB come back as their path and size only.

license?:

string
SPDX license identifier for the skill.

compatibility?:

unknown
Compatibility requirements. The Agent Skills spec leaves this flexible — can be a string array, object, or any structure your tooling expects.

user-invocable?:

boolean
Whether end users can invoke this skill directly. Defaults to undefined (agent decides).

metadata?:

Record<string, unknown>
Arbitrary metadata attached to the skill.

Return value
Direct link to Return value

Returns an InlineSkill object that implements the Skill interface:

interface InlineSkill extends Skill {
__inline: true
__referenceContents: Record<string, string>
__scriptContents?: Record<string, string>
__assetContents?: Record<string, string | Uint8Array>
}

The skill is assigned a synthetic path of inline/<name> (e.g., inline/code-review).

Validation
Direct link to Validation

createSkill() validates inputs using the same rules as filesystem skills:

  • name is required and must be a valid slug
  • description is required
  • Keys in references, scripts, and assets must be relative file paths separated by /, without empty, ., or .. segments, and can't start with a drive letter such as C:. A key can't also be the directory of another key

If validation fails, an Error is thrown with details about the invalid fields.

// Throws: Invalid skill "": name: Skill name cannot be empty
createSkill({ name: '', description: 'test', instructions: 'test' })
On this page