-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSuperMind Level Hackathon.json
2572 lines (2572 loc) · 129 KB
/
SuperMind Level Hackathon.json
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
{
"description": "Social Media Engagement Analyzer with Langflow and DataStax",
"id": "12347358-fe77-43b9-9485-815c6afd5b5a",
"name": "SuperMind Level Hackathon",
"data": {
"nodes": [
{
"id": "AstraDBToolComponent-NJe1R",
"type": "genericNode",
"position": {
"x": 2178.6828697560504,
"y": 353.92638112615134
},
"data": {
"node": {
"template": {
"_type": "Component",
"api_endpoint": {
"trace_as_metadata": true,
"load_from_db": false,
"list": false,
"required": true,
"placeholder": "",
"show": true,
"name": "api_endpoint",
"value": "https://bd2a987d-deb4-4685-8135-1f69036871ef-us-east-2.apps.astra.datastax.com",
"display_name": "API Endpoint",
"advanced": false,
"dynamic": false,
"info": "API endpoint URL for the Astra DB service.",
"title_case": false,
"type": "str",
"_input_type": "StrInput"
},
"code": {
"type": "code",
"required": true,
"placeholder": "",
"list": false,
"show": true,
"multiline": true,
"value": "from typing import Any\n\nfrom astrapy import Collection, DataAPIClient, Database\nfrom langchain.pydantic_v1 import BaseModel, Field, create_model\nfrom langchain_core.tools import StructuredTool\n\nfrom langflow.base.langchain_utilities.model import LCToolComponent\nfrom langflow.io import DictInput, IntInput, SecretStrInput, StrInput\nfrom langflow.schema import Data\n\n\nclass AstraDBToolComponent(LCToolComponent):\n display_name: str = \"Astra DB\"\n description: str = \"Create a tool to get transactional data from DataStax Astra DB Collection\"\n documentation: str = \"https://docs.langflow.org/Components/components-tools#astra-db-tool\"\n icon: str = \"AstraDB\"\n\n inputs = [\n StrInput(\n name=\"tool_name\",\n display_name=\"Tool Name\",\n info=\"The name of the tool.\",\n required=True,\n ),\n StrInput(\n name=\"tool_description\",\n display_name=\"Tool Description\",\n info=\"The description of the tool.\",\n required=True,\n ),\n StrInput(\n name=\"namespace\",\n display_name=\"Namespace Name\",\n info=\"The name of the namespace within Astra where the collection is be stored.\",\n value=\"default_keyspace\",\n advanced=True,\n ),\n StrInput(\n name=\"collection_name\",\n display_name=\"Collection Name\",\n info=\"The name of the collection within Astra DB where the vectors will be stored.\",\n required=True,\n ),\n SecretStrInput(\n name=\"token\",\n display_name=\"Astra DB Application Token\",\n info=\"Authentication token for accessing Astra DB.\",\n value=\"ASTRA_DB_APPLICATION_TOKEN\",\n required=True,\n ),\n StrInput(\n name=\"api_endpoint\",\n display_name=\"API Endpoint\",\n info=\"API endpoint URL for the Astra DB service.\",\n value=\"ASTRA_DB_API_ENDPOINT\",\n required=True,\n ),\n StrInput(\n name=\"projection_attributes\",\n display_name=\"Projection Attributes\",\n info=\"Attributes to return separated by comma.\",\n required=True,\n value=\"*\",\n advanced=True,\n ),\n DictInput(\n name=\"tool_params\",\n info=\"Attributes to filter and description to the model. Add ! for mandatory (e.g: !customerId)\",\n display_name=\"Tool params\",\n is_list=True,\n ),\n DictInput(\n name=\"static_filters\",\n info=\"Attributes to filter and correspoding value\",\n display_name=\"Static filters\",\n advanced=True,\n is_list=True,\n ),\n IntInput(\n name=\"number_of_results\",\n display_name=\"Number of Results\",\n info=\"Number of results to return.\",\n advanced=True,\n value=5,\n ),\n ]\n\n _cached_client: DataAPIClient | None = None\n _cached_db: Database | None = None\n _cached_collection: Collection | None = None\n\n def _build_collection(self):\n if self._cached_collection:\n return self._cached_collection\n\n _cached_client = DataAPIClient(self.token)\n _cached_db = _cached_client.get_database(self.api_endpoint, namespace=self.namespace)\n self._cached_collection = _cached_db.get_collection(self.collection_name)\n return self._cached_collection\n\n def create_args_schema(self) -> dict[str, BaseModel]:\n args: dict[str, tuple[Any, Field] | list[str]] = {}\n\n for key in self.tool_params:\n if key.startswith(\"!\"): # Mandatory\n args[key[1:]] = (str, Field(description=self.tool_params[key]))\n else: # Optional\n args[key] = (str | None, Field(description=self.tool_params[key], default=None))\n\n model = create_model(\"ToolInput\", **args, __base__=BaseModel)\n return {\"ToolInput\": model}\n\n def build_tool(self) -> StructuredTool:\n \"\"\"Builds an Astra DB Collection tool.\n\n Returns:\n Tool: The built Astra DB tool.\n \"\"\"\n schema_dict = self.create_args_schema()\n\n tool = StructuredTool.from_function(\n name=self.tool_name,\n args_schema=schema_dict[\"ToolInput\"],\n description=self.tool_description,\n func=self.run_model,\n return_direct=False,\n )\n self.status = \"Astra DB Tool created\"\n\n return tool\n\n def projection_args(self, input_str: str) -> dict:\n elements = input_str.split(\",\")\n result = {}\n\n for element in elements:\n if element.startswith(\"!\"):\n result[element[1:]] = False\n else:\n result[element] = True\n\n return result\n\n def run_model(self, **args) -> Data | list[Data]:\n collection = self._build_collection()\n results = collection.find(\n ({**args, **self.static_filters}),\n projection=self.projection_args(self.projection_attributes),\n limit=self.number_of_results,\n )\n\n data: list[Data] = [Data(data=doc) for doc in results]\n self.status = data\n return data\n",
"fileTypes": [],
"file_path": "",
"password": false,
"name": "code",
"advanced": true,
"dynamic": true,
"info": "",
"load_from_db": false,
"title_case": false
},
"collection_name": {
"trace_as_metadata": true,
"load_from_db": false,
"list": false,
"required": true,
"placeholder": "",
"show": true,
"name": "collection_name",
"value": "socials",
"display_name": "Collection Name",
"advanced": false,
"dynamic": false,
"info": "The name of the collection within Astra DB where the vectors will be stored.",
"title_case": false,
"type": "str",
"_input_type": "StrInput"
},
"namespace": {
"trace_as_metadata": true,
"load_from_db": false,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "namespace",
"value": "default_keyspace",
"display_name": "Namespace Name",
"advanced": true,
"dynamic": false,
"info": "The name of the namespace within Astra where the collection is be stored.",
"title_case": false,
"type": "str",
"_input_type": "StrInput"
},
"number_of_results": {
"trace_as_metadata": true,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "number_of_results",
"value": 100,
"display_name": "Number of Results",
"advanced": true,
"dynamic": false,
"info": "Number of results to return.",
"title_case": false,
"type": "int",
"_input_type": "IntInput"
},
"projection_attributes": {
"trace_as_metadata": true,
"load_from_db": false,
"list": false,
"required": true,
"placeholder": "",
"show": true,
"name": "projection_attributes",
"value": "*",
"display_name": "Projection Attributes",
"advanced": true,
"dynamic": false,
"info": "Attributes to return separated by comma.",
"title_case": false,
"type": "str",
"_input_type": "StrInput"
},
"static_filters": {
"trace_as_input": true,
"list": true,
"required": false,
"placeholder": "",
"show": true,
"name": "static_filters",
"value": [
{
"Platform": "Instagram"
}
],
"display_name": "Static filters",
"advanced": false,
"dynamic": false,
"info": "Attributes to filter and correspoding value",
"title_case": false,
"type": "dict",
"_input_type": "DictInput"
},
"token": {
"load_from_db": false,
"required": true,
"placeholder": "",
"show": true,
"name": "token",
"value": "AstraCS:jjmOFQpHwGnfzibutxZTRWuL:49280efa4d7cb74aca6b01e2ae14442638a1c039fce1fe94e669e7baa63abd34",
"display_name": "Astra DB Application Token",
"advanced": false,
"input_types": [
"Message"
],
"dynamic": false,
"info": "Authentication token for accessing Astra DB.",
"title_case": false,
"password": true,
"type": "str",
"_input_type": "SecretStrInput"
},
"tool_description": {
"trace_as_metadata": true,
"load_from_db": false,
"list": false,
"required": true,
"placeholder": "",
"show": true,
"name": "tool_description",
"value": "Get social media post data from Astra DB",
"display_name": "Tool Description",
"advanced": false,
"dynamic": false,
"info": "The description of the tool.",
"title_case": false,
"type": "str",
"_input_type": "StrInput"
},
"tool_name": {
"trace_as_metadata": true,
"load_from_db": false,
"list": false,
"required": true,
"placeholder": "",
"show": true,
"name": "tool_name",
"value": "astra_db_fetch",
"display_name": "Tool Name",
"advanced": false,
"dynamic": false,
"info": "The name of the tool.",
"title_case": false,
"type": "str",
"_input_type": "StrInput"
},
"tool_params": {
"trace_as_input": true,
"list": true,
"required": false,
"placeholder": "",
"show": true,
"name": "tool_params",
"value": [
{
"": ""
}
],
"display_name": "Tool params",
"advanced": true,
"dynamic": false,
"info": "Attributes to filter and description to the model. Add ! for mandatory (e.g: !customerId)",
"title_case": false,
"type": "dict",
"_input_type": "DictInput"
}
},
"description": "Create a tool to get transactional data from DataStax Astra DB Collection",
"icon": "AstraDB",
"base_classes": [
"Data",
"StructuredTool"
],
"display_name": "Astra DB",
"documentation": "https://docs.langflow.org/Components/components-tools#astra-db-tool",
"custom_fields": {},
"output_types": [],
"pinned": false,
"conditional_paths": [],
"frozen": false,
"outputs": [
{
"types": [
"Data"
],
"selected": "Data",
"name": "api_run_model",
"display_name": "Data",
"method": "run_model",
"value": "__UNDEFINED__",
"cache": true,
"required_inputs": [
"api_endpoint",
"collection_name",
"projection_attributes",
"token",
"tool_description",
"tool_name"
]
},
{
"types": [
"StructuredTool"
],
"selected": "StructuredTool",
"name": "api_build_tool",
"display_name": "Tool",
"method": "build_tool",
"value": "__UNDEFINED__",
"cache": true,
"required_inputs": [
"api_endpoint",
"collection_name",
"projection_attributes",
"token",
"tool_description",
"tool_name"
]
}
],
"field_order": [
"tool_name",
"tool_description",
"namespace",
"collection_name",
"token",
"api_endpoint",
"projection_attributes",
"tool_params",
"static_filters",
"number_of_results"
],
"beta": false,
"legacy": false,
"edited": false,
"metadata": {},
"tool_mode": false,
"category": "tools",
"key": "AstraDBToolComponent",
"score": 0.007568328950209746,
"lf_version": "1.1.1"
},
"type": "AstraDBToolComponent",
"id": "AstraDBToolComponent-NJe1R"
},
"selected": false,
"width": 320,
"height": 735,
"positionAbsolute": {
"x": 2178.6828697560504,
"y": 353.92638112615134
},
"dragging": false
},
{
"id": "Agent-EvgUv",
"type": "genericNode",
"position": {
"x": 3000.9143035979964,
"y": 633.02787823479
},
"data": {
"node": {
"template": {
"_type": "Component",
"memory": {
"trace_as_metadata": true,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "memory",
"value": "",
"display_name": "External Memory",
"advanced": true,
"input_types": [
"BaseChatMessageHistory"
],
"dynamic": false,
"info": "Retrieve messages from an external memory. If empty, it will use the Langflow tables.",
"title_case": false,
"type": "other",
"_input_type": "HandleInput"
},
"tools": {
"trace_as_metadata": true,
"list": true,
"required": false,
"placeholder": "",
"show": true,
"name": "tools",
"value": "",
"display_name": "Tools",
"advanced": false,
"input_types": [
"Tool",
"BaseTool",
"StructuredTool"
],
"dynamic": false,
"info": "These are the tools that the agent can use to help with tasks.",
"title_case": false,
"type": "other",
"_input_type": "HandleInput"
},
"add_current_date_tool": {
"trace_as_metadata": true,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "add_current_date_tool",
"value": true,
"display_name": "Add tool Current Date",
"advanced": true,
"dynamic": false,
"info": "If true, will add a tool to the agent that returns the current date.",
"title_case": false,
"type": "bool",
"_input_type": "BoolInput",
"input_types": []
},
"agent_description": {
"tool_mode": false,
"trace_as_input": true,
"multiline": true,
"trace_as_metadata": true,
"load_from_db": false,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "agent_description",
"value": "A helpful assistant with access to the following tools:",
"display_name": "Agent Description",
"advanced": true,
"input_types": [
"Message"
],
"dynamic": false,
"info": "The description of the agent. This is only used when in Tool Mode. Defaults to 'A helpful assistant with access to the following tools:' and tools are added dynamically.",
"title_case": false,
"type": "str",
"_input_type": "MultilineInput"
},
"agent_llm": {
"tool_mode": false,
"trace_as_metadata": true,
"options": [
"Amazon Bedrock",
"Anthropic",
"Azure OpenAI",
"Groq",
"NVIDIA",
"OpenAI",
"Custom"
],
"combobox": false,
"required": false,
"placeholder": "",
"show": true,
"name": "agent_llm",
"value": "Groq",
"display_name": "Language Model",
"advanced": false,
"input_types": [],
"dynamic": false,
"info": "",
"real_time_refresh": true,
"title_case": false,
"type": "str",
"_input_type": "DropdownInput"
},
"code": {
"type": "code",
"required": true,
"placeholder": "",
"list": false,
"show": true,
"multiline": true,
"value": "from langchain_core.tools import StructuredTool\n\nfrom langflow.base.agents.agent import LCToolsAgentComponent\nfrom langflow.base.models.model_input_constants import ALL_PROVIDER_FIELDS, MODEL_PROVIDERS_DICT\nfrom langflow.base.models.model_utils import get_model_name\nfrom langflow.components.helpers import CurrentDateComponent\nfrom langflow.components.helpers.memory import MemoryComponent\nfrom langflow.components.langchain_utilities.tool_calling import ToolCallingAgentComponent\nfrom langflow.io import BoolInput, DropdownInput, MultilineInput, Output\nfrom langflow.schema.dotdict import dotdict\nfrom langflow.schema.message import Message\n\n\ndef set_advanced_true(component_input):\n component_input.advanced = True\n return component_input\n\n\nclass AgentComponent(ToolCallingAgentComponent):\n display_name: str = \"Agent\"\n description: str = \"Define the agent's instructions, then enter a task to complete using tools.\"\n icon = \"bot\"\n beta = False\n name = \"Agent\"\n\n memory_inputs = [set_advanced_true(component_input) for component_input in MemoryComponent().inputs]\n\n inputs = [\n DropdownInput(\n name=\"agent_llm\",\n display_name=\"Model Provider\",\n info=\"The provider of the language model that the agent will use to generate responses.\",\n options=[*sorted(MODEL_PROVIDERS_DICT.keys()), \"Custom\"],\n value=\"OpenAI\",\n real_time_refresh=True,\n input_types=[],\n ),\n *MODEL_PROVIDERS_DICT[\"OpenAI\"][\"inputs\"],\n MultilineInput(\n name=\"system_prompt\",\n display_name=\"Agent Instructions\",\n info=\"System Prompt: Initial instructions and context provided to guide the agent's behavior.\",\n value=\"You are a helpful assistant that can use tools to answer questions and perform tasks.\",\n advanced=False,\n ),\n *LCToolsAgentComponent._base_inputs,\n *memory_inputs,\n BoolInput(\n name=\"add_current_date_tool\",\n display_name=\"Add tool Current Date\",\n advanced=True,\n info=\"If true, will add a tool to the agent that returns the current date.\",\n value=True,\n ),\n ]\n outputs = [Output(name=\"response\", display_name=\"Response\", method=\"message_response\")]\n\n async def message_response(self) -> Message:\n llm_model, display_name = self.get_llm()\n self.model_name = get_model_name(llm_model, display_name=display_name)\n if llm_model is None:\n msg = \"No language model selected\"\n raise ValueError(msg)\n self.chat_history = self.get_memory_data()\n\n if self.add_current_date_tool:\n if not isinstance(self.tools, list): # type: ignore[has-type]\n self.tools = []\n # Convert CurrentDateComponent to a StructuredTool\n current_date_tool = CurrentDateComponent().to_toolkit()[0]\n if isinstance(current_date_tool, StructuredTool):\n self.tools.append(current_date_tool)\n else:\n msg = \"CurrentDateComponent must be converted to a StructuredTool\"\n raise ValueError(msg)\n\n if not self.tools:\n msg = \"Tools are required to run the agent.\"\n raise ValueError(msg)\n self.set(\n llm=llm_model,\n tools=self.tools,\n chat_history=self.chat_history,\n input_value=self.input_value,\n system_prompt=self.system_prompt,\n )\n agent = self.create_agent_runnable()\n return await self.run_agent(agent)\n\n def get_memory_data(self):\n memory_kwargs = {\n component_input.name: getattr(self, f\"{component_input.name}\") for component_input in self.memory_inputs\n }\n\n return MemoryComponent().set(**memory_kwargs).retrieve_messages()\n\n def get_llm(self):\n if isinstance(self.agent_llm, str):\n try:\n provider_info = MODEL_PROVIDERS_DICT.get(self.agent_llm)\n if provider_info:\n component_class = provider_info.get(\"component_class\")\n display_name = component_class.display_name\n inputs = provider_info.get(\"inputs\")\n prefix = provider_info.get(\"prefix\", \"\")\n return self._build_llm_model(component_class, inputs, prefix), display_name\n except Exception as e:\n msg = f\"Error building {self.agent_llm} language model\"\n raise ValueError(msg) from e\n return self.agent_llm, None\n\n def _build_llm_model(self, component, inputs, prefix=\"\"):\n model_kwargs = {input_.name: getattr(self, f\"{prefix}{input_.name}\") for input_ in inputs}\n return component.set(**model_kwargs).build_model()\n\n def delete_fields(self, build_config: dotdict, fields: dict | list[str]) -> None:\n \"\"\"Delete specified fields from build_config.\"\"\"\n for field in fields:\n build_config.pop(field, None)\n\n def update_input_types(self, build_config: dotdict) -> dotdict:\n \"\"\"Update input types for all fields in build_config.\"\"\"\n for key, value in build_config.items():\n if isinstance(value, dict):\n if value.get(\"input_types\") is None:\n build_config[key][\"input_types\"] = []\n elif hasattr(value, \"input_types\") and value.input_types is None:\n value.input_types = []\n return build_config\n\n def update_build_config(self, build_config: dotdict, field_value: str, field_name: str | None = None) -> dotdict:\n # Iterate over all providers in the MODEL_PROVIDERS_DICT\n # Existing logic for updating build_config\n if field_name == \"agent_llm\":\n provider_info = MODEL_PROVIDERS_DICT.get(field_value)\n if provider_info:\n component_class = provider_info.get(\"component_class\")\n if component_class and hasattr(component_class, \"update_build_config\"):\n # Call the component class's update_build_config method\n build_config = component_class.update_build_config(build_config, field_value, field_name)\n\n provider_configs: dict[str, tuple[dict, list[dict]]] = {\n provider: (\n MODEL_PROVIDERS_DICT[provider][\"fields\"],\n [\n MODEL_PROVIDERS_DICT[other_provider][\"fields\"]\n for other_provider in MODEL_PROVIDERS_DICT\n if other_provider != provider\n ],\n )\n for provider in MODEL_PROVIDERS_DICT\n }\n if field_value in provider_configs:\n fields_to_add, fields_to_delete = provider_configs[field_value]\n\n # Delete fields from other providers\n for fields in fields_to_delete:\n self.delete_fields(build_config, fields)\n\n # Add provider-specific fields\n if field_value == \"OpenAI\" and not any(field in build_config for field in fields_to_add):\n build_config.update(fields_to_add)\n else:\n build_config.update(fields_to_add)\n # Reset input types for agent_llm\n build_config[\"agent_llm\"][\"input_types\"] = []\n elif field_value == \"Custom\":\n # Delete all provider fields\n self.delete_fields(build_config, ALL_PROVIDER_FIELDS)\n # Update with custom component\n custom_component = DropdownInput(\n name=\"agent_llm\",\n display_name=\"Language Model\",\n options=[*sorted(MODEL_PROVIDERS_DICT.keys()), \"Custom\"],\n value=\"Custom\",\n real_time_refresh=True,\n input_types=[\"LanguageModel\"],\n )\n build_config.update({\"agent_llm\": custom_component.to_dict()})\n # Update input types for all fields\n build_config = self.update_input_types(build_config)\n\n # Validate required keys\n default_keys = [\n \"code\",\n \"_type\",\n \"agent_llm\",\n \"tools\",\n \"input_value\",\n \"add_current_date_tool\",\n \"system_prompt\",\n \"agent_description\",\n \"max_iterations\",\n \"handle_parsing_errors\",\n \"verbose\",\n ]\n missing_keys = [key for key in default_keys if key not in build_config]\n if missing_keys:\n msg = f\"Missing required keys in build_config: {missing_keys}\"\n raise ValueError(msg)\n if isinstance(self.agent_llm, str) and self.agent_llm in MODEL_PROVIDERS_DICT:\n provider_info = MODEL_PROVIDERS_DICT.get(self.agent_llm)\n if provider_info:\n component_class = provider_info.get(\"component_class\")\n prefix = provider_info.get(\"prefix\")\n if component_class and hasattr(component_class, \"update_build_config\"):\n # Call each component class's update_build_config method\n # remove the prefix from the field_name\n if isinstance(field_name, str) and isinstance(prefix, str):\n field_name = field_name.replace(prefix, \"\")\n build_config = component_class.update_build_config(build_config, field_value, field_name)\n\n return build_config\n",
"fileTypes": [],
"file_path": "",
"password": false,
"name": "code",
"advanced": true,
"dynamic": true,
"info": "",
"load_from_db": false,
"title_case": false,
"input_types": []
},
"handle_parsing_errors": {
"trace_as_metadata": true,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "handle_parsing_errors",
"value": true,
"display_name": "Handle Parse Errors",
"advanced": true,
"dynamic": false,
"info": "Should the Agent fix errors when reading user input for better processing?",
"title_case": false,
"type": "bool",
"_input_type": "BoolInput",
"input_types": []
},
"input_value": {
"tool_mode": true,
"trace_as_input": true,
"trace_as_metadata": true,
"load_from_db": false,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "input_value",
"value": "",
"display_name": "Input",
"advanced": false,
"input_types": [
"Message"
],
"dynamic": false,
"info": "The input provided by the user for the agent to process.",
"title_case": false,
"type": "str",
"_input_type": "MessageTextInput"
},
"max_iterations": {
"trace_as_metadata": true,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "max_iterations",
"value": 15,
"display_name": "Max Iterations",
"advanced": true,
"dynamic": false,
"info": "The maximum number of attempts the agent can make to complete its task before it stops.",
"title_case": false,
"type": "int",
"_input_type": "IntInput",
"input_types": []
},
"n_messages": {
"trace_as_metadata": true,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "n_messages",
"value": 100,
"display_name": "Number of Messages",
"advanced": true,
"dynamic": false,
"info": "Number of messages to retrieve.",
"title_case": false,
"type": "int",
"_input_type": "IntInput",
"input_types": []
},
"order": {
"tool_mode": false,
"trace_as_metadata": true,
"options": [
"Ascending",
"Descending"
],
"combobox": false,
"required": false,
"placeholder": "",
"show": true,
"name": "order",
"value": "Ascending",
"display_name": "Order",
"advanced": true,
"dynamic": false,
"info": "Order of the messages.",
"title_case": false,
"type": "str",
"_input_type": "DropdownInput",
"input_types": []
},
"sender": {
"tool_mode": false,
"trace_as_metadata": true,
"options": [
"Machine",
"User",
"Machine and User"
],
"combobox": false,
"required": false,
"placeholder": "",
"show": true,
"name": "sender",
"value": "Machine and User",
"display_name": "Sender Type",
"advanced": true,
"dynamic": false,
"info": "Filter by sender type.",
"title_case": false,
"type": "str",
"_input_type": "DropdownInput",
"input_types": []
},
"sender_name": {
"tool_mode": false,
"trace_as_input": true,
"trace_as_metadata": true,
"load_from_db": false,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "sender_name",
"value": "",
"display_name": "Sender Name",
"advanced": true,
"input_types": [
"Message"
],
"dynamic": false,
"info": "Filter by sender name.",
"title_case": false,
"type": "str",
"_input_type": "MessageTextInput"
},
"session_id": {
"tool_mode": false,
"trace_as_input": true,
"trace_as_metadata": true,
"load_from_db": false,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "session_id",
"value": "",
"display_name": "Session ID",
"advanced": true,
"input_types": [
"Message"
],
"dynamic": false,
"info": "The session ID of the chat. If empty, the current session ID parameter will be used.",
"title_case": false,
"type": "str",
"_input_type": "MessageTextInput"
},
"system_prompt": {
"tool_mode": false,
"trace_as_input": true,
"multiline": true,
"trace_as_metadata": true,
"load_from_db": false,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "system_prompt",
"value": "you are a helpful bot that helps user by\n\nRetrieving the all data from **Astra DB**.\n\nOnce the data is fetched, then using calculator tool count average engagement for each post type separately\n\nexample output (format) -\nCarousel - Likes = 45, Shares = 34, Comments = 21\nReel - Likes = 51, Shares = 37, Comments = 24\nStaticImage - Likes = 23, Shares = 47, Comments = 23\n\nSimilar to provided example format please calculate the engagement for each post type and return to user, use proper input format for calculator\nDo proper calculations, no data is exactly same\nyou must provide the details for each post type\nDon't provide me summarized data, share just collected averaged data in proper format\n",
"display_name": "Agent Instructions",
"advanced": false,
"input_types": [
"Message"
],
"dynamic": false,
"info": "System Prompt: Initial instructions and context provided to guide the agent's behavior.",
"title_case": false,
"type": "str",
"_input_type": "MultilineInput"
},
"template": {
"tool_mode": false,
"trace_as_input": true,
"multiline": true,
"trace_as_metadata": true,
"load_from_db": false,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "template",
"value": "{sender_name}: {text}",
"display_name": "Template",
"advanced": true,
"input_types": [
"Message"
],
"dynamic": false,
"info": "The template to use for formatting the data. It can contain the keys {text}, {sender} or any other key in the message data.",
"title_case": false,
"type": "str",
"_input_type": "MultilineInput"
},
"verbose": {
"trace_as_metadata": true,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "verbose",
"value": true,
"display_name": "Verbose",
"advanced": true,
"dynamic": false,
"info": "",
"title_case": false,
"type": "bool",
"_input_type": "BoolInput",
"input_types": []
},
"groq_api_key": {
"load_from_db": false,
"required": false,
"placeholder": "",
"show": true,
"name": "groq_api_key",
"value": "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",
"display_name": "Groq API Key",
"advanced": false,
"input_types": [
"Message"
],
"dynamic": false,
"info": "API key for the Groq API.",
"real_time_refresh": null,
"refresh_button": null,
"refresh_button_text": null,
"title_case": false,
"password": true,
"type": "str",
"_input_type": "SecretStrInput"
},
"groq_api_base": {
"tool_mode": false,
"trace_as_input": true,
"trace_as_metadata": true,
"load_from_db": false,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "groq_api_base",
"value": "https://api.groq.com",
"display_name": "Groq API Base",
"advanced": true,
"input_types": [
"Message"
],
"dynamic": false,
"info": "Base URL path for API requests, leave blank if not using a proxy or service emulator.",
"real_time_refresh": null,
"refresh_button": null,
"refresh_button_text": null,
"title_case": false,
"type": "str",
"_input_type": "MessageTextInput"
},
"max_tokens": {
"trace_as_metadata": true,
"range_spec": null,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "max_tokens",
"value": "",
"display_name": "Max Output Tokens",
"advanced": true,
"input_types": [],
"dynamic": false,
"info": "The maximum number of tokens to generate.",
"real_time_refresh": null,
"refresh_button": null,
"refresh_button_text": null,
"title_case": false,
"type": "int",
"_input_type": "IntInput"
},
"temperature": {
"trace_as_metadata": true,
"range_spec": null,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "temperature",
"value": 0.1,
"display_name": "Temperature",
"advanced": true,
"input_types": [],
"dynamic": false,
"info": "Run inference with this temperature. Must by in the closed interval [0.0, 1.0].",
"real_time_refresh": null,
"refresh_button": null,
"refresh_button_text": null,
"title_case": false,
"type": "float",
"_input_type": "FloatInput"
},
"n": {
"trace_as_metadata": true,
"range_spec": null,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "n",
"value": "",
"display_name": "N",
"advanced": true,
"input_types": [],
"dynamic": false,
"info": "Number of chat completions to generate for each prompt. Note that the API may not return the full n completions if duplicates are generated.",
"real_time_refresh": null,
"refresh_button": null,
"refresh_button_text": null,
"title_case": false,
"type": "int",
"_input_type": "IntInput"
},
"model_name": {
"tool_mode": false,
"trace_as_metadata": true,
"options": [
"llama3-70b-8192",
"llama-3.2-11b-vision-preview",
"llama-3.3-70b-specdec",
"llama-3.3-70b-versatile",
"llama-3.1-8b-instant",
"distil-whisper-large-v3-en",
"whisper-large-v3",
"llama-3.1-70b-versatile",
"whisper-large-v3-turbo",
"llama-guard-3-8b",
"llama-3.2-1b-preview",
"llama-3.2-3b-preview",
"llama3-8b-8192",
"mixtral-8x7b-32768",
"gemma2-9b-it",
"llama-3.2-90b-vision-preview"
],
"combobox": false,
"required": false,
"placeholder": "",
"show": true,
"name": "model_name",
"value": "llama-3.3-70b-specdec",
"display_name": "Model",
"advanced": false,
"input_types": [],
"dynamic": false,
"info": "The name of the model to use.",
"real_time_refresh": null,
"refresh_button": true,
"refresh_button_text": null,
"title_case": false,
"type": "str",
"_input_type": "DropdownInput"
},
"output_parser": {
"trace_as_metadata": true,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "output_parser",
"value": "",
"display_name": "Output Parser",
"advanced": true,
"input_types": [
"OutputParser"
],
"dynamic": false,
"info": "The parser to use to parse the output of the model",
"real_time_refresh": null,
"refresh_button": null,
"refresh_button_text": null,
"title_case": false,
"type": "other",
"_input_type": "HandleInput"
}
},
"description": "Define the agent's instructions, then enter a task to complete using tools.",
"icon": "bot",
"base_classes": [
"Message"
],
"display_name": "Agent",
"documentation": "",
"custom_fields": {},
"output_types": [],
"pinned": false,
"conditional_paths": [],
"frozen": false,
"outputs": [
{
"types": [
"Message"
],
"selected": "Message",
"name": "response",
"hidden": null,
"display_name": "Response",
"method": "message_response",
"value": "__UNDEFINED__",
"cache": true,
"required_inputs": null
}
],
"field_order": [
"agent_llm",
"max_tokens",
"model_kwargs",
"json_mode",
"output_schema",
"model_name",
"openai_api_base",
"api_key",
"temperature",
"seed",
"output_parser",
"system_prompt",
"tools",
"input_value",
"handle_parsing_errors",
"verbose",
"max_iterations",
"agent_description",
"memory",
"sender",
"sender_name",
"n_messages",
"session_id",
"order",
"template",
"add_current_date_tool"
],
"beta": false,
"legacy": false,
"edited": false,
"metadata": {},
"tool_mode": false,
"lf_version": "1.1.1"
},
"type": "Agent",
"id": "Agent-EvgUv"
},
"selected": false,
"width": 320,
"height": 648,
"positionAbsolute": {
"x": 3000.9143035979964,
"y": 633.02787823479
},
"dragging": false
},
{
"id": "CalculatorTool-ezhXu",
"type": "genericNode",
"position": {
"x": 2180.4977167238308,
"y": 1150.5139544258136
},
"data": {
"node": {
"template": {
"_type": "Component",
"code": {
"type": "code",
"required": true,
"placeholder": "",
"list": false,
"show": true,
"multiline": true,
"value": "import ast\nimport operator\n\nfrom langchain.tools import StructuredTool\nfrom langchain_core.tools import ToolException\nfrom loguru import logger\nfrom pydantic import BaseModel, Field\n\nfrom langflow.base.langchain_utilities.model import LCToolComponent\nfrom langflow.field_typing import Tool\nfrom langflow.inputs import MessageTextInput\nfrom langflow.schema import Data\n\n\nclass CalculatorToolComponent(LCToolComponent):\n display_name = \"Calculator\"\n description = \"Perform basic arithmetic operations on a given expression.\"\n icon = \"calculator\"\n name = \"CalculatorTool\"\n\n inputs = [\n MessageTextInput(\n name=\"expression\",\n display_name=\"Expression\",\n info=\"The arithmetic expression to evaluate (e.g., '4*4*(33/22)+12-20').\",\n ),\n ]\n\n class CalculatorToolSchema(BaseModel):\n expression: str = Field(..., description=\"The arithmetic expression to evaluate.\")\n\n def run_model(self) -> list[Data]:\n return self._evaluate_expression(self.expression)\n\n def build_tool(self) -> Tool:\n return StructuredTool.from_function(\n name=\"calculator\",\n description=\"Evaluate basic arithmetic expressions. Input should be a string containing the expression.\",\n func=self._eval_expr_with_error,\n args_schema=self.CalculatorToolSchema,\n )\n\n def _eval_expr(self, node):\n # Define the allowed operators\n operators = {\n ast.Add: operator.add,\n ast.Sub: operator.sub,\n ast.Mult: operator.mul,\n ast.Div: operator.truediv,\n ast.Pow: operator.pow,\n }\n if isinstance(node, ast.Num):\n return node.n\n if isinstance(node, ast.BinOp):\n return operators[type(node.op)](self._eval_expr(node.left), self._eval_expr(node.right))\n if isinstance(node, ast.UnaryOp):\n return operators[type(node.op)](self._eval_expr(node.operand))\n if isinstance(node, ast.Call):\n msg = (\n \"Function calls like sqrt(), sin(), cos() etc. are not supported. \"\n \"Only basic arithmetic operations (+, -, *, /, **) are allowed.\"\n )\n raise TypeError(msg)\n msg = f\"Unsupported operation or expression type: {type(node).__name__}\"\n raise TypeError(msg)\n\n def _eval_expr_with_error(self, expression: str) -> list[Data]:\n try:\n return self._evaluate_expression(expression)\n except Exception as e:\n raise ToolException(str(e)) from e\n\n def _evaluate_expression(self, expression: str) -> list[Data]:\n try:\n # Parse the expression and evaluate it\n tree = ast.parse(expression, mode=\"eval\")\n result = self._eval_expr(tree.body)\n\n # Format the result to a reasonable number of decimal places\n formatted_result = f\"{result:.6f}\".rstrip(\"0\").rstrip(\".\")\n\n self.status = formatted_result\n return [Data(data={\"result\": formatted_result})]\n\n except (SyntaxError, TypeError, KeyError) as e:\n error_message = f\"Invalid expression: {e}\"\n self.status = error_message\n return [Data(data={\"error\": error_message, \"input\": expression})]\n except ZeroDivisionError:\n error_message = \"Error: Division by zero\"\n self.status = error_message\n return [Data(data={\"error\": error_message, \"input\": expression})]\n except Exception as e: # noqa: BLE001\n logger.opt(exception=True).debug(\"Error evaluating expression\")\n error_message = f\"Error: {e}\"\n self.status = error_message\n return [Data(data={\"error\": error_message, \"input\": expression})]\n",
"fileTypes": [],
"file_path": "",
"password": false,
"name": "code",
"advanced": true,
"dynamic": true,
"info": "",
"load_from_db": false,
"title_case": false
},
"expression": {
"tool_mode": false,
"trace_as_input": true,
"trace_as_metadata": true,
"load_from_db": false,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "expression",
"value": "",
"display_name": "Expression",
"advanced": false,
"input_types": [
"Message"
],
"dynamic": false,
"info": "The arithmetic expression to evaluate (e.g., '4*4*(33/22)+12-20').",
"title_case": false,
"type": "str",
"_input_type": "MessageTextInput"
}
},
"description": "Perform basic arithmetic operations on a given expression.",
"icon": "calculator",
"base_classes": [
"Data",
"Tool"
],
"display_name": "Calculator",
"documentation": "",
"custom_fields": {},
"output_types": [],
"pinned": false,
"conditional_paths": [],
"frozen": false,
"outputs": [
{
"types": [
"Data"
],
"selected": "Data",
"name": "api_run_model",
"display_name": "Data",
"method": "run_model",
"value": "__UNDEFINED__",
"cache": true,
"required_inputs": []
},
{
"types": [
"Tool"
],
"selected": "Tool",
"name": "api_build_tool",
"display_name": "Tool",
"method": "build_tool",
"value": "__UNDEFINED__",
"cache": true,
"required_inputs": []
}
],