SKILL.md
唯讀
名稱
ai-agent-builder
描述
使用工具、記憶與多步驟推理來建構 AI 代理 — ChatGPT、Claude、Gemini 整合模式
版本
1.0.0
AI Agent Builder
設計並建構具備工具、記憶與多步驟推理能力的 AI 代理。涵蓋 ChatGPT、Claude、Gemini 整合模式,參考 n8n 超過 5,000 個 AI 工作流程模板。
概述
本技能涵蓋:
- AI 代理架構設計
- 工具/函式呼叫模式
- 記憶與上下文管理
- 多步驟推理工作流程
- 平台整合(Slack、Telegram、Web)
AI 代理架構
核心元件
┌─────────────────────────────────────────────────────────────────┐
│ AI AGENT ARCHITECTURE │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Input │────▶│ Agent │────▶│ Output │ │
│ │ (Query) │ │ (LLM) │ │ (Response) │ │
│ └─────────────┘ └──────┬──────┘ └─────────────┘ │
│ │ │
│ ┌───────────────────┼───────────────────┐ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Tools │ │ Memory │ │ Knowledge │ │
│ │ (Functions) │ │ (Context) │ │ (RAG) │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
代理類型
agent_types:
reactive_agent:
description: "單輪回應,無記憶"
use_case: 簡單問答、分類
complexity: low
conversational_agent:
description: "多輪對話,具備對話記憶"
use_case: 聊天機器人、客服
complexity: medium
tool_using_agent:
description: "可呼叫外部工具/API"
use_case: 資料查詢、執行操作
complexity: medium
reasoning_agent:
description: "多步驟規劃與執行"
use_case: 複雜任務、研究
complexity: high
multi_agent:
description: "多個專業代理協作"
use_case: 複雜工作流程
complexity: very_high
工具呼叫模式
工具定義
tool_definition:
name: "get_weather"
description: "取得指定地點的目前天氣"
parameters:
type: object
properties:
location:
type: string
description: "城市名稱或座標"
units:
type: string
enum: ["celsius", "fahrenheit"]
default: "celsius"
required: ["location"]
implementation:
type: api_call
endpoint: "https://api.weather.com/v1/current"
method: GET
params:
q: "{location}"
units: "{units}"
常見工具類別
tool_categories:
data_retrieval:
- web_search: 搜尋網路
- database_query: 查詢 SQL/NoSQL
- api_lookup: 呼叫外部 API
- file_read: 讀取文件
actions:
- send_email: 寄送電子郵件
- create_calendar: 建立行程
- update_crm: 修改 CRM 記錄
- post_slack: 傳送 Slack 訊息
computation:
- calculator: 數學運算
- code_interpreter: 執行 Python
- data_analysis: 分析資料集
generation:
- image_generation: 產生圖片
- document_creation: 產生文件
- chart_creation: 建立圖表
n8n 工具整合
n8n_agent_workflow:
nodes:
- trigger:
type: webhook
path: "/ai-agent"
- ai_agent:
type: "@n8n/n8n-nodes-langchain.agent"
model: openai_gpt4
system_prompt: |
你是一個有用的助手,可以:
1. 搜尋網路資訊
2. 查詢客戶資料庫
3. 代表使用者寄送電子郵件
tools:
- web_search
- database_query
- send_email
- respond:
type: respond_to_webhook
data: "{{ $json.output }}"
記憶模式
記憶類型
memory_types:
buffer_memory:
description: "儲存最近 N 則訊息"
implementation: |
messages = []
def add_message(role, content):
messages.append({"role": role, "content": content})
if len(messages) > MAX_MESSAGES:
messages.pop(0)
use_case: 簡單聊天機器人
summary_memory:
description: "定期摘要對話內容"
implementation: |
When messages > threshold:
summary = llm.summarize(messages[:-5])
messages = [summary_message] + messages[-5:]
use_case: 長時間對話
vector_memory:
description: "儲存於向量資料庫以進行語意檢索"
implementation: |
# 儲存
embedding = embed(message)
vector_db.insert(embedding, message)
# 檢索
relevant = vector_db.search(query_embedding, k=5)
use_case: 知識檢索
entity_memory:
description: "追蹤對話中提及的實體"
implementation: |
entities = {}
def update_entities(message):
extracted = llm.extract_entities(message)
entities.update(extracted)
use_case: 個人化助手
上下文視窗管理
context_management:
strategies:
sliding_window:
keep: last_n_messages
n: 10
relevance_based:
method: embed_and_rank
keep: top_k_relevant
k: 5
hierarchical:
levels:
- immediate: last_3_messages
- recent: summary_of_last_10
- long_term: key_facts_from_all
token_budget:
total: 8000
system_prompt: 1000
tools: 1000
memory: 4000
current_query: 1000
response: 1000
多步驟推理
ReAct 模式
Thought: 我需要找到關於 X 的資訊
Action: web_search("X")
Observation: [搜尋結果]
Thought: 根據結果,我應該也檢查 Y
Action: database_query("SELECT * FROM Y")
Observation: [資料庫結果]
Thought: 現在我有足夠資訊可以回答
Action: respond("根據 X 和 Y 的最終答案")
規劃代理
planning_workflow:
step_1_plan:
prompt: |
任務:{user_request}
建立逐步計畫來完成此任務。
每個步驟應具體且可執行。
output: numbered_steps
step_2_execute:
for_each: step
actions:
- execute_step
- validate_result
- adjust_if_needed
step_3_synthesize:
prompt: |
已完成步驟:{executed_steps}
結果:{results}
為使用者整合最終回應。
平台整合
Slack 機器人代理
slack_agent:
trigger: slack_message
workflow:
1. receive_message:
extract: [user, channel, text, thread_ts]
2. get_context:
if: thread_ts
action: fetch_thread_history
3. process_with_agent:
model: gpt-4
system: "你是一個有用的 Slack 助手"
tools: [web_search, jira_lookup, calendar_check]
4. respond:
action: post_to_slack
channel: "{channel}"
thread_ts: "{thread_ts}"
text: "{agent_response}"
Telegram 機器人代理
telegram_agent:
trigger: telegram_message
handlers:
text_message:
- extract_text
- process_with_ai
- send_response
voice_message:
- transcribe_with_whisper
- process_with_ai
- send_text_or_voice_response
image:
- analyze_with_vision
- process_with_ai
- send_response
document:
- extract_content
- process_with_ai
- send_response
網頁聊天介面
web_chat_agent:
frontend:
type: react_component
features:
- message_input
- message_history
- typing_indicator
- file_upload
backend:
endpoint: "/api/chat"
method: POST
streaming: true
session_management:
method: jwt_token
storage: redis
ttl: 24_hours
代理模板
客戶支援代理
support_agent:
name: "客戶支援 AI"
model: gpt-4
system_prompt: |
你是 {company} 的客戶支援代理。
指導原則:
- 保持友善、專業且同理心
- 使用知識庫回答問題
- 若無法協助則升級給真人
- 絕不編造資訊
可用操作:
- 搜尋知識庫
- 查詢客戶帳戶
- 建立支援單
- 升級給真人客服
tools:
- knowledge_search:
description: "搜尋幫助文章"
- customer_lookup:
description: "取得客戶帳戶資訊"
- create_ticket:
description: "建立支援單"
- escalate:
description: "轉接給真人客服"
escalation_triggers:
- sentiment: very_negative
- keywords: ["speak to human", "manager", "complaint"]
- failed_resolution: after_3_attempts
研究代理
research_agent:
name: "研究助手"
model: claude-opus
system_prompt: |
你是一個研究助手,幫助使用者尋找
並整合任何主題的資訊。
流程:
1. 理解研究問題
2. 規劃搜尋策略
3. 在多個來源執行搜尋
4. 整合發現
5. 附上引用呈現
tools:
- web_search
- academic_search
- news_search
- wikipedia_lookup
output_format:
- executive_summary
- key_findings
- detailed_analysis
- sources_cited
輸出範例
請求:「設計一個用於預約排程的 AI 代理」
輸出:
# 預約排程代理設計
## 架構
```yaml
agent:
name: "排程助手"
model: gpt-4
capabilities:
- 檢查行事曆空檔
- 預約時間
- 傳送確認通知
- 處理重新排程
- 回答常見問題
所需工具
-
calendar_check
- 輸入:日期範圍、時長
- 輸出:可用時段[]
-
book_appointment
- 輸入:日期時間、客戶資訊、服務類型
- 輸出:確認編號
-
send_notification
- 輸入:類型、收件人、詳細資訊
- 輸出:成功/失敗
-
customer_lookup
- 輸入:電子郵件或電話
- 輸出:客戶記錄
對話流程
使用者:「我想預約一個時間」
代理:[思考:需要知道服務類型和偏好時間]
代理:「很高興為您服務!請問您需要什麼服務,
以及有沒有偏好的日期/時間?」
使用者:「剪頭髮,下週二下午」
代理:[動作:calendar_check(date="下週二", time="下午")]
代理:「下週二我有下午 2 點、3 點和 4 點半的空檔。
哪個時間最適合您?」
使用者:「3 點,謝謝」
代理:[動作:book_appointment(datetime="週二 3 點", service="剪髮")]
代理:[動作:send_notification(type="確認", ...)]
代理:「您已成功預約下週二下午 3 點的剪髮服務。
我已將確認信寄到您的電子郵件。到時見!」
n8n 實作
workflow:
- webhook_trigger: /schedule-chat
- ai_agent:
tools: [calendar, booking, notification]
- respond_to_user
---
*AI Agent Builder 技能 — Claude Office Skills 的一部分*






