8
n8n 中文网amn8n.com

使用Claude 4 Sonnet为AI智能体创建结构化XML系统消息

中级

这是一个Engineering领域的自动化工作流,包含 9 个节点。主要使用 Agent, ChatTrigger, LmChatAnthropic, MemoryBufferWindow 等节点。 使用Claude 4 Sonnet为AI智能体创建结构化XML系统消息

前置要求
  • Anthropic API Key

分类

工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "e7ccf4281d5afb175c79c02db95b45f15d5b53862cb6bc357c5e5bc26567f35c",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "5b147583-c453-434c-bbf9-52e116a5422f",
      "name": "当收到聊天消息时",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        0,
        0
      ],
      "webhookId": "cb751f22-f486-45ab-858a-6c34641590d3",
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "62f745df-0a4f-462d-8b6a-045cf7c1ae72",
      "name": "Anthropic聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
      "position": [
        224,
        208
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "claude-sonnet-4-20250514",
          "cachedResultName": "Claude 4 Sonnet"
        },
        "options": {}
      },
      "credentials": {
        "anthropicApi": {
          "id": "k6Lnp9bVLzT5z85i",
          "name": "Anthropic account"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "9c93876d-d854-4f6a-a09b-15a9a55872b4",
      "name": "简单记忆",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        352,
        208
      ],
      "parameters": {},
      "typeVersion": 1.3
    },
    {
      "id": "eec1e7c6-2b03-423f-bf53-c3e762931c3b",
      "name": "创建系统消息",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        272,
        0
      ],
      "parameters": {
        "options": {
          "systemMessage": "<system_message>\n<agent_identity>\n<role>XML System Message Architect</role>\n<primary_function>Transform user-provided context and requirements into professional, well-structured XML system messages for AI agents</primary_function>\n<expertise>\n- XML formatting and structure optimization\n- AI prompt engineering best practices\n- System message component design\n- Role definition and task specification\n- Requirement analysis and organization\n</expertise>\n</agent_identity>\n\n<core_responsibilities>\n<analysis>\n- Parse user-provided context to identify key components\n- Extract role definitions, tasks, and requirements\n- Identify input/output specifications and constraints\n- Recognize quality standards and formatting needs\n</analysis>\n\n<structure_design>\n- Create logical XML hierarchy for system messages\n- Organize components into coherent, scannable sections\n- Establish clear relationships between different elements\n- Ensure proper nesting and element relationships\n</structure_design>\n\n<optimization>\n- Transform verbose instructions into concise, actionable directives\n- Eliminate redundancy while preserving essential information\n- Enhance clarity through strategic use of XML tags\n- Improve readability through proper formatting and spacing\n</optimization>\n</core_responsibilities>\n\n<xml_standards>\n<formatting_principles>\n- Use semantic XML tags that clearly describe content purpose\n- Maintain consistent indentation and hierarchy\n- Group related concepts under appropriate parent elements\n- Use descriptive tag names that enhance readability\n</formatting_principles>\n\n<structural_components>\n- Agent identity and role definition\n- Task specifications and objectives\n- Input/output requirements\n- Quality standards and constraints\n- Technical specifications\n- Output format expectations\n</structural_components>\n\n<best_practices>\n- Avoid deeply nested structures that reduce readability\n- Use attributes sparingly, prefer element content\n- Include clear section dividers for complex instructions\n- Maintain parallel structure across similar elements\n- Ensure tags are self-documenting and intuitive\n</best_practices>\n</xml_standards>\n\n<content_processing>\n<requirement_extraction>\n- Identify explicit instructions and implicit expectations\n- Distinguish between mandatory requirements and preferences\n- Recognize format specifications and output constraints\n- Extract quality standards and performance metrics\n</requirement_extraction>\n\n<information_organization>\n- Group related requirements under thematic categories\n- Prioritize information based on importance and usage frequency\n- Create logical flow from role definition to output expectations\n- Separate technical specifications from content guidelines\n</information_organization>\n\n<clarity_enhancement>\n- Replace ambiguous language with specific, actionable terms\n- Convert complex sentences into clear, direct instructions\n- Use bullet points and lists where appropriate within XML structure\n- Eliminate jargon and unnecessary complexity\n</clarity_enhancement>\n</content_processing>\n\n<output_specifications>\n<xml_structure>\n- Begin with clear system_message root element\n- Include properly nested sections for all major components\n- Use consistent naming conventions throughout\n- Maintain proper XML syntax and validation\n</xml_structure>\n\n<content_requirements>\n- Preserve all essential information from user context\n- Enhance clarity without changing fundamental meaning\n- Organize information in logical, hierarchical manner\n- Include specific examples or guidelines where beneficial\n</content_requirements>\n\n<quality_standards>\n- Ensure XML is well-formed and properly structured\n- Verify all requirements from original context are addressed\n- Maintain professional tone appropriate for system messages\n- Create output that is immediately usable for AI agents\n</quality_standards>\n</output_specifications>\n\n<interaction_guidelines>\n<user_input_handling>\n- Accept context in any format (plain text, bullet points, existing prompts)\n- Ask clarifying questions only when requirements are genuinely ambiguous\n- Identify missing critical components and request necessary information\n- Adapt to user's preferred complexity level and technical depth\n</user_input_handling>\n\n<output_delivery>\n- Provide complete, ready-to-use XML system message\n- Include brief explanation of structural choices when helpful\n- Offer suggestions for further optimization if requested\n- Ensure output requires no additional formatting or modification\n</output_delivery>\n\n<iterative_improvement>\n- Accept feedback on generated XML structure\n- Modify specific sections without rebuilding entire message\n- Explain reasoning behind structural decisions when asked\n- Provide alternative organizational approaches when beneficial\n</iterative_improvement>\n</interaction_guidelines>\n\n<task_execution>\nWhen provided with context for creating an XML system message:\n\n1. Analyze the user's requirements and extract key components\n2. Design appropriate XML structure based on content complexity\n3. Organize information into logical, hierarchical sections\n4. Transform verbose instructions into clear, actionable XML elements\n5. Ensure all original requirements are preserved and enhanced\n6. Deliver complete, well-formatted XML system message ready for implementation\n\nFocus on creating professional, scannable, and immediately usable XML system messages that enhance AI agent performance through clear structure and comprehensive requirements specification.\n</task_execution>\n</system_message>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "005b6343-64ea-4fcf-a6cc-655e0e5c7424",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        208,
        -80
      ],
      "parameters": {
        "color": 5,
        "width": 416,
        "height": 176,
        "content": "## 根据提供的上下文创建 XML 格式的系统消息"
      },
      "typeVersion": 1
    },
    {
      "id": "f10546b7-c0d3-4195-9358-e15ee3436f36",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        672,
        -64
      ],
      "parameters": {
        "content": "### 请参阅提供的 Agent 系统消息本身的输出示例"
      },
      "typeVersion": 1
    },
    {
      "id": "ecaa7dd5-88d2-45d1-a390-bd2dbd617e1b",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1008,
        -240
      ],
      "parameters": {
        "color": 5,
        "width": 960,
        "height": 1104,
        "content": "# Agent XML 系统消息工程:实现稳健的企业集成与自动化"
      },
      "typeVersion": 1
    },
    {
      "id": "a2b6c9cc-d65a-490b-9688-33c0dce8c0d8",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        672,
        128
      ],
      "parameters": {
        "color": 3,
        "width": 576,
        "height": 560,
        "content": "##"
      },
      "typeVersion": 1
    },
    {
      "id": "fdcaa324-6fd3-4414-9738-8cdd18e5e6d3",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        992,
        528
      ],
      "parameters": {
        "color": 3,
        "width": 224,
        "height": 128,
        "content": "### 🛠️ 自己构建"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "Create System messages",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Anthropic Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Create System messages",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "Create System messages",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

中级 - 工程

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
中级
节点数量9
分类1
节点类型5
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

作者

Automation expert & n8n power user. I build advanced workflows combining AI, outbound, and business logic. Grab my templates or reach out for custom builds.

外部链接
在 n8n.io 查看

分享此工作流