HelloAgent_n8nCase.json 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. {
  2. "name": "HelloAgent_n8nCase",
  3. "nodes": [
  4. {
  5. "parameters": {
  6. "pollTimes": {
  7. "item": [
  8. {
  9. "mode": "everyMinute"
  10. }
  11. ]
  12. },
  13. "filters": {}
  14. },
  15. "type": "n8n-nodes-base.gmailTrigger",
  16. "typeVersion": 1.3,
  17. "position": [
  18. 368,
  19. -160
  20. ],
  21. "id": "46a534e3-3e72-4d0b-9a41-bc5c28834ee4",
  22. "name": "Gmail",
  23. "alwaysOutputData": false,
  24. "credentials": {
  25. "gmailOAuth2": {
  26. "id": "XD1oTN8hEyHzsxBR",
  27. "name": "Gmail account"
  28. }
  29. }
  30. },
  31. {
  32. "parameters": {
  33. "options": {}
  34. },
  35. "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
  36. "typeVersion": 1,
  37. "position": [
  38. 416,
  39. 32
  40. ],
  41. "id": "882131ef-83bc-415f-9430-59d40503c4ae",
  42. "name": "Google Gemini Chat Model",
  43. "credentials": {
  44. "googlePalmApi": {
  45. "id": "4HqrqZ1DN3LCRp28",
  46. "name": "Google Gemini(PaLM) Api account"
  47. }
  48. }
  49. },
  50. {
  51. "parameters": {
  52. "sessionIdType": "customKey",
  53. "sessionKey": "={{ $('Gmail').item.json.threadId }}"
  54. },
  55. "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
  56. "typeVersion": 1.3,
  57. "position": [
  58. 544,
  59. 32
  60. ],
  61. "id": "d230cedb-0a48-424f-8b79-4a5e8ae304a7",
  62. "name": "Simple Memory"
  63. },
  64. {
  65. "parameters": {
  66. "options": {}
  67. },
  68. "type": "@n8n/n8n-nodes-langchain.toolSerpApi",
  69. "typeVersion": 1,
  70. "position": [
  71. 672,
  72. 32
  73. ],
  74. "id": "164578ff-9ef8-41ab-b4c3-22f7871c4885",
  75. "name": "SerpAPI",
  76. "credentials": {
  77. "serpApi": {
  78. "id": "Nmxsc4WxINf7TGrA",
  79. "name": "SerpAPI account"
  80. }
  81. }
  82. },
  83. {
  84. "parameters": {
  85. "sendTo": "={{ $('Gmail').item.json.From }}",
  86. "subject": "=Re: {{ $('Gmail').item.json.Subject }}",
  87. "message": "={{ $json.output }}",
  88. "options": {}
  89. },
  90. "type": "n8n-nodes-base.gmail",
  91. "typeVersion": 2.1,
  92. "position": [
  93. 928,
  94. -160
  95. ],
  96. "id": "c680c326-e4e1-41df-9f76-520c4b522618",
  97. "name": "Send a message",
  98. "webhookId": "94ed889e-1e8a-4c90-980f-38cd02c32873",
  99. "credentials": {
  100. "gmailOAuth2": {
  101. "id": "XD1oTN8hEyHzsxBR",
  102. "name": "Gmail account"
  103. }
  104. }
  105. },
  106. {
  107. "parameters": {
  108. "mode": "insert",
  109. "memoryKey": {
  110. "__rl": true,
  111. "value": "my-dailytime",
  112. "mode": "list"
  113. }
  114. },
  115. "type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
  116. "typeVersion": 1.3,
  117. "position": [
  118. -16,
  119. -160
  120. ],
  121. "id": "ead1ed07-6e2c-4ba2-9d28-d5adf76540f1",
  122. "name": "Simple Vector Store1"
  123. },
  124. {
  125. "parameters": {
  126. "modelName": "models/gemini-embedding-exp-03-07"
  127. },
  128. "type": "@n8n/n8n-nodes-langchain.embeddingsGoogleGemini",
  129. "typeVersion": 1,
  130. "position": [
  131. -32,
  132. 48
  133. ],
  134. "id": "67402e5f-270b-4e31-9b48-4d2a2b60d79e",
  135. "name": "Embeddings Google Gemini",
  136. "credentials": {
  137. "googlePalmApi": {
  138. "id": "4HqrqZ1DN3LCRp28",
  139. "name": "Google Gemini(PaLM) Api account"
  140. }
  141. }
  142. },
  143. {
  144. "parameters": {
  145. "options": {}
  146. },
  147. "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
  148. "typeVersion": 1.1,
  149. "position": [
  150. 128,
  151. 48
  152. ],
  153. "id": "e55e36f5-8628-496b-acb7-52a4f67b9af2",
  154. "name": "Default Data Loader"
  155. },
  156. {
  157. "parameters": {
  158. "jsCode": "return [\n\n {\n \"doc_id\": \"work-schedule-001\",\n \"content\": \"我的工作时间是周一至周五,上午9点到下午5点。时区是澳大利亚东部标准时间(AEST)。\"\n },\n {\n \"doc_id\": \"off-hours-policy-001\",\n \"content\": \"在非工作时间(包括周末和公共假期),我无法立即回复邮件。\"\n },\n {\n \"doc_id\": \"auto-reply-instruction-001\",\n \"content\": \"如果邮件是在非工作时间收到的,AI助手应该告知发件人,邮件已收到,我会在下一个工作日的9点到5点之间尽快处理并回复。\"\n }\n\n];"
  159. },
  160. "type": "n8n-nodes-base.code",
  161. "typeVersion": 2,
  162. "position": [
  163. -240,
  164. -160
  165. ],
  166. "id": "75bc8b52-3ff2-43b3-a6fa-d200c821de4a",
  167. "name": "Code in JavaScript1"
  168. },
  169. {
  170. "parameters": {
  171. "mode": "retrieve-as-tool",
  172. "toolDescription": "这是Simple Vector Store2工具,用来查询我的个人信息,特别是我的工作时间和邮件回复策略。当需要判断当前是否为工作时间,或者需要告知对方我何时会回复邮件时,必须使用此工具。",
  173. "memoryKey": {
  174. "__rl": true,
  175. "value": "my-dailytime",
  176. "mode": "list",
  177. "cachedResultName": "my-dailytime"
  178. }
  179. },
  180. "type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
  181. "typeVersion": 1.3,
  182. "position": [
  183. 800,
  184. 48
  185. ],
  186. "id": "ad9ba7d0-26b7-499b-9c5a-3d4295f6f7ed",
  187. "name": "Simple Vector Store2"
  188. },
  189. {
  190. "parameters": {
  191. "modelName": "models/gemini-embedding-exp-03-07"
  192. },
  193. "type": "@n8n/n8n-nodes-langchain.embeddingsGoogleGemini",
  194. "typeVersion": 1,
  195. "position": [
  196. 800,
  197. 208
  198. ],
  199. "id": "9ff48ca5-a7fd-45d6-8ff3-01c86bf63eea",
  200. "name": "Embeddings Google Gemini1",
  201. "credentials": {
  202. "googlePalmApi": {
  203. "id": "4HqrqZ1DN3LCRp28",
  204. "name": "Google Gemini(PaLM) Api account"
  205. }
  206. }
  207. },
  208. {
  209. "parameters": {
  210. "promptType": "define",
  211. "text": "=# 上下文信息\n- 当前时间: {{ new Date().toLocaleString('en-AU', { timeZone: 'Australia/Sydney', hour12: false }) }} (澳大利亚悉尼时间)\n- 发件人: {{ $json.From }}\n- 主题: {{ $json.Subject }}\n- 邮件正文: {{ $json.snippet }}",
  212. "hasOutputParser": true,
  213. "options": {
  214. "systemMessage": "=# 角色和目标\n你是一个全天候待命、专业高效的AI邮件助手。你的任务是:第一时间使用公开信息尽力回答所有邮件中的问题,并根据我的工作日程,在回复的开头附加上下文状态提醒。\n\n# 上下文信息\n- 当前时间: {{ new Date().toLocaleString('en-AU', { timeZone: 'Australia/Sydney', hour12: false }) }} (澳大利亚悉尼时间)\n- 邮件信息在输入数据中。\n\n# 可用工具\n- Simple Vector Store2: 用来查询我准确的工作时间(例如:周一至周五,上午9点到下午5点)。\n- SerpAPI: **[主要信息来源]** 优先使用此工具在互联网上搜索,以回答邮件中的具体问题。\n\n# 执行步骤\n1.  **分析问题**: 首先,仔细阅读邮件内容,提炼出发件人的核心问题。\n\n2.  **并行信息搜集**: 同时执行以下两个操作来收集信息:\n    a. 使用 `SerpAPI` 工具,上网搜索出发件人问题的答案。\n    b. 使用 `Simple Vector Store2` 工具,获取我设定的准确工作时间。\n\n3.  **草拟核心回复**: 根据 `SerpAPI` 搜集到的信息,清晰、直接地回答发件人的问题,这部分将作为邮件回复的主体。\n\n4.  **添加状态前缀并整合**:\n    a. 对比“当前时间”和我从工具中获取的工作时间。\n    b. **如果当前是“非工作时间”**: 创建一段状态提醒前缀。这段前缀**必须包含**从 `Simple Vector Store2` 获取到的具体工作时间。\n        * **前缀示例**: \"您好,感谢您的来信。您已在我的非工作时间联系我(我的工作时间为:[此处插入查询到的工作时间])。我会在下一个工作日亲自审阅此邮件。与此同时,这是根据公开信息为您找到的初步答复:**<br><br>---<br><br>**\"\n    c. **如果当前是“工作时间”**: 只需使用简单的问候语即可。\n        * **前缀示例**: \"您好,关于您提出的问题,答复如下:**<br><br>---<br><br>**\"\n    d. 将生成的前缀和你草拟的核心回复(第3步的结果)拼接在一起,形成最终的邮件正文。\n\n5.  **格式化输出**: 你必须将最终生成的邮件内容以一个严格的 JSON 格式输出。格式如下,不要添加任何额外的解释或文字:\n    {\n      \"shouldReply\": true,\n      \"subject\": \"Re: [原始邮件主题]\",\n      \"body\": \"[这里是拼接好的、完整的邮件回复正文,**所有换行必须使用HTML的<br>标签**]\"\n    }\n\n# 规则和限制\n- **永远优先尝试回答**: 无论何时,你的首要任务是使用 `SerpAPI` 为用户提供有价值的回复。\n- **必须声明状态**: 如果在非工作时间回复,必须在邮件开头明确声明,并附上我准确的工作时间。\n- **信息来源要准确**: 工作时间必须严格以 `Simple Vector Store2` 的结果为准;问题答案主要来源于 `SerpAPI`,不要编造信息。\n- **输出格式**: **在最终输出的JSON中,`body`字段内的所有换行都必须使用 `<br>` 标签,而不是 `\\n`。**"
  215. }
  216. },
  217. "type": "@n8n/n8n-nodes-langchain.agent",
  218. "typeVersion": 2.2,
  219. "position": [
  220. 576,
  221. -160
  222. ],
  223. "id": "b5e90bc0-1d53-4bea-9300-b9982ff5b9b4",
  224. "name": "AI Agent1"
  225. }
  226. ],
  227. "pinData": {},
  228. "connections": {
  229. "Gmail": {
  230. "main": [
  231. [
  232. {
  233. "node": "AI Agent1",
  234. "type": "main",
  235. "index": 0
  236. }
  237. ]
  238. ]
  239. },
  240. "Google Gemini Chat Model": {
  241. "ai_languageModel": [
  242. [
  243. {
  244. "node": "AI Agent1",
  245. "type": "ai_languageModel",
  246. "index": 0
  247. }
  248. ]
  249. ]
  250. },
  251. "Simple Memory": {
  252. "ai_memory": [
  253. [
  254. {
  255. "node": "AI Agent1",
  256. "type": "ai_memory",
  257. "index": 0
  258. }
  259. ]
  260. ]
  261. },
  262. "SerpAPI": {
  263. "ai_tool": [
  264. [
  265. {
  266. "node": "AI Agent1",
  267. "type": "ai_tool",
  268. "index": 0
  269. }
  270. ]
  271. ]
  272. },
  273. "Embeddings Google Gemini": {
  274. "ai_embedding": [
  275. [
  276. {
  277. "node": "Simple Vector Store1",
  278. "type": "ai_embedding",
  279. "index": 0
  280. }
  281. ]
  282. ]
  283. },
  284. "Default Data Loader": {
  285. "ai_document": [
  286. [
  287. {
  288. "node": "Simple Vector Store1",
  289. "type": "ai_document",
  290. "index": 0
  291. }
  292. ]
  293. ]
  294. },
  295. "Code in JavaScript1": {
  296. "main": [
  297. [
  298. {
  299. "node": "Simple Vector Store1",
  300. "type": "main",
  301. "index": 0
  302. }
  303. ]
  304. ]
  305. },
  306. "Simple Vector Store2": {
  307. "ai_tool": [
  308. [
  309. {
  310. "node": "AI Agent1",
  311. "type": "ai_tool",
  312. "index": 0
  313. }
  314. ]
  315. ]
  316. },
  317. "Embeddings Google Gemini1": {
  318. "ai_embedding": [
  319. [
  320. {
  321. "node": "Simple Vector Store2",
  322. "type": "ai_embedding",
  323. "index": 0
  324. }
  325. ]
  326. ]
  327. },
  328. "AI Agent1": {
  329. "main": [
  330. [
  331. {
  332. "node": "Send a message",
  333. "type": "main",
  334. "index": 0
  335. }
  336. ]
  337. ]
  338. }
  339. },
  340. "active": false,
  341. "settings": {
  342. "executionOrder": "v1"
  343. },
  344. "versionId": "4b54e880-ce89-48af-bc22-d753d162b460",
  345. "meta": {
  346. "instanceId": "87f6aa8e755e8ea119eeb2e3b3db6a7d58c6b1d2109e9b94ec4ef98f2449f77d"
  347. },
  348. "id": "b8xRsyXsQr5XE16V",
  349. "tags": []
  350. }