.getSkill()
按名稱從 Agent 已設定的 Skill(包括 Agent 層級和 Workspace Skill)擷取指定 Skill。
使用範例使用範例 的直接連結
src/routes/skills.ts
import { agent } from '../mastra/agents'
const skill = await agent.getSkill('code-review')
if (skill) {
console.log(skill.name) // "code-review"
console.log(skill.description) // "Use when reviewing code changes."
console.log(skill.instructions) // Full markdown instructions
}
參數參數 的直接連結
skillName:
string
要擷取的 Skill 名稱。
options?:
object
解析 Skill 的選項。
object
requestContext?:
RequestContext
傳送至動態 Skill 解析器的請求情境。
傳回值傳回值 的直接連結
傳回 Promise<Skill | null>。
如找到 Skill,便傳回 Skill 物件;如不存在該名稱的 Skill,則傳回 null。
interface Skill {
name: string
description: string
instructions: string
path: string
source: { type: string; projectPath: string }
references: string[]
scripts: string[]
assets: string[]
license?: string
compatibility?: string[]
'user-invocable'?: boolean
metadata?: Record<string, unknown>
}
合併行為合併行為 的直接連結
同時設定 Agent 層級 Skill 和 Workspace Skill 時,.getSkill() 會搜尋合併後的集合。如果名稱衝突,Agent 層級 Skill 優先。