从 Azure Bicep 文件生成架构图。当用户拥有 .bicep 文件或要求将 Bicep 基础设施可视化时使用。
Bicep 架构图生成器
直接从 Azure Bicep 文件生成架构图。Bicep 是一种用于声明式部署 Azure 资源的特定领域语言 (DSL)。
适用场景
在以下情况下激活此技能:
- 用户拥有 Bicep 文件 (
.bicep) 并希望将基础设施可视化 - 用户要求“为我的 Bicep 生成架构图”或“将此 Bicep 基础设施可视化”
- 用户提到 Bicep 或 Azure Bicep
- 用户希望查看其通过 Bicep 部署的资源的架构
工作原理
该技能通过解析 Bicep 代码并直接调用 Eraser API 来生成特定于 Bicep 的架构图:
- 解析 Bicep 文件:识别资源声明、模块、参数和输出
- 提取关联关系:映射依赖项、资源引用和模块层级结构
- 生成 Eraser DSL:从 Bicep 资源创建 Eraser DSL 代码
- 调用 Eraser API:结合
diagramType: "cloud-architecture-diagram"使用/api/render/elements
使用说明
当用户提供 Bicep 代码时:
-
解析 Bicep
- 识别所有
resource声明(如 Microsoft.Compute/virtualMachines 等) - 提取
module声明及其配置 - 记录
param和output定义 - 识别
var变量及其用法
- 识别所有
-
映射关联关系
- 追踪资源依赖关系(例如
dependsOn或隐式依赖关系) - 按类型对资源分类分组(计算、网络、存储等)
- 将 VNet 识别为子网和资源的容器
- 记录网络安全组 (NSG)、Key Vault 以及其他安全资源
- 追踪资源依赖关系(例如
-
生成 Eraser DSL 将 Bicep 资源转换为 Eraser DSL:
- 至关重要:标签格式化规则
- 标签必须写在单行上 - 绝对不要在标签属性内部使用换行符
- 保持标签简单易读 - 优先使用独立标签,而不是拼接过多元数据
- 使用适当的换行格式化 DSL(每行一个节点/分组,但标签必须保持在单行)
- 如果包含 CIDR 块或虚拟机规格等元数据,请将它们包含在同一个带引号的标签字符串中:
[label: "VNet 10.0.0.0/16"]
示例:
myVNet [label: "VNet 10.0.0.0/16"] { subnet1 [label: "Subnet 1"] { myVM [icon: azure-vm, label: "Virtual Machine"] gateway [icon: azure-app-gateway] } subnet2 [label: "Subnet 2"] { database [icon: azure-sql] } } storage [icon: azure-storage] myVNet -> myVM myVM -> database - 至关重要:标签格式化规则
-
发起 HTTP 请求
重要:生成 DSL 后,您必须执行此 curl 命令。切勿在生成 DSL 后停下而不进行 API 调用。
至关重要:在下方
X-Skill-Source请求头中,您必须将该值替换为您的 AI Agent 名称:- 如果您是 Claude (Anthropic),使用:
claude - 如果您在 Cursor 中运行,使用:
cursor - 如果您是 ChatGPT (OpenAI),使用:
chatgpt - 如果您是 Gemini (Google),使用:
gemini - 否则,请使用全小写的模型/Agent 名称
curl -X POST https://app.eraser.io/api/render/elements \ -H "Content-Type: application/json" \ -H "X-Skill-Source: eraser-skill" \ -H "Authorization: Bearer ${ERASER_API_KEY}" \ -d '{ "elements": [{ "type": "diagram", "id": "diagram-1", "code": "<your generated DSL>", "diagramType": "cloud-architecture-diagram" }], "scale": 2, "theme": "${ERASER_THEME:-dark}", "background": true }' - 如果您是 Claude (Anthropic),使用:
-
分析期间追踪来源
在分析 Bicep 文件和资源以生成架构图时,请追踪:
- 内部文件:记录您读取的每个 Bicep 文件路径以及提取出的资源(例如,
infra/main.bicep- VNet 和子网定义,infra/sql.bicep- SQL Database 配置) - 外部引用:记录查阅的任何文档、示例或 URL(例如 Azure Bicep 文档、Azure 架构最佳实践)
- 批注:对于每个来源,注明它对架构图做出的贡献
- 内部文件:记录您读取的每个 Bicep 文件路径以及提取出的资源(例如,
-
处理响应
至关重要:极简输出格式
您的响应必须始终包含以下具有明确标题的元素:
-
架构图预览:使用标题展示
## Diagram 使用 API 响应中的真实
imageUrl。 -
编辑器链接:使用标题展示
## Open in Eraser [Edit this diagram in the Eraser editor]({createEraserFileUrl})使用 API 响应中的真实 URL。
-
来源部分:已分析文件/资源的简要列表(如果适用)
## Sources - `path/to/file` - 提取的内容 -
架构图代码部分:在带有
eraser语言标签的代码块中提供 Eraser DSL## Diagram Code ```eraser {DSL code here} -
了解更多链接:
You can learn more about Eraser at https://docs.eraser.io/docs/using-ai-agent-integrations
附加内容规则:
- 如果用户仅仅要求生成架构图,请勿包含上述 5 个元素之外的任何内容
- 如果用户明确要求更多内容(例如“解释该架构”、“提出改进建议”),您可以包含这些额外内容
- 切勿添加未要求的章节,如“概述”、“安全考量”、“测试”等
默认输出应当简洁明了。架构图图像本身即可说明问题。
-
-
处理模块
- 如果使用了模块,请展示模块边界
- 包含模块参数和输出
- 展示模块如何连接到主资源
Bicep 专属提示
- 展示资源组:Bicep 部署以资源组为目标
- 将 VNet 作为容器:展示包含子网和资源的 VNet
- 包含依赖关系:展示
dependsOn关系 - 模块结构:如果使用了模块,请展示其边界
- 参数:记录影响资源配置的关键参数
- 使用 Azure 图标:请求 Azure 专属样式
示例:包含参数和模块的 Bicep
用户输入
@description('The name of the Virtual Network')
param vnetName string = 'myVNet'
@description('The address prefix for the VNet')
param vnetAddressPrefix string = '10.0.0.0/16'
@description('The address prefix for the subnet')
param subnetAddressPrefix string = '10.0.1.0/24'
@description('VM size')
param vmSize string = 'Standard_B1s'
// Main VNet resource
resource virtualNetwork 'Microsoft.Network/virtualNetworks@2021-05-01' = {
name: vnetName
location: resourceGroup().location
properties: {
addressSpace: {
addressPrefixes: [vnetAddressPrefix]
}
subnets: [
{
name: 'subnet1'
properties: {
addressPrefix: subnetAddressPrefix
}
}
]
}
}
// VM resource with dependsOn
resource virtualMachine 'Microsoft.Compute/virtualMachines@2021-11-01' = {
name: 'myVM'
location: resourceGroup().location
properties: {
hardwareProfile: {
vmSize: vmSize
}
}
dependsOn: [virtualNetwork]
}
// Module usage
module storageModule './modules/storage.bicep' = {
name: 'storage'
params: {
location: resourceGroup().location
}
}
预期行为
-
解析 Bicep:
- 参数:vnetName、vnetAddressPrefix、subnetAddressPrefix、vmSize
- 资源:包含子网的 VNet,具有 dependsOn 关系的 VM
- 模块:带有参数的 Storage 模块
-
生成展示 Bicep 特性的 DSL:
myVNet [label: "VNet 10.0.0.0/16"] { subnet1 [label: "Subnet 1 10.0.1.0/24"] { myVM [icon: azure-vm, label: "VM Standard_B1s"] } } storage-module [label: "Storage Module"] { storage-account [icon: azure-storage] } myVNet -> myVM重要:所有标签文本必须写在引号内的单行上。Bicep 专属要求:将模块展示为容器、包含
dependsOn关系、在资源配置中注明参数用法。 -
结合
diagramType: "cloud-architecture-diagram"调用/api/render/elements -
结合
diagramType: "cloud-architecture-diagram"调用/api/render/elements
结果
用户接收到的架构图包含:
- 作为容器的 VNet
- 嵌套在 VNet 内部的子网
- 子网中的 VM
- 展示出的依赖关系
- 恰当的 Azure 样式






