mcpField
B
build-agent

build-agent

github.com/happy-technologies-llcAgent 工作流4142 次安装3 天前更新
代码仓库

关于 build-agent

build-agent 是面向 ServiceNow 团队的技能,用于设计和配置自定义 AI Agent,适用于构建虚拟 Agent 主题或扩展 Now Assist。内容涵盖知识来源、对话流程、操作、护栏、测试与部署。

主要功能

  1. 01定义 Agent 范围与能力
  2. 02配置知识来源
  3. 03设计意图与对话流程
  4. 04设置操作与安全护栏
  5. 05测试、部署和监控 Agent

适用场景

  1. 01构建 IT 支持虚拟 Agent
  2. 02创建 HR 福利助手
  3. 03配置 Agent 自动执行操作

MCP 相关

该技能介绍使用 SN-Query-Table 和 SN-Create-Record 等 MCP 工具,配置并检查 ServiceNow Agent 组件。

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/happy-technologies-llc/happy-platform-skills --skill build-agent

安装后在 Claude Code 中输入/build-agent确认已加载。

详细介绍

构建自定义 AI Agent

概述

本技能提供在 ServiceNow 中构建自定义 AI Agent 的全面指南:

  • 定义 Agent 的能力和职责范围
  • 配置用于 Agent 知识依据的知识源(知识库文章、目录项、文档)
  • 设置工具访问权限,以便 Agent 执行操作(创建记录、查询数据、触发流程)
  • 设计具备意图识别和实体提取功能的对话流程
  • 实施安全、准确性和合规性护栏
  • 在生产部署前测试并迭代 Agent 的行为

使用场景: 构建新的虚拟 Agent 主题、扩展 Now Assist 技能能力、创建特定领域的 AI 助手,或配置 Agent 工具访问权限以自动执行任务时。

先决条件

  • 角色: admin、va_admin 或 now_assist_admin
  • 插件: 建议启用 com.glide.cs.chatbot(Virtual Agent)和 com.snc.now_assist(Now Assist)
  • 访问权限: 对 sys_cs_topic、sys_cs_intent、sys_cs_entity、sys_cb_topic、kb_knowledge 表具有写入权限
  • 知识: 了解对话式 AI 概念(意图、实体、槽位、履行)
  • 相关技能: 用于发现可自动化内容的 genai/agent-miner,以及用于 Now Assist 技能的 genai/skill-kit-custom

操作步骤

步骤 1:定义 Agent 的范围和能力

记录 Agent 的用途、目标用户和边界。

=== AGENT DEFINITION ===
Name: [Agent Name]
Domain: [IT Support / HR / Facilities / Custom]
Target Users: [Employee / Customer / Technician]

CAPABILITIES (What the agent CAN do):
- [ ] Answer questions about [topic]
- [ ] Create [record type] on behalf of users
- [ ] Look up [information type]
- [ ] Trigger [workflow/process]
- [ ] Escalate to [team] when needed

BOUNDARIES (What the agent CANNOT do):
- [ ] Access [restricted data/system]
- [ ] Approve [request type]
- [ ] Modify [critical records]
- [ ] Share [sensitive information]

SUCCESS METRICS:
- Deflection Rate Target: [%]
- User Satisfaction Target: [score]
- Resolution Rate Target: [%]
- Average Handle Time Target: [minutes]
步骤 2:配置知识源

设置 Agent 用于知识依据的知识库文章和数据源。

MCP 方式:

Tool: SN-Query-Table
Parameters:
  table_name: kb_knowledge
  query: kb_knowledge_base=[KB_SYS_ID]^workflow_state=published^active=true
  fields: sys_id,number,short_description,kb_category,article_type
  limit: 100

REST 方式:

GET /api/now/table/kb_knowledge
  ?sysparm_query=kb_knowledge_base=[KB_SYS_ID]^workflow_state=published^active=true
  &sysparm_fields=sys_id,number,short_description,kb_category,article_type
  &sysparm_limit=100

验证每项 Agent 能力的知识覆盖情况:

能力知识库文章发现的缺口
重置密码KB001、KB002无
VPN 设置KB010缺少 macOS 说明
软件申请无需要目录映射文章
步骤 3:创建 Agent 主题

构建用于定义 Agent 对话范围的主要主题。

MCP 方式:

Tool: SN-Create-Record
Parameters:
  table_name: sys_cs_topic
  data:
    name: "IT Support Assistant"
    description: "Handles common IT support requests including password resets, VPN access, and software installations"
    state: draft
    category: IT
    greeting_message: "Hi! I'm your IT Support Assistant. I can help with password resets, VPN access, software requests, and general IT questions. What do you need help with?"
    no_match_message: "I'm not sure I understand. Could you rephrase your request, or would you like me to connect you with a live agent?"
    max_retries: 3

REST 方式:

POST /api/now/table/sys_cs_topic
Body: {
  "name": "IT Support Assistant",
  "description": "Handles common IT support requests",
  "state": "draft",
  "category": "IT",
  "greeting_message": "Hi! I'm your IT Support Assistant...",
  "no_match_message": "I'm not sure I understand...",
  "max_retries": "3"
}
步骤 4:定义意图和训练话语

创建 Agent 应识别并响应的意图。

MCP 方式:

Tool: SN-Create-Record
Parameters:
  table_name: sys_cs_intent
  data:
    name: "Reset Password"
    topic: [TOPIC_SYS_ID]
    description: "User wants to reset their password for any system"
    training_utterances: |
      I need to reset my password
      My password expired
      I can't log in
      Password not working
      Forgot my password
      Need a new password
      Locked out of my account
      Account locked
      Can't access my account
      Reset credentials

对每项能力重复此操作:

意图示例话语实体槽位
重置密码“重置我的密码”、“无法登录”system_name、username
VPN 访问“连接到 VPN”、“VPN 无法使用”vpn_type、device_type
安装软件“安装软件”、“需要 [app]”software_name、justification
一般问题“如何……”、“什么是……”topic_keyword
步骤 5:定义用于槽位填充的实体

创建实体,以从用户消息中提取结构化数据。

MCP 方式:

Tool: SN-Create-Record
Parameters:
  table_name: sys_cs_entity
  data:
    name: "system_name"
    topic: [TOPIC_SYS_ID]
    type: "list"
    prompt: "Which system do you need the password reset for?"
    required: true
    values: |
      Active Directory|AD|Windows login
      Email|Outlook|Exchange
      VPN|Cisco AnyConnect
      SAP|ERP
      Salesforce|CRM

REST 方式:

POST /api/now/table/sys_cs_entity
Body: {
  "name": "system_name",
  "topic": "[TOPIC_SYS_ID]",
  "type": "list",
  "prompt": "Which system do you need the password reset for?",
  "required": "true"
}
步骤 6:配置工具访问权限和操作

定义 Agent 可在 ServiceNow 中执行的操作。

MCP 方式:

Tool: SN-Create-Record
Parameters:
  table_name: sys_cb_action
  data:
    topic: [TOPIC_SYS_ID]
    name: "Create Incident for Password Reset"
    action_type: "create_record"
    table: "incident"
    field_values: |
      category=inquiry
      subcategory=password
      short_description=Password reset request: ${system_name}
      assignment_group=IT Help Desk
      caller_id=${sys_user}
      urgency=3
      impact=3

REST 方式:

POST /api/now/table/sys_cb_action
Body: {
  "topic": "[TOPIC_SYS_ID]",
  "name": "Create Incident for Password Reset",
  "action_type": "create_record",
  "table": "incident",
  "field_values": "category=inquiry^subcategory=password^short_description=Password reset request"
}

常见操作类型:

操作类型用途配置
create_record创建新记录table、field_values
update_record更新现有记录table、sys_id、field_values
query_record查找记录table、query、return_fields
run_flow触发 Flow Designer 流程flow_sys_id、inputs
run_script执行服务器端脚本脚本正文
kb_search搜索知识库query、kb_base
escalate转接给人工 Agentqueue、message
步骤 7:实施护栏

配置安全边界和合规性控制。

输入护栏:

Tool: SN-Create-Record
Parameters:
  table_name: sys_cs_topic_goal
  data:
    topic: [TOPIC_SYS_ID]
    name: "Input Validation"
    type: "guardrail"
    configuration: |
      BLOCKED_INTENTS:
      - Requests for other users' personal data
      - Attempts to bypass approval processes
      - Requests for admin/root access

      INPUT_SANITIZATION:
      - Strip HTML/script tags from user input
      - Validate employee ID format before lookup
      - Limit free-text input to 500 characters

      AUTHENTICATION:
      - Require verified session for record creation
      - Verify caller identity before sharing account details
      - MFA challenge for sensitive operations

输出护栏:

RESPONSE RULES:
- Never expose sys_id values or internal table names to users
- Never share other employees' personal information
- Always confirm destructive actions before executing
- Include disclaimer for estimated timeframes
- Redirect compliance/legal questions to appropriate teams
- Log all agent actions for audit trail

ESCALATION TRIGGERS:
- User expresses frustration (sentiment < -0.5)
- 3 consecutive failed intent matches
- Request involves VIP or executive user
- Security-related request (account compromise)
- Agent confidence score below threshold (< 0.7)
步骤 8:设计对话流程

为每个意图规划完整的对话流程。

CONVERSATION FLOW: Password Reset

[User Message] -> Intent Recognition -> "Reset Password" (confidence > 0.8)
  |
  v
[Slot: system_name] -> "Which system?" -> User provides system
  |
  v
[Slot: username] -> "What is your username?" -> User provides username
  |
  v
[Validation] -> Verify user exists in system
  |-- User found -> Proceed
  |-- User not found -> "I couldn't find that username. Please verify and try again."
  |
  v
[Action] -> Trigger password reset flow
  |-- Success -> "Your password has been reset. Check your email for the temporary password."
  |-- Failure -> "I wasn't able to reset your password. Let me connect you with a live agent."
  |
  v
[Follow-up] -> "Is there anything else I can help you with?"
第 9 步:测试 Agent

通过测试场景验证 Agent 的行为。

MCP 方案:

Tool: SN-Query-Table
Parameters:
  table_name: sys_cs_topic
  query: sys_id=[TOPIC_SYS_ID]
  fields: sys_id,name,state,test_status,last_tested

测试矩阵:

测试用例输入预期行为结果
正常流程"Reset my AD password"收集用户名,触发重置
缺少实体"Reset my password"询问是哪一个系统
未知意图"What's the weather?"返回无匹配响应
触发护栏"Reset John's password"拒绝并说明原因
升级处理"This isn't working, get me a human"转接给人工 Agent
边缘情况空消息提示输入内容
第 10 步:部署和监控

发布 Agent 并设置监控。

MCP 方案:

Tool: SN-Update-Record
Parameters:
  table_name: sys_cs_topic
  sys_id: [TOPIC_SYS_ID]
  data:
    state: published

部署后监控查询:

Tool: SN-Query-Table
Parameters:
  table_name: sys_cs_conversation
  query: topic=[TOPIC_SYS_ID]^sys_created_on>=javascript:gs.daysAgo(7)
  fields: sys_id,state,live_agent,transfer_reason,user_satisfaction,sys_created_on
  limit: 100

工具用法

工具用途使用时机
SN-Query-Table查找现有主题、意图和知识文章探索和验证
SN-Create-Record创建主题、意图、实体和操作构建 Agent 组件
SN-Update-Record修改 Agent 设置、发布主题配置和部署
SN-Get-Table-Schema探索主题和意图表结构初始设置
SN-Get-Record获取特定主题或意图的详细记录检查现有配置

最佳实践

  1. 从小范围开始,逐步扩展 —— 添加更多意图前,先发布 2-3 个定义明确的意图
  2. 每个意图至少使用 10 条训练话语,以确保可靠识别
  3. 使用真实的用户用语进行测试 —— 避免在训练数据中使用技术术语
  4. 实施平稳的回退方案 —— 始终提供转接人工 Agent 的途径
  5. 部署后的第一个月内每周监控并重新训练
  6. 为主题进行版本管理 —— 保留草稿版本,同时让已发布版本为用户提供服务
  7. 划分关注领域 —— 每个领域设置一个主题(IT、HR、设施)
  8. 记录所有操作 —— 保留审计跟踪,以满足合规要求并便于调试
  9. 设置置信度阈值 —— 不要根据低置信度的意图匹配采取操作
  10. 收集用户反馈 —— 使用对话后的调查问卷,找出需要改进的方面

故障排除

问题原因解决方法
Agent 无法识别意图训练话语不足或质量不佳添加更多样化的话语;包含拼写错误和缩写
匹配到错误的意图不同意图之间的话语重叠检查并删除重复的训练数据;提高置信度阈值
未提取实体实体值与用户输入不匹配在实体值列表中添加同义词和变体
操作无提示地失败权限缺失或字段映射无效检查 Agent 用户角色;根据表架构验证字段名称
Agent 针对同一问题反复询问用户回复未填入必填槽位添加跳过逻辑或其他槽位填充提示词
升级率过高Agent 范围过窄或回复没有帮助扩展知识来源;检查已升级的对话以发现规律

示例

示例 1:IT 支持机器人

场景: 为常见 IT 支持请求构建虚拟 Agent。

AGENT: IT Support Assistant
INTENTS:
1. Password Reset -> Flow: Reset Password (AD, Email, VPN)
2. Software Request -> Action: Create RITM from catalog
3. VPN Troubleshooting -> KB Search: VPN articles
4. Hardware Issue -> Action: Create incident, escalate if P1
5. General IT Question -> KB Search: IT knowledge base

GUARDRAILS:
- Cannot reset passwords for other users
- Software requests require manager approval flow
- Hardware replacements require asset verification
示例 2:HR 福利机器人

场景: 为福利登记问题构建 Agent。

AGENT: Benefits Assistant
INTENTS:
1. Benefits Overview -> KB: Benefits summary article
2. Enrollment Period -> KB: Open enrollment dates and process
3. Plan Comparison -> KB: Plan comparison matrix
4. Life Event Change -> Action: Create HR case for life event
5. Dependent Add/Remove -> Action: Create HR case with dependent info

GUARDRAILS:
- Cannot share other employees' benefits information
- Directs medical questions to benefits provider
- Logs all interactions for compliance
示例 3:设施服务机器人

场景: 为工作场所服务请求构建 Agent。

AGENT: Facilities Assistant
INTENTS:
1. Room Booking -> Action: Query room availability, create reservation
2. Maintenance Request -> Action: Create facilities incident
3. Badge Access -> Action: Create access request RITM
4. Parking -> KB: Parking policy and waitlist info
5. Catering -> Action: Create catering request with details

GUARDRAILS:
- Room bookings limited to 4 hours maximum
- Maintenance requests auto-prioritized by type
- Badge access requires security team approval

相关技能

  • genai/agent-miner - 从交互数据中发现自动化机会
  • genai/flow-generation - 构建 Agent 可触发的流程
  • genai/playbook-generation - 为 Agent 辅助工作流创建操作手册
  • genai/skill-kit-custom - 构建自定义 Now Assist 技能
  • knowledge/article-generation - 为 Agent 知识来源生成 KB 文章

评论

支持 Markdown