🚀 快速安装
复制以下命令并运行,立即安装此 Skill:
npx skills add https://skills.sh/claude-office-skills/skills/ai-agent-builder
💡 提示:需要 Node.js 和 NPM
AI 智能体构建器 (AI Agent Builder)
设计并构建具有工具、记忆和多步推理能力的 AI 智能体。涵盖基于 n8n 5000+ AI 工作流模板的 ChatGPT、Claude、Gemini 集成模式。
概述 (Overview)
本技能涵盖:
- AI 智能体架构设计
- 工具/函数调用模式
- 记忆与上下文管理
- 多步推理工作流
- 平台集成(Slack、Telegram、Web)
AI 智能体架构 (AI Agent Architecture)
核心组件 (Core Components)
┌─────────────────────────────────────────────────────────────────┐
│ AI 智能体架构 (AI AGENT ARCHITECTURE) │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ 输入 │────▶│ 智能体 │────▶│ 输出 │ │
│ │ (查询) │ │ (LLM) │ │ (响应) │ │
│ └─────────────┘ └──────┬──────┘ └─────────────┘ │
│ │ │
│ ┌───────────────────┼───────────────────┐ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ 工具 │ │ 记忆 │ │ 知识库 │ │
│ │ (函数) │ │ (上下文) │ │ (RAG) │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
智能体类型 (Agent Types)
agent_types:
reactive_agent:
description: "单轮响应,无记忆 (Single-turn response, no memory)"
use_case: 简单问答, 分类 (simple_qa, classification)
complexity: 低 (low)
conversational_agent:
description: "多轮对话,具有对话记忆 (Multi-turn with conversation memory)"
use_case: 聊天机器人, 客服支持 (chatbots, support)
complexity: 中 (medium)
tool_using_agent:
description: "可调用外部工具/API (Can call external tools/APIs)"
use_case: 数据查询, 执行操作 (data_lookup, actions)
complexity: 中 (medium)
reasoning_agent:
description: "多步规划与执行 (Multi-step planning and execution)"
use_case: 复杂任务, 研究分析 (complex_tasks, research)
complexity: 高 (high)
multi_agent:
description: "多个专业智能体协作 (Multiple specialized agents collaborating)"
use_case: 复杂工作流 (complex_workflows)
complexity: 非常高 (very_high)
工具调用模式 (Tool Calling Pattern)
工具定义 (Tool Definition)
tool_definition:
name: "get_weather"
description: "获取某个位置的当前天气 (Get current weather for a location)"
parameters:
type: object
properties:
location:
type: string
description: "城市名或坐标 (City name or coordinates)"
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}"
常见工具类别 (Common Tool Categories)
tool_categories:
data_retrieval: # 数据检索
- web_search: 搜索互联网 (search the internet)
- database_query: 查询 SQL/NoSQL (query SQL/NoSQL)
- api_lookup: 调用外部 API (call external APIs)
- file_read: 读取文档 (read documents)
actions: # 操作
- send_email: 发送邮件 (send emails)
- create_calendar: 安排日程 (schedule events)
- update_crm: 修改 CRM 记录 (modify CRM records)
- post_slack: 发送 Slack 消息 (send Slack messages)
computation: # 计算
- calculator: 数学运算 (math operations)
- code_interpreter: 运行 Python (run Python)
- data_analysis: 分析数据集 (analyze datasets)
generation: # 生成
- image_generation: 创建图像 (create images)
- document_creation: 生成文档 (generate docs)
- chart_creation: 创建可视化 (create visualizations)
n8n 工具集成 (n8n Tool Integration)
n8n_agent_workflow:
nodes:
- trigger:
type: webhook
path: "/ai-agent"
- ai_agent:
type: "@n8n/n8n-nodes-langchain.agent"
model: openai_gpt4
system_prompt: |
你是一个乐于助人的助手,可以:
(You are a helpful assistant that can:)
1. 搜索网络获取信息 (Search the web for information)
2. 查询我们的客户数据库 (Query our customer database)
3. 代表用户发送邮件 (Send emails on behalf of the user)
tools:
- web_search
- database_query
- send_email
- respond:
type: respond_to_webhook
data: "{{ $json.output }}"
记忆模式 (Memory Patterns)
记忆类型 (Memory Types)
memory_types:
buffer_memory:
description: "存储最近 N 条消息 (Store last N messages)"
implementation: |
messages = []
def add_message(role, content):
messages.append({"role": role, "content": content})
if len(messages) > MAX_MESSAGES:
messages.pop(0)
use_case: 简单聊天机器人 (simple_chatbots)
summary_memory:
description: "定期总结对话内容 (Summarize conversation periodically)"
implementation: |
When messages > threshold:
summary = llm.summarize(messages[:-5])
messages = [summary_message] + messages[-5:]
use_case: 长对话 (long_conversations)
vector_memory:
description: "存储在向量数据库中用于语义检索 (Store in vector DB for semantic retrieval)"
implementation: |
# 存储 (Store)
embedding = embed(message)
vector_db.insert(embedding, message)
# 检索 (Retrieve)
relevant = vector_db.search(query_embedding, k=5)
use_case: 知识检索 (knowledge_retrieval)
entity_memory:
description: "跟踪对话中提到的实体 (Track entities mentioned in conversation)"
implementation: |
entities = {}
def update_entities(message):
extracted = llm.extract_entities(message)
entities.update(extracted)
use_case: 个性化助手 (personalized_assistants)
上下文窗口管理 (Context Window Management)
context_management:
strategies:
sliding_window:
keep: 最近 N 条消息 (last_n_messages)
n: 10
relevance_based:
method: 嵌入并排序 (embed_and_rank)
keep: 保留最相关的 K 条 (top_k_relevant)
k: 5
hierarchical:
levels:
- immediate: 最近 3 条消息 (last_3_messages)
- recent: 最近 10 条消息的摘要 (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
多步推理 (Multi-Step Reasoning)
ReAct 模式 (ReAct Pattern)
思考 (Thought): 我需要查找关于 X 的信息 (I need to find information about X)
行动 (Action): web_search("X")
观察 (Observation): [搜索结果 (search results)]
思考 (Thought): 根据结果,我还应该检查 Y (Based on the results, I should also check Y)
行动 (Action): database_query("SELECT * FROM Y")
观察 (Observation): [数据库结果 (database results)]
思考 (Thought): 现在我有足够的信息来回答了 (Now I have enough information to answer)
行动 (Action): respond("基于 X 和 Y 的最终答案 (Final answer based on X and Y)")
规划型智能体 (Planning Agent)
planning_workflow:
step_1_plan:
prompt: |
任务: {user_request}
创建完成此任务的分步计划。
每一步都应具体且可操作。
(Create a step-by-step plan to complete this task.
Each step should be specific and actionable.)
output: 编号步骤列表 (numbered_steps)
step_2_execute:
for_each: 步骤 (step)
actions:
- 执行步骤 (execute_step)
- 验证结果 (validate_result)
- 必要时调整 (adjust_if_needed)
step_3_synthesize:
prompt: |
已完成的步骤: {executed_steps}
结果: {results}
为用户综合出最终回复。
(Synthesize a final response for the user.)
平台集成 (Platform Integrations)
Slack 机器人智能体 (Slack Bot Agent)
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 助手 (You are a helpful Slack assistant)"
tools: [web_search, jira_lookup, calendar_check]
4. respond:
action: 发送至 Slack (post_to_slack)
channel: "{channel}"
thread_ts: "{thread_ts}"
text: "{agent_response}"
Telegram 机器人智能体 (Telegram Bot Agent)
telegram_agent:
trigger: telegram_message
handlers:
text_message:
- 提取文本 (extract_text)
- 使用 AI 处理 (process_with_ai)
- 发送回复 (send_response)
voice_message:
- 使用 Whisper 转写 (transcribe_with_whisper)
- 使用 AI 处理 (process_with_ai)
- 发送文本或语音回复 (send_text_or_voice_response)
image:
- 使用视觉模型分析 (analyze_with_vision)
- 使用 AI 处理 (process_with_ai)
- 发送回复 (send_response)
document:
- 提取内容 (extract_content)
- 使用 AI 处理 (process_with_ai)
- 发送回复 (send_response)
Web 聊天界面 (Web Chat Interface)
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 小时 (24_hours)
智能体模板 (Agent Templates)
客服支持智能体 (Customer Support Agent)
support_agent:
name: "客服支持 AI (Customer Support AI)"
model: gpt-4
system_prompt: |
你是 {company} 的客服支持智能体。
(You are a customer support agent for {company}.)
准则 (Guidelines):
- 乐于助人、专业且富有同理心 (Be helpful, professional, and empathetic)
- 使用知识库回答问题 (Use the knowledge base to answer questions)
- 如果无法帮助,转接至人工 (Escalate to human if you cannot help)
- 绝不捏造信息 (Never make up information)
可用操作 (Available actions):
- 搜索知识库 (Search knowledge base)
- 查找客户账户 (Look up customer account)
- 创建支持工单 (Create support ticket)
- 转接人工客服 (Escalate to human agent)
tools:
- knowledge_search:
description: "搜索帮助文章 (Search help articles)"
- customer_lookup:
description: "获取客户账户信息 (Get customer account info)"
- create_ticket:
description: "创建支持工单 (Create support ticket)"
- escalate:
description: "转接至人工客服 (Transfer to human agent)"
escalation_triggers:
- sentiment: 非常消极 (very_negative)
- keywords: ["找人工客服", "经理", "投诉"] (["speak to human", "manager", "complaint"])
- failed_resolution: 3 次尝试后 (after_3_attempts)
研究智能体 (Research Agent)
research_agent:
name: "研究助手 (Research Assistant)"
model: claude-opus
system_prompt: |
你是一个研究助手,帮助用户查找并综合任何主题的信息。
(You are a research assistant that helps users find
and synthesize information on any topic.)
流程 (Process):
1. 理解研究问题 (Understand the research question)
2. 规划搜索策略 (Plan search strategy)
3. 跨多个来源执行搜索 (Execute searches across multiple sources)
4. 综合研究结果 (Synthesize findings)
5. 附带引用呈现结果 (Present with citations)
tools:
- web_search
- academic_search
- news_search
- wikipedia_lookup
output_format:
- 执行摘要 (executive_summary)
- 关键发现 (key_findings)
- 详细分析 (detailed_analysis)
- 引用来源 (sources_cited)
输出示例 (Output Example)
请求 (Request): “为预约安排设计一个 AI 智能体 (Design an AI agent for appointment scheduling)”
输出 (Output):
# 预约安排智能体设计 (Appointment Scheduling Agent Design)
## 架构 (Architecture)
```yaml
agent:
name: "安排助手 (Scheduling Assistant)"
model: gpt-4
capabilities:
- 检查日历可用性 (Check calendar availability)
- 预约 (Book appointments)
- 发送确认 (Send confirmations)
- 处理改期 (Handle rescheduling)
- 解答常见问题 (Answer FAQs)
所需工具 (Tools Required)
- calendar_check
- 输入 (Input): 日期范围、时长 (date_range, duration)
- 输出 (Output): 可用时段列表 (available_slots[])
- book_appointment
- 输入 (Input): 日期时间、客户信息、服务类型 (datetime, customer_info, service_type)
- 输出 (Output): 确认 ID (confirmation_id)
- send_notification
- 输入 (Input): 类型、接收人、详情 (type, recipient, details)
- 输出 (Output): 成功/失败 (success/failure)
- customer_lookup
- 输入 (Input): 邮箱或电话 (email or phone)
- 输出 (Output): 客户记录 (customer_record)
对话流程 (Conversation Flow)
用户 (User): "我想预约 (I'd like to book an appointment)"
智能体 (Agent): [思考 (Thought): 需要了解服务类型和首选时间 (Need to know service type and preferred time)]
智能体 (Agent): "我很乐意帮忙!您需要什么服务,有偏好的日期/时间吗?
(I'd be happy to help! What service are you looking for,
and do you have a preferred date/time?)"
用户 (User): "理发,下周二下午 (Haircut, next Tuesday afternoon)"
智能体 (Agent): [行动 (Action): calendar_check(date="下周二 (next Tuesday)", time="下午 (afternoon)")]
智能体 (Agent): "下周二下午我有 2 点、3 点和 4 点半的时间。哪个最适合您?
(I have availability at 2pm, 3pm, and 4:30pm next Tuesday.
Which works best for you?)"
用户 (User): "3 点吧 (3pm please)"
智能体 (Agent): [行动 (Action): book_appointment(datetime="周二 3 点 (Tuesday 3pm)", service="理发 (haircut)")]
智能体 (Agent): [行动 (Action): send_notification(type="确认 (confirmation)", ...)]
智能体 (Agent): "您已成功预约下周二下午 3 点的理发。我已将确认信息发送至您的邮箱。到时见!
(You're all set for a haircut at 3pm next Tuesday.
I've sent a confirmation to your email. See you then!)"
n8n 实现 (n8n Implementation)
workflow:
- webhook_trigger: /schedule-chat
- ai_agent:
tools: [calendar, booking, notification]
- respond_to_user
---
*AI 智能体构建器技能 - Claude 办公技能套件的一部分 (AI Agent Builder Skill - Part of Claude Office Skills)*
📄 原始文档
完整文档(英文):
https://skills.sh/claude-office-skills/skills/ai-agent-builder
💡 提示:点击上方链接查看 skills.sh 原始英文文档,方便对照翻译。
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

评论(0)