AI Series Interview 7: How to Define a Skill Properly
1. Core Concepts of Skill
A Skill is a set of executable capability units encapsulated in an Agent or AI system. It typically 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
2.1. Clarify the Skill Name and Description
- Name: Short, unique, semantic (e.g.,
search_web,send_email). - Description: One sentence explaining the Skill's function, facilitating automatic matching by the Agent.
2.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
}
}
}
2.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.
2.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" }
}
}
}
}
}
2.5. Additional Metadata
- Version: For iterative management.
- Author/Maintainer: Responsibility attribution.
- Dependencies: Required external services or libraries.
- 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 one thing, avoiding 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.
Skills defined through the above methods can be dynamically scheduled by AI Agents and directly integrated by developers, achieving a "write once, use everywhere" reuse effect.
评论
暂无已展示的评论。
发表评论(匿名)