-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Expand file tree
/
Copy pathHost Your Own AI Deep Research Agent with n8n, Apify and OpenAI o3.json
More file actions
5883 lines (5883 loc) · 147 KB
/
Copy pathHost Your Own AI Deep Research Agent with n8n, Apify and OpenAI o3.json
File metadata and controls
5883 lines (5883 loc) · 147 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
"meta": {
"instanceId": "408f9fb9940c3cb18ffdef0e0150fe342d6e655c3a9fac21f0f644e8bedabcd9",
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "645ae2b1-799e-49be-8bdf-12cd1bb739e6",
"name": "Structured Output Parser",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
1680,
1140
],
"parameters": {
"schemaType": "manual",
"inputSchema": "{\n \"type\": \"object\",\n \"properties\": {\n \"learnings\": {\n \"type\": \"array\",\n \"description\": \"List of learnings, max of 3.\",\n \"items\": { \"type\": \"string\" }\n },\n \"followUpQuestions\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"string\",\n \"description\": \"List of follow-up questions to research the topic further, max of 3.\"\n }\n }\n }\n}"
},
"typeVersion": 1.2
},
{
"id": "cbdb4e98-eeba-4609-91de-394c416b7904",
"name": "Set Variables",
"type": "n8n-nodes-base.set",
"position": [
-1360,
-460
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "df28b12e-7c20-4ff5-b5b8-dc773aa14d4b",
"name": "request_id",
"type": "string",
"value": "={{ $execution.id }}"
},
{
"id": "9362c1e7-717d-444a-8ea2-6b5f958c9f3f",
"name": "prompt",
"type": "string",
"value": "={{ $json['What would you like to research?'] }}"
},
{
"id": "09094be4-7844-4a9e-af82-cc8e39322398",
"name": "depth",
"type": "number",
"value": "={{ $json['Enter research depth (recommended 1-5, default 2)'] || 2 }}"
},
{
"id": "3fc30a30-7806-4013-835d-97e27ddd7ae1",
"name": "breadth",
"type": "number",
"value": "={{ $json['Enter research breadth (recommended 2-10, default 4)'] || 4 }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "c7096ab9-0b10-45b0-b178-a049bf57830b",
"name": "OpenAI Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
1500,
1140
],
"parameters": {
"model": {
"__rl": true,
"mode": "id",
"value": "o3-mini"
},
"options": {}
},
"credentials": {
"openAiApi": {
"id": "8gccIjcuf3gvaoEr",
"name": "OpenAi account"
}
},
"typeVersion": 1.2
},
{
"id": "d0f1bc2f-6a10-4ac7-8d35-34f48f14fad5",
"name": "OpenAI Chat Model1",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
-860,
1760
],
"parameters": {
"model": {
"__rl": true,
"mode": "id",
"value": "o3-mini"
},
"options": {}
},
"credentials": {
"openAiApi": {
"id": "8gccIjcuf3gvaoEr",
"name": "OpenAi account"
}
},
"typeVersion": 1.2
},
{
"id": "bba3278c-0336-4305-887d-56515dfd87db",
"name": "OpenAI Chat Model2",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
-1060,
-300
],
"parameters": {
"model": {
"__rl": true,
"mode": "id",
"value": "o3-mini"
},
"options": {}
},
"credentials": {
"openAiApi": {
"id": "8gccIjcuf3gvaoEr",
"name": "OpenAi account"
}
},
"typeVersion": 1.2
},
{
"id": "f31f2fc7-0bec-4105-9d83-5f4f9a0eb35d",
"name": "Structured Output Parser1",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
-840,
-300
],
"parameters": {
"schemaType": "manual",
"inputSchema": "{\n \"type\": \"object\",\n \"properties\": {\n \"questions\": {\n \"type\": \"array\",\n \"description\": \"Follow up questions to clarify the research direction, max of 3.\",\n \"items\": {\n \"type\": \"string\"\n }\n }\n }\n}"
},
"typeVersion": 1.2
},
{
"id": "ea59c5ab-fa05-4c68-bc60-3f56e240478b",
"name": "On form submission",
"type": "n8n-nodes-base.formTrigger",
"position": [
-1760,
-460
],
"webhookId": "7ddfaa7c-a523-4d92-b033-d76cd5a313e9",
"parameters": {
"options": {
"path": "deep_research",
"ignoreBots": true,
"buttonLabel": "Next"
},
"formTitle": " DeepResearcher",
"formFields": {
"values": [
{
"fieldType": "html",
"fieldLabel": "placeholder"
}
]
},
"formDescription": "=DeepResearcher is a multi-step, recursive approach using the internet to solve complex research tasks, accomplishing in tens of minutes what a human would take many hours.\n\nTo use, provide a short summary of what the research and how \"deep\" you'd like the workflow to investigate. Note, the higher the numbers the more time and cost will occur for the research.\n\nThe workflow is designed to complete independently and when finished, a report will be saved in a designated Notion Database."
},
"typeVersion": 2.2
},
{
"id": "a8262288-a8c1-4967-9870-f728fa08b579",
"name": "Generate SERP Queries",
"type": "@n8n/n8n-nodes-langchain.chainLlm",
"position": [
-1040,
820
],
"parameters": {
"text": "=Given the following prompt from the user, generate a list of SERP queries to research the topic. Return a maximum of {{ $('JobType Router').first().json.data.breadth }} queries, but feel free to return less if the original prompt is clear. Make sure each query is unique and not similar to each other: <prompt>{{ $('JobType Router').first().json.data.query.trim() }}</prompt>\n\n{{\n$('JobType Router').first().json.data.learnings.length\n ? `Here are some learnings from previous research, use them to generate more specific queries: ${$('JobType Router').first().json.data.learnings.join('\\n')}`\n : ''\n}}",
"messages": {
"messageValues": [
{
"type": "HumanMessagePromptTemplate",
"message": "=You are an expert researcher. Today is {{ $now.toLocaleString() }}. Follow these instructions when responding:\n - You may be asked to research subjects that is after your knowledge cutoff, assume the user is right when presented with news.\n - The user is a highly experienced analyst, no need to simplify it, be as detailed as possible and make sure your response is correct.\n - Be highly organized.\n - Suggest solutions that I didn't think about.\n - Be proactive and anticipate my needs.\n - Treat me as an expert in all subject matter.\n - Mistakes erode my trust, so be accurate and thorough.\n - Provide detailed explanations, I'm comfortable with lots of detail.\n - Value good arguments over authorities, the source is irrelevant.\n - Consider new technologies and contrarian ideas, not just the conventional wisdom.\n - You may use high levels of speculation or prediction, just flag it for me."
}
]
},
"promptType": "define",
"hasOutputParser": true
},
"typeVersion": 1.5
},
{
"id": "0534be47-22b7-4c2a-956b-d085e6b9f280",
"name": "Structured Output Parser2",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
-860,
980
],
"parameters": {
"schemaType": "manual",
"inputSchema": "{\n \"type\": \"object\",\n \"properties\": {\n \"queries\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"object\",\n \"properties\": {\n \"query\": {\n \"type\": \"string\",\n \"description\": \"The SERP query\"\n },\n \"researchGoal\": {\n \"type\": \"string\",\n \"description\": \"First talk about the goal of the research that this query is meant to accomplish, then go deeper into how to advance the research once the results are found, mention additional research directions. Be as specific as possible, especially for additional research directions.\"\n }\n }\n }\n }\n }\n}"
},
"typeVersion": 1.2
},
{
"id": "4d8aa196-986f-442d-9b56-92c043ab785d",
"name": "OpenAI Chat Model3",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
-1040,
980
],
"parameters": {
"model": {
"__rl": true,
"mode": "id",
"value": "o3-mini"
},
"options": {}
},
"credentials": {
"openAiApi": {
"id": "8gccIjcuf3gvaoEr",
"name": "OpenAi account"
}
},
"typeVersion": 1.2
},
{
"id": "7488b037-7422-4f62-8c37-1f6a901b3299",
"name": "Set Initial Query",
"type": "n8n-nodes-base.set",
"position": [
-580,
180
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "acb41e93-70c6-41a3-be0f-e5a74ec3ec88",
"name": "query",
"type": "string",
"value": "={{ $('JobType Router').first().json.data.query }}"
},
{
"id": "7fc54063-b610-42bc-a250-b1e8847c4d1e",
"name": "learnings",
"type": "array",
"value": "={{ $('JobType Router').first().json.data.learnings }}"
},
{
"id": "e8f1c158-56fb-41c8-8d86-96add16289bb",
"name": "breadth",
"type": "number",
"value": "={{ $('JobType Router').first().json.data.breadth }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "12ae382e-d88a-4f1b-a71f-3bd63c892b17",
"name": "SERP to Items",
"type": "n8n-nodes-base.splitOut",
"position": [
-700,
820
],
"parameters": {
"options": {},
"fieldToSplitOut": "output.queries"
},
"typeVersion": 1
},
{
"id": "46700052-f48a-493c-aebf-cdf175d58550",
"name": "Item Ref",
"type": "n8n-nodes-base.noOp",
"position": [
-240,
980
],
"parameters": {},
"typeVersion": 1
},
{
"id": "2cef6f1d-e244-4ee6-bf25-6dc3e8042afa",
"name": "Research Goal + Learnings",
"type": "n8n-nodes-base.set",
"position": [
1840,
1120
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "9acec2cc-64c8-4e62-bed4-c3d9ffab1379",
"name": "researchGoal",
"type": "string",
"value": "={{ $('Item Ref').first().json.researchGoal }}"
},
{
"id": "1b2d2dad-429b-4fc9-96c5-498f572a85c3",
"name": "learnings",
"type": "array",
"value": "={{ $json.output.learnings }}"
},
{
"id": "655b99f2-6045-4774-a634-49751bc9326f",
"name": "followUpQuestions",
"type": "array",
"value": "={{ $json.output.followUpQuestions }}"
},
{
"id": "c9e34ea4-5606-46d6-8d66-cb42d772a8b4",
"name": "urls",
"type": "array",
"value": "={{\n$('Page Contents')\n .all()\n .filter(item => !item.json.error && item.json.body)\n .map(item => item.json.url)\n}}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "4aebae86-2bd2-4f3d-8290-d34b9ac837c6",
"name": "Accumulate Results",
"type": "n8n-nodes-base.set",
"position": [
-200,
180
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "db509e90-9a86-431f-8149-4094d22666cc",
"name": "should_stop",
"type": "boolean",
"value": "={{\n$runIndex >= ($('JobType Router').first().json.data.depth)\n}}"
},
{
"id": "90986e2b-8aca-4a22-a9db-ed8809d6284d",
"name": "all_learnings",
"type": "array",
"value": "={{\nArray($runIndex+1)\n .fill(0)\n .flatMap((_,idx) => {\n try {\n return $('Generate Learnings')\n .all(0,idx)\n .flatMap(item => item.json.data.flatMap(d => d.learnings))\n } catch (e) {\n return []\n }\n })\n}}"
},
{
"id": "3eade958-e8ab-4975-aac4-f4a4a983c163",
"name": "all_urls",
"type": "array",
"value": "={{\nArray($runIndex+1)\n .fill(0)\n .flatMap((_,idx) => {\n try {\n return $('Generate Learnings')\n .all(0,idx)\n .flatMap(item => item.json.data.flatMap(d => d.urls))\n } catch (e) {\n return []\n }\n })\n}}"
}
]
}
},
"executeOnce": true,
"typeVersion": 3.4
},
{
"id": "782baa36-ba07-4845-873c-c9400de6d463",
"name": "DeepResearch Results",
"type": "n8n-nodes-base.set",
"position": [
160,
360
],
"parameters": {
"mode": "raw",
"options": {},
"jsonOutput": "={{ $('Generate Learnings').item.json }}"
},
"typeVersion": 3.4
},
{
"id": "89b09898-79ec-4924-975f-e9581d3bf774",
"name": "Results to Items",
"type": "n8n-nodes-base.splitOut",
"position": [
320,
360
],
"parameters": {
"options": {},
"fieldToSplitOut": "data"
},
"typeVersion": 1
},
{
"id": "122cd071-aade-4753-ba0a-8db4c58fa84e",
"name": "Set Next Queries",
"type": "n8n-nodes-base.set",
"position": [
480,
360
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "d88bfe95-9e73-4d25-b45c-9f164b940b0e",
"name": "query",
"type": "string",
"value": "=Previous research goal: {{ $json.researchGoal }}\nFollow-up research directions: {{ $json.followUpQuestions.map(q => `\\n${q}`).join('') }}"
},
{
"id": "4aa20690-d998-458a-b1e4-0d72e6a68e6b",
"name": "learnings",
"type": "array",
"value": "={{ $('Accumulate Results').item.json.all_learnings }}"
},
{
"id": "89acafae-b04a-4d5d-b08b-656e715654e4",
"name": "breadth",
"type": "number",
"value": "={{ $('JobType Router').first().json.data.breadth }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "9da01d8a-48d6-45b4-b8c6-9a0503b4bda6",
"name": "Web Search",
"type": "n8n-nodes-base.httpRequest",
"onError": "continueRegularOutput",
"position": [
-80,
980
],
"parameters": {
"url": "https://api.apify.com/v2/acts/serping~fast-google-search-results-scraper/run-sync-get-dataset-items",
"method": "POST",
"options": {},
"sendBody": true,
"authentication": "genericCredentialType",
"bodyParameters": {
"parameters": [
{
"name": "searchTerms",
"value": "={{\n[\n `${$json.query} -filetype:pdf`\n]\n}}"
},
{
"name": "resultsPerPage",
"value": "={{ 10 }}"
}
]
},
"genericAuthType": "httpHeaderAuth"
},
"credentials": {
"httpQueryAuth": {
"id": "cO2w8RDNOZg8DRa8",
"name": "Apify API"
},
"httpHeaderAuth": {
"id": "SV9BDKc1cRbZBeoL",
"name": "Apify.com (personal token)"
}
},
"typeVersion": 4.2
},
{
"id": "99bd2c8e-5600-43a9-ab2f-7f2911efb16c",
"name": "Top 5 Organic Results",
"type": "n8n-nodes-base.set",
"position": [
80,
980
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "29d1a759-d886-4a44-860b-9d16f9922043",
"name": "results",
"type": "array",
"value": "={{\n$json.origin_search.results\n ? $json.origin_search\n .results\n .filter(res => res.type === 'normal')\n .slice(0, 5)\n .map(res => ({\n title: res.title,\n url: res.source.link\n }))\n : []\n}}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "cb7c5a8b-5420-4fb9-b7f0-4e8e8d10034a",
"name": "Convert to Markdown",
"type": "n8n-nodes-base.markdown",
"position": [
1320,
980
],
"parameters": {
"html": "={{ $json.body }}",
"options": {
"ignore": "a,img,picture,svg,video,audio,iframe"
},
"destinationKey": "markdown"
},
"typeVersion": 1
},
{
"id": "818ccf2e-081d-492e-ba8d-de458b0c26db",
"name": "For Each Query...",
"type": "n8n-nodes-base.splitInBatches",
"position": [
-420,
820
],
"parameters": {
"options": {}
},
"typeVersion": 3
},
{
"id": "1787b562-17e8-41af-9cdc-eb2d3e630916",
"name": "Feedback to Items",
"type": "n8n-nodes-base.splitOut",
"position": [
-720,
-460
],
"parameters": {
"options": {},
"fieldToSplitOut": "output.questions"
},
"typeVersion": 1
},
{
"id": "4c695faa-74e3-456b-a1ef-aaea67e46743",
"name": "Ask Clarity Questions",
"type": "n8n-nodes-base.form",
"position": [
-360,
-380
],
"webhookId": "ab0d9b81-73f6-4baa-a3cd-ac3b31397708",
"parameters": {
"options": {
"formTitle": "DeepResearcher",
"buttonLabel": "Answer",
"formDescription": "=<img\n src=\"https://res.cloudinary.com/daglih2g8/image/upload/f_auto,q_auto/v1/n8n-workflows/o4wqztloz3j6okfxpeyw\"\n width=\"100%\"\n style=\"border:1px solid #ccc\"\n/>\n<p style=\"text-align:left\">\nAnswer the following clarification questions to assist the DeepResearcher better under the research topic.\n</p>\n<hr style=\"display:block;margin-top:16px;margin-bottom:0\" />\n<p style=\"text-align:left;font-family:sans-serif;font-weight:700;\">\nTotal {{ $('Feedback to Items').all().length }} questions.\n</p>"
},
"formFields": {
"values": [
{
"fieldType": "textarea",
"fieldLabel": "={{ $json[\"output.questions\"] }}",
"placeholder": "=",
"requiredField": true
}
]
}
},
"typeVersion": 1
},
{
"id": "e07d8c3e-8bcd-4393-9892-f825433ab58d",
"name": "For Each Question...",
"type": "n8n-nodes-base.splitInBatches",
"position": [
-540,
-460
],
"parameters": {
"options": {}
},
"typeVersion": 3
},
{
"id": "e8d26351-52f4-40a6-ba5b-fb6bc816b734",
"name": "DeepResearch Subworkflow",
"type": "n8n-nodes-base.executeWorkflowTrigger",
"position": [
-1880,
820
],
"parameters": {
"workflowInputs": {
"values": [
{
"name": "requestId",
"type": "any"
},
{
"name": "jobType"
},
{
"name": "data",
"type": "object"
}
]
}
},
"typeVersion": 1.1
},
{
"id": "25a8055a-27aa-414f-856b-25a2e2f31974",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1140,
-680
],
"parameters": {
"color": 7,
"width": 1000,
"height": 560,
"content": "## 2. Ask Clarifying Questions\n[Read more about form nodes](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.form/)\n\nTo handle the clarification questions generated by the LLM, I used the same technique found in my \"AI Interviewer\" template ([link](https://n8n.io/workflows/2566-conversational-interviews-with-ai-agents-and-n8n-forms/)).\nThis involves a looping of dynamically generated forms to collect answers from the user."
},
"typeVersion": 1
},
{
"id": "68398b92-eb35-48bf-885e-540074531cc4",
"name": "Clarifying Questions",
"type": "@n8n/n8n-nodes-langchain.chainLlm",
"position": [
-1040,
-460
],
"parameters": {
"text": "=Given the following query from the user, ask some follow up questions to clarify the research direction. Return a maximum of 3 questions, but feel free to return less if the original query is clear: <query>{{ $json.prompt }}</query>`",
"messages": {
"messageValues": [
{
"type": "HumanMessagePromptTemplate",
"message": "=You are an expert researcher. Today is {{ $now.toLocaleString() }}. Follow these instructions when responding:\n - You may be asked to research subjects that is after your knowledge cutoff, assume the user is right when presented with news.\n - The user is a highly experienced analyst, no need to simplify it, be as detailed as possible and make sure your response is correct.\n - Be highly organized.\n - Suggest solutions that I didn't think about.\n - Be proactive and anticipate my needs.\n - Treat me as an expert in all subject matter.\n - Mistakes erode my trust, so be accurate and thorough.\n - Provide detailed explanations, I'm comfortable with lots of detail.\n - Value good arguments over authorities, the source is irrelevant.\n - Consider new technologies and contrarian ideas, not just the conventional wisdom.\n - You may use high levels of speculation or prediction, just flag it for me."
}
]
},
"promptType": "define",
"hasOutputParser": true
},
"typeVersion": 1.5
},
{
"id": "65c4c293-67b8-4e64-af04-16e45e97c09a",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-660,
-60
],
"parameters": {
"color": 7,
"width": 1360,
"height": 640,
"content": "## 6. Perform DeepSearch Loop\n[Learn more about the Looping in n8n](https://docs.n8n.io/flow-logic/looping/#creating-loops)\n\nThe key of the Deep Research flow is its extensive data collection capability. In this implementation, this capability is represented by a recursive web search & scrape loop which starts with the original query and extended by AI-generated subqueries. How many subqueries to generate are determined the depth and breadth parameters specified.\n\n\"Learnings\" are generated for each subquery and accumulate on each iteration of the loop. When the loop finishes when depth limit is reached, all learnings are collected and it's these learnings are what we use to generate the report."
},
"typeVersion": 1
},
{
"id": "43a5d93d-cae2-43ec-b9ae-b15d6b11b932",
"name": "End Form",
"type": "n8n-nodes-base.form",
"position": [
960,
-420
],
"webhookId": "7b531f5d-942f-4c49-ac55-8ee480889600",
"parameters": {
"options": {},
"operation": "completion",
"completionTitle": "=Thank you for using DeepResearcher.",
"completionMessage": "=You may now close this window."
},
"typeVersion": 1
},
{
"id": "9a824011-e76f-433f-8735-44b358f4ff7d",
"name": "Initiate DeepResearch",
"type": "n8n-nodes-base.executeWorkflow",
"position": [
600,
-420
],
"parameters": {
"mode": "each",
"options": {
"waitForSubWorkflow": false
},
"workflowId": {
"__rl": true,
"mode": "id",
"value": "={{ $workflow.id }}"
},
"workflowInputs": {
"value": {
"data": "={{\n{\n \"query\": $('Get Initial Query').first().json.query,\n \"learnings\": [],\n \"depth\": $('Set Variables').first().json.depth,\n \"breadth\": $('Set Variables').first().json.breadth,\n}\n}}",
"jobType": "deepresearch_initiate",
"requestId": "={{ $('Set Variables').first().json.request_id }}"
},
"schema": [
{
"id": "requestId",
"display": true,
"removed": false,
"required": false,
"displayName": "requestId",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "jobType",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "jobType",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "data",
"type": "object",
"display": true,
"removed": false,
"required": false,
"displayName": "data",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [],
"attemptToConvertTypes": false,
"convertFieldsToString": true
}
},
"typeVersion": 1.2
},
{
"id": "c48ee4cd-bac1-4405-bb4c-5614e5eb25a0",
"name": "Page Contents",
"type": "n8n-nodes-base.httpRequest",
"onError": "continueRegularOutput",
"position": [
560,
980
],
"parameters": {
"url": "https://api.apify.com/v2/acts/apify~web-scraper/run-sync-get-dataset-items",
"options": {},
"jsonBody": "={\n \"startUrls\": {{ [{ url: $json.url, method: 'GET' }].toJsonString() }},\n \"breakpointLocation\": \"NONE\",\n \"browserLog\": false,\n \"closeCookieModals\": false,\n \"debugLog\": false,\n \"downloadCss\": false,\n \"downloadMedia\": false,\n \"excludes\": [\n {\n \"glob\": \"/**/*.{png,jpg,jpeg,pdf}\"\n }\n ],\n \"headless\": true,\n \"ignoreCorsAndCsp\": false,\n \"ignoreSslErrors\": false,\n \"injectJQuery\": true,\n \"keepUrlFragments\": false,\n \"linkSelector\": \"\",\n \"maxCrawlingDepth\": 1,\n \"maxPagesPerCrawl\": 1,\n \"maxRequestRetries\": 1,\n \"maxResultsPerCrawl\": 1,\n \"pageFunction\": \"// The function accepts a single argument: the \\\"context\\\" object.\\n// For a complete list of its properties and functions,\\n// see https://apify.com/apify/web-scraper#page-function \\nasync function pageFunction(context) {\\n\\n await new Promise(res => { setTimeout(res, 6000) });\\n // This statement works as a breakpoint when you're trying to debug your code. Works only with Run mode: DEVELOPMENT!\\n // debugger; \\n\\n // jQuery is handy for finding DOM elements and extracting data from them.\\n // To use it, make sure to enable the \\\"Inject jQuery\\\" option.\\n const $ = context.jQuery;\\n const title = $('title').first().text();\\n\\n // Clone the body to avoid modifying the original content\\n const bodyClone = $('body').clone();\\n bodyClone.find('iframe, img, script, style, object, embed, noscript, svg, video, audio').remove();\\n const body = bodyClone.html();\\n\\n // Return an object with the data extracted from the page.\\n // It will be stored to the resulting dataset.\\n return {\\n url: context.request.url,\\n title,\\n body\\n };\\n}\",\n \"postNavigationHooks\": \"// We need to return array of (possibly async) functions here.\\n// The functions accept a single argument: the \\\"crawlingContext\\\" object.\\n[\\n async (crawlingContext) => {\\n // ...\\n },\\n]\",\n \"preNavigationHooks\": \"// We need to return array of (possibly async) functions here.\\n// The functions accept two arguments: the \\\"crawlingContext\\\" object\\n// and \\\"gotoOptions\\\".\\n[\\n async (crawlingContext, gotoOptions) => {\\n // ...\\n },\\n]\\n\",\n \"proxyConfiguration\": {\n \"useApifyProxy\": true\n },\n \"runMode\": \"PRODUCTION\",\n \"useChrome\": false,\n \"waitUntil\": [\n \"domcontentloaded\"\n ],\n \"globs\": [],\n \"pseudoUrls\": [],\n \"proxyRotation\": \"RECOMMENDED\",\n \"maxConcurrency\": 50,\n \"pageLoadTimeoutSecs\": 60,\n \"pageFunctionTimeoutSecs\": 60,\n \"maxScrollHeightPixels\": 5000,\n \"customData\": {}\n}",
"sendBody": true,
"sendQuery": true,
"specifyBody": "json",
"authentication": "genericCredentialType",
"genericAuthType": "httpQueryAuth",
"queryParameters": {
"parameters": [
{
"name": "memory",
"value": "2048"
},
{
"name": "timeout",
"value": "90"
}
]
}
},
"credentials": {
"httpQueryAuth": {
"id": "cO2w8RDNOZg8DRa8",
"name": "Apify API"
}
},
"typeVersion": 4.2
},
{
"id": "dc9f85ff-7565-4c29-981a-5ef65bba6ca3",
"name": "Execution Data",
"type": "n8n-nodes-base.executionData",
"position": [
-1700,
820
],
"parameters": {
"dataToSave": {
"values": [
{
"key": "requestId",
"value": "={{ $json.requestId }}"
},
{
"key": "=jobType",
"value": "={{ $json.jobType }}"
}
]
}
},
"typeVersion": 1
},
{
"id": "26b33429-6d61-4758-9c76-3e998dd31fa4",
"name": "JobType Router",
"type": "n8n-nodes-base.switch",
"position": [
-1520,
820
],
"parameters": {
"rules": {
"values": [
{
"outputKey": "initiate",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.jobType }}",
"rightValue": "deepresearch_initiate"
}
]
},
"renameOutput": true
},
{
"outputKey": "learnings",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "ecbfa54d-fc97-48c5-8d3d-f0538b8d727b",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.jobType }}",
"rightValue": "deepresearch_learnings"
}
]
},
"renameOutput": true
},
{
"outputKey": "report",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "392f9a98-ec22-4e57-9c8e-0e1ed6b7dafa",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.jobType }}",
"rightValue": "deepresearch_report"
}
]
},
"renameOutput": true
}
]
},
"options": {}
},
"typeVersion": 3.2
},
{
"id": "a9637952-7c09-40ae-96ec-bdf0fc63d94e",
"name": "Valid Pages",
"type": "n8n-nodes-base.filter",
"position": [
720,
980
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "f44691e4-f753-47b0-b66a-068a723b6beb",
"operator": {
"type": "boolean",
"operation": "false",
"singleValue": true
},
"leftValue": "={{ $json['#error'] }}",
"rightValue": ""
},
{
"id": "8e05df2b-0d4a-47da-9aab-da7e8907cbca",
"operator": {
"type": "string",
"operation": "notEmpty",
"singleValue": true
},
"leftValue": "={{ $json.body }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2,
"alwaysOutputData": true
},
{
"id": "204cfca2-05bb-46dd-ba96-b41866ed2cfe",
"name": "OpenAI Chat Model4",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
-20,
-280
],
"parameters": {
"model": {
"__rl": true,
"mode": "id",
"value": "o3-mini"
},
"options": {}
},
"credentials": {
"openAiApi": {
"id": "8gccIjcuf3gvaoEr",
"name": "OpenAi account"
}
},
"typeVersion": 1.2
},
{
"id": "45bc6261-35c8-4994-bb88-ed7a0f022767",
"name": "Get Initial Query",
"type": "n8n-nodes-base.set",
"position": [
-360,
-540
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "14b77741-c3c3-4bd2-be6e-37bd09fcea2b",
"name": "query",
"type": "string",
"value": "=Initial query: {{ $('Set Variables').first().json.prompt }}\nFollow-up Questions and Answers:\n{{\n$input.all()\n .map(item => {\n const q = Object.keys(item.json)[0];\n const a = item.json[q];\n return `question: ${q}\\nanswer: ${a}`;\n })\n .join('\\n')\n}}"
}
]
}
},
"executeOnce": true,
"typeVersion": 3.4
},
{
"id": "26d26e54-ee9b-4714-ae27-4f033dc825d3",
"name": "Structured Output Parser4",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
160,