SKILL.md
只读
名称
ai-agent-builder
描述
使用工具、记忆和多步推理构建AI智能体——ChatGPT、Claude、Gemini集成模式
版本
1.0.0
AI智能体构建器
设计并构建具备工具、记忆和多步推理能力的AI智能体。涵盖基于n8n 5000+ AI工作流模板的ChatGPT、Claude、Gemini集成模式。
概述
本技能涵盖:
- AI智能体架构设计
- 工具/函数调用模式
- 记忆与上下文管理
- 多步推理工作流
- 平台集成(Slack、Telegram、Web)
AI智能体架构
核心组件
┌─────────────────────────────────────────────────────────────────┐
│ AI智能体架构 │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ 输入 │────▶│ 智能体 │────▶│ 输出 │ │
│ │ (查询) │ │ (LLM) │ │ (响应) │ │
│ └─────────────┘ └──────┬──────┘ └─────────────┘ │
│ │ │
│ ┌───────────────────┼───────────────────┐ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ 工具 │ │ 记忆 │ │ 知识 │ │
│ │ (函数) │ │ (上下文) │ │ (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聊天界面
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: ["转人工", "经理", "投诉"]
- 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
- 输入:date_range, duration
- 输出:available_slots[]
-
book_appointment
- 输入:datetime, customer_info, service_type
- 输出:confirmation_id
-
send_notification
- 输入:type, recipient, details
- 输出:success/failure
-
customer_lookup
- 输入:email or phone
- 输出:customer_record
对话流程
用户:"我想预约"
智能体:[思考:需要了解服务类型和偏好时间]
智能体:"很高兴为您服务!请问您需要什么服务,以及偏好的日期/时间?"
用户:"理发,下周二下午"
智能体:[动作: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智能体构建器技能——Claude办公技能系列*






