← 返回列表

AI Series Interview 7: How to Define a Skill Properly

1. Core Concept of Skill

A Skill is a set of executable capability units encapsulated in an Agent or AI system. It usually includes:

  • Trigger condition: when it is called (e.g., user command, system event).
  • Input parameters: data or context to be received.
  • Execution logic: specific processing steps (e.g., calling API, running code, querying knowledge base).
  • Output result: response or action returned to the caller.

2. Steps to Define a Skill Properly

1. Specify the Skill's Name and Description

  • Name: short, unique, semantic (e.g., search_web, send_email).
  • Description: one sentence explaining the Skill's function, helping the Agent to auto-match.

2. Define Input Parameters (Input Schema)

Use JSON Schema or similar format to specify each parameter's type, required status, default value, and constraints.

{
  "type": "object",
  "properties": {
    "query": {
      "type": "string",
      "description": "Search keyword",
      "required": true
    },
    "max_results": {
      "type": "integer",
      "description": "Maximum number of results to return",
      "default": 10
    }
  }
}

3. Write Execution Logic

  • Deterministic logic: directly call functions, APIs, or databases.
  • Non-deterministic logic: use LLM to generate responses (provide prompt template).
  • Error handling: define timeout, retry, and degradation strategies.

4. Define Output Format (Output Schema)

Also use JSON Schema to describe the returned data structure.

{
  "type": "object",
  "properties": {
    "results": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "title": { "type": "string" },
          "url": { "type": "string", "format": "uri" }
        }
      }
    }
  }
}

5. Additional Metadata

  • Version: for iterative management.
  • Author/Maintainer: responsibility attribution.
  • Dependencies: external services or libraries required.
  • Usage restrictions: e.g., rate limits, permission requirements.

3. Example: A Complete Skill Definition

name: "weather_query"
description: "Query current weather by city name"
version: "1.0.0"
author: "AI Team"

input:
  type: object
  properties:
    city:
      type: string
      description: "City name, e.g., 'Beijing'"
      required: true
    unit:
      type: string
      enum: ["celsius", "fahrenheit"]
      default: "celsius"

execute:
  - step: "Call weather API"
    api: "https://api.weather.com/v1/current"
    method: "GET"
    params:
      city: "{input.city}"
      unit: "{input.unit}"
  - step: "Format result"
    format: "Current temperature in {city} is {temperature}°{unit}"

output:
  type: object
  properties:
    temperature:
      type: number
    condition:
      type: string
    humidity:
      type: number

4. Best Practices

  • Single responsibility: each Skill does only one thing, avoid excessive coupling.
  • Self-contained: minimize dependence on external global state; input determines output.
  • Testable: provide mock data or sandbox environment for unit testing.
  • Documented: write usage instructions and examples for each Skill.

By following the above methods, a Skill can be dynamically scheduled by an AI Agent and directly integrated by developers into systems, achieving the reuse effect of "write once, use everywhere".

评论

暂无已展示的评论。

发表评论(匿名)