File size: 82,569 Bytes
226ac39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d92d2aa
226ac39
 
 
 
d92d2aa
226ac39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
"""
Complete Tools Registry for Groq Function Calling - All 67 Tools
Defines all available tools in Groq's function calling format.
"""

TOOLS = [
    # ============================================
    # BASIC TOOLS (16)
    # ============================================
    
    # Data Profiling Tools (3)
    {
        "type": "function",
        "function": {
            "name": "profile_dataset",
            "description": "Get comprehensive statistics about a dataset including shape, data types, memory usage, null counts, and unique values. Use this as the first step to understand any new dataset.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {
                        "type": "string",
                        "description": "Absolute or relative path to the CSV or Parquet file"
                    }
                },
                "required": ["file_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "detect_data_quality_issues",
            "description": "Detect data quality issues including outliers (using IQR method), duplicate rows, inconsistent formats, and data anomalies. Returns a prioritized list of issues with severity levels.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {
                        "type": "string",
                        "description": "Path to the dataset file"
                    }
                },
                "required": ["file_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "analyze_correlations",
            "description": "Compute correlation matrix and identify top correlations. If a target column is specified, shows features most correlated with the target. Useful for feature selection and understanding relationships.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {
                        "type": "string",
                        "description": "Path to the dataset file"
                    },
                    "target": {
                        "type": "string",
                        "description": "Optional target column name to analyze correlations with"
                    }
                },
                "required": ["file_path"]
            }
        }
    },
    
    # Data Cleaning Tools (3)
    {
        "type": "function",
        "function": {
            "name": "clean_missing_values",
            "description": "Handle missing values using appropriate strategies based on column type. Strategies include median/mean for numeric, mode for categorical, forward_fill for time series, or drop. In 'auto' mode, first drops columns with >threshold missing (default 40%), then imputes remaining columns. Will not impute ID columns.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {
                        "type": "string",
                        "description": "Path to the dataset file"
                    },
                    "strategy": {
                        "oneOf": [
                            {
                                "type": "string",
                                "enum": ["auto"],
                                "description": "Use 'auto' to automatically decide strategies for all columns based on data type. First drops columns with >threshold missing, then imputes remaining columns."
                            },
                            {
                                "type": "object",
                                "description": "Dictionary mapping column names to strategies ('median', 'mean', 'mode', 'forward_fill', 'drop')",
                                "additionalProperties": {"type": "string"}
                            }
                        ],
                        "description": "Either 'auto' (string) to automatically handle all missing values, or a dictionary mapping specific columns to strategies"
                    },
                    "output_path": {
                        "type": "string",
                        "description": "Path to save cleaned dataset"
                    },
                    "threshold": {
                        "type": "number",
                        "description": "For 'auto' mode: drop columns with missing percentage above this threshold (default: 0.4 = 40%). Range: 0.0 to 1.0. For example, 0.7 means drop columns with >70% missing values."
                    }
                },
                "required": ["file_path", "strategy", "output_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "handle_outliers",
            "description": "Detect and handle outliers in numeric columns using IQR method. Methods: 'clip' (cap at boundaries), 'winsorize' (cap at percentiles), or 'remove' (delete rows).",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {
                        "type": "string",
                        "description": "Path to the dataset file"
                    },
                    "method": {
                        "type": "string",
                        "enum": ["clip", "winsorize", "remove"],
                        "description": "Method to handle outliers"
                    },
                    "columns": {
                        "type": "array",
                        "items": {"type": "string"},
                        "description": "List of column names to check for outliers. Use 'all' to check all numeric columns."
                    },
                    "output_path": {
                        "type": "string",
                        "description": "Path to save cleaned dataset"
                    }
                },
                "required": ["file_path", "method", "columns", "output_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "fix_data_types",
            "description": "Auto-detect and fix incorrect data types. Handles dates, booleans, categoricals, and numeric columns. Fixes common issues like 'null' strings and mixed types.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {
                        "type": "string",
                        "description": "Path to the dataset file"
                    },
                    "type_mapping": {
                        "type": "object",
                        "description": "Optional dictionary mapping column names to target types ('int', 'float', 'string', 'date', 'bool', 'category'). Use 'auto' for automatic detection.",
                        "additionalProperties": {"type": "string"}
                    },
                    "output_path": {
                        "type": "string",
                        "description": "Path to save dataset with fixed types"
                    }
                },
                "required": ["file_path", "output_path"]
            }
        }
    },
    
    # Data Type Conversion Tools (2)
    {
        "type": "function",
        "function": {
            "name": "force_numeric_conversion",
            "description": "CRITICAL TOOL: Force convert columns to numeric type even if detected as strings/objects. Essential for datasets with numeric columns stored as strings (with commas, spaces, currency symbols). Use this BEFORE encoding when you see 'no numeric features' errors.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {
                        "type": "string",
                        "description": "Path to the dataset file"
                    },
                    "columns": {
                        "type": "array",
                        "items": {"type": "string"},
                        "description": "List of column names to force convert to numeric. Use ['all'] to auto-detect and convert all non-ID columns that look numeric."
                    },
                    "output_path": {
                        "type": "string",
                        "description": "Path to save dataset with converted types"
                    },
                    "errors": {
                        "type": "string",
                        "enum": ["coerce", "raise"],
                        "description": "How to handle conversion errors. 'coerce' makes invalid values null (recommended), 'raise' throws error."
                    }
                },
                "required": ["file_path", "columns", "output_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "smart_type_inference",
            "description": "Intelligently infer and fix data types for all columns by analyzing patterns. Goes beyond basic type detection to understand semantic meaning. Use when dataset has widespread type issues.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {
                        "type": "string",
                        "description": "Path to the dataset file"
                    },
                    "output_path": {
                        "type": "string",
                        "description": "Path to save dataset with inferred types"
                    },
                    "aggressive": {
                        "type": "boolean",
                        "description": "If true, attempts aggressive conversion on ambiguous columns. Recommended for messy datasets."
                    }
                },
                "required": ["file_path", "output_path"]
            }
        }
    },
    
    # Feature Engineering Tools (2)
    {
        "type": "function",
        "function": {
            "name": "create_time_features",
            "description": "Extract comprehensive time-based features from datetime columns including year, month, day, day_of_week, quarter, is_weekend, and cyclical encodings (sin/cos for month and hour).",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {
                        "type": "string",
                        "description": "Path to the dataset file"
                    },
                    "date_col": {
                        "type": "string",
                        "description": "Name of the datetime column to extract features from"
                    },
                    "output_path": {
                        "type": "string",
                        "description": "Path to save dataset with new features"
                    }
                },
                "required": ["file_path", "date_col", "output_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "encode_categorical",
            "description": "Encode categorical variables using one-hot encoding, target encoding, or frequency encoding. Handles high-cardinality columns intelligently. Use method='auto' to automatically choose the best encoding.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {
                        "type": "string",
                        "description": "Path to the dataset file"
                    },
                    "method": {
                        "type": "string",
                        "enum": ["one_hot", "target", "frequency", "auto"],
                        "description": "Encoding method to use. 'auto' automatically selects the best method."
                    },
                    "columns": {
                        "type": "array",
                        "items": {"type": "string"},
                        "description": "List of categorical columns to encode. Use ['all'] to encode all categorical columns. If not specified, defaults to all categorical columns."
                    },
                    "target_col": {
                        "type": "string",
                        "description": "Required for target encoding: name of the target column"
                    },
                    "output_path": {
                        "type": "string",
                        "description": "Path to save dataset with encoded features"
                    }
                },
                "required": ["file_path", "output_path"]
            }
        }
    },
    
    # Model Training Tools (2)
    {
        "type": "function",
        "function": {
            "name": "train_baseline_models",
            "description": "Train multiple baseline models (Logistic Regression, Random Forest, XGBoost) and compare their performance. Automatically detects task type (classification/regression) and returns the best model with metrics.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {
                        "type": "string",
                        "description": "Path to the prepared dataset file"
                    },
                    "target_col": {
                        "type": "string",
                        "description": "Name of the target column to predict"
                    },
                    "task_type": {
                        "type": "string",
                        "enum": ["classification", "regression", "auto"],
                        "description": "Type of ML task. Use 'auto' to detect automatically."
                    },
                    "test_size": {
                        "type": "number",
                        "description": "Proportion of data to use for testing (default: 0.2)"
                    },
                    "random_state": {
                        "type": "integer",
                        "description": "Random seed for reproducibility (default: 42)"
                    }
                },
                "required": ["file_path", "target_col"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "generate_model_report",
            "description": "Generate comprehensive model evaluation report including metrics, confusion matrix (for classification), feature importance, and SHAP values for top features. Saves report as JSON.",
            "parameters": {
                "type": "object",
                "properties": {
                    "model_path": {
                        "type": "string",
                        "description": "Path to saved model file (.pkl or .joblib)"
                    },
                    "test_data_path": {
                        "type": "string",
                        "description": "Path to test dataset file"
                    },
                    "target_col": {
                        "type": "string",
                        "description": "Name of the target column"
                    },
                    "output_path": {
                        "type": "string",
                        "description": "Path to save the report JSON file"
                    }
                },
                "required": ["model_path", "test_data_path", "target_col", "output_path"]
            }
        }
    },
    
    # New Data Wrangling Tools (3)
    {
        "type": "function",
        "function": {
            "name": "get_smart_summary",
            "description": "Generate an LLM-friendly smart summary of a dataset with per-column missing value percentages (sorted by severity), unique value counts, sample data, and numeric statistics. Much more detailed than profile_dataset for decision-making.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {
                        "type": "string",
                        "description": "Path to the CSV or Parquet file to summarize"
                    },
                    "n_samples": {
                        "type": "integer",
                        "description": "Number of sample rows to include in the summary (default: 5)"
                    }
                },
                "required": ["file_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "merge_datasets",
            "description": "Merge two datasets using SQL-like join operations (inner, left, right, outer, cross). Supports joining on single or multiple columns with same or different names. Automatically handles duplicate columns with suffixes.",
            "parameters": {
                "type": "object",
                "properties": {
                    "left_path": {
                        "type": "string",
                        "description": "Path to the left (first) dataset file"
                    },
                    "right_path": {
                        "type": "string",
                        "description": "Path to the right (second) dataset file"
                    },
                    "output_path": {
                        "type": "string",
                        "description": "Path to save the merged dataset"
                    },
                    "how": {
                        "type": "string",
                        "enum": ["inner", "left", "right", "outer", "cross"],
                        "description": "Join type: 'inner' (only matching rows), 'left' (all left + matching right), 'right' (all right + matching left), 'outer' (all rows from both), 'cross' (cartesian product)"
                    },
                    "on": {
                        "type": ["string", "array"],
                        "items": {"type": "string"},
                        "description": "Column name(s) to join on (must exist in both datasets). Can be a single column name or list of columns. Use this when join columns have the same name in both datasets."
                    },
                    "left_on": {
                        "type": ["string", "array"],
                        "items": {"type": "string"},
                        "description": "Column name(s) in left dataset to join on. Use with right_on when join columns have different names."
                    },
                    "right_on": {
                        "type": ["string", "array"],
                        "items": {"type": "string"},
                        "description": "Column name(s) in right dataset to join on. Use with left_on when join columns have different names."
                    }
                },
                "required": ["left_path", "right_path", "output_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "concat_datasets",
            "description": "Concatenate multiple datasets either vertically (stacking rows, useful for monthly data) or horizontally (adding columns side-by-side). Validates schema compatibility for vertical concat.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_paths": {
                        "type": "array",
                        "items": {"type": "string"},
                        "description": "List of paths to dataset files to concatenate (minimum 2 files)"
                    },
                    "output_path": {
                        "type": "string",
                        "description": "Path to save the concatenated dataset"
                    },
                    "axis": {
                        "type": "string",
                        "enum": ["vertical", "horizontal"],
                        "description": "'vertical' to stack rows (union, for monthly data), 'horizontal' to add columns side-by-side (default: 'vertical')"
                    }
                },
                "required": ["file_paths", "output_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "reshape_dataset",
            "description": "Transform dataset structure using pivot (long→wide format), melt (wide→long format), or transpose (swap rows and columns) operations.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {
                        "type": "string",
                        "description": "Path to the dataset file to reshape"
                    },
                    "output_path": {
                        "type": "string",
                        "description": "Path to save the reshaped dataset"
                    },
                    "operation": {
                        "type": "string",
                        "enum": ["pivot", "melt", "transpose"],
                        "description": "Reshape operation: 'pivot' (long→wide, requires index/columns/values), 'melt' (wide→long, requires id_vars/value_vars), 'transpose' (swap rows/columns)"
                    },
                    "index": {
                        "type": "string",
                        "description": "Column to use as row index (for pivot operation)"
                    },
                    "columns": {
                        "type": "string",
                        "description": "Column whose values become new column names (for pivot operation)"
                    },
                    "values": {
                        "type": "string",
                        "description": "Column whose values populate the pivoted table (for pivot operation)"
                    },
                    "id_vars": {
                        "type": "array",
                        "items": {"type": "string"},
                        "description": "Columns to keep as identifiers (for melt operation)"
                    },
                    "value_vars": {
                        "type": "array",
                        "items": {"type": "string"},
                        "description": "Columns to unpivot (for melt operation). If not specified, uses all columns except id_vars."
                    }
                },
                "required": ["file_path", "output_path", "operation"]
            }
        }
    },
    
    # ============================================
    # ADVANCED ANALYSIS TOOLS (5)
    # ============================================
    {
        "type": "function",
        "function": {
            "name": "perform_eda_analysis",
            "description": "Comprehensive Exploratory Data Analysis with visualizations, distribution analysis, and automated insights. Generates HTML report with plots.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "target_col": {"type": "string", "description": "Optional target column for supervised analysis"},
                    "output_dir": {"type": "string", "description": "Directory to save EDA report and plots"}
                },
                "required": ["file_path", "output_dir"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "detect_model_issues",
            "description": "Detect overfitting, underfitting, class imbalance, and other model performance issues. Provides diagnostic recommendations.",
            "parameters": {
                "type": "object",
                "properties": {
                    "model_path": {"type": "string", "description": "Path to trained model"},
                    "train_data_path": {"type": "string", "description": "Path to training data"},
                    "test_data_path": {"type": "string", "description": "Path to test data"},
                    "target_col": {"type": "string", "description": "Target column name"}
                },
                "required": ["model_path", "train_data_path", "test_data_path", "target_col"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "detect_anomalies",
            "description": "Detect anomalies using Isolation Forest, LOF, or statistical methods. Returns anomaly scores and flags.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "method": {"type": "string", "enum": ["isolation_forest", "lof", "statistical"], "description": "Anomaly detection method"},
                    "contamination": {"type": "number", "description": "Expected proportion of anomalies (default: 0.1)"},
                    "output_path": {"type": "string", "description": "Path to save dataset with anomaly scores"}
                },
                "required": ["file_path", "method", "output_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "detect_and_handle_multicollinearity",
            "description": "Detect and handle multicollinearity using VIF (Variance Inflation Factor). Removes highly correlated features automatically.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "threshold": {"type": "number", "description": "VIF threshold (default: 10)"},
                    "method": {"type": "string", "enum": ["drop", "combine"], "description": "How to handle correlated features"},
                    "output_path": {"type": "string", "description": "Path to save cleaned dataset"}
                },
                "required": ["file_path", "output_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "perform_statistical_tests",
            "description": "Perform statistical hypothesis tests (t-test, chi-square, ANOVA) to analyze relationships between features and target.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "target_col": {"type": "string", "description": "Target column name"},
                    "test_type": {"type": "string", "enum": ["auto", "ttest", "chi2", "anova"], "description": "Type of statistical test"}
                },
                "required": ["file_path", "target_col"]
            }
        }
    },
    
    # ============================================
    # ADVANCED FEATURE ENGINEERING (4)
    # ============================================
    {
        "type": "function",
        "function": {
            "name": "create_interaction_features",
            "description": "Create polynomial, PCA, or cross-product interaction features to capture non-linear relationships.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "method": {"type": "string", "enum": ["polynomial", "pca", "cross"], "description": "Interaction method"},
                    "degree": {"type": "integer", "description": "Polynomial degree (default: 2)"},
                    "max_features": {"type": "integer", "description": "Maximum new features to create (default: 50)"},
                    "output_path": {"type": "string", "description": "Path to save enhanced dataset"}
                },
                "required": ["file_path", "method", "output_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "create_aggregation_features",
            "description": "Create aggregation features (mean, sum, count, etc.) grouped by categorical columns. Useful for customer/transaction data.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "group_cols": {"type": "array", "items": {"type": "string"}, "description": "Columns to group by"},
                    "agg_cols": {"type": "array", "items": {"type": "string"}, "description": "Columns to aggregate"},
                    "agg_functions": {"type": "array", "items": {"type": "string"}, "description": "Aggregation functions (mean, sum, count, etc.)"},
                    "output_path": {"type": "string", "description": "Path to save dataset with aggregations"}
                },
                "required": ["file_path", "group_cols", "agg_cols", "output_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "engineer_text_features",
            "description": "Extract features from text columns: TF-IDF, word counts, sentiment, readability scores, and embeddings.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "text_col": {"type": "string", "description": "Text column name"},
                    "methods": {"type": "array", "items": {"type": "string"}, "description": "Feature extraction methods (tfidf, count, sentiment, readability)"},
                    "max_features": {"type": "integer", "description": "Max TF-IDF features (default: 100)"},
                    "output_path": {"type": "string", "description": "Path to save dataset with text features"}
                },
                "required": ["file_path", "text_col", "methods", "output_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "auto_feature_engineering",
            "description": "Use LLM (Gemini/Groq) to automatically generate creative feature engineering ideas and implement them. Works without API key if environment variables are set.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "target_col": {"type": "string", "description": "Target column name"},
                    "groq_api_key": {"type": "string", "description": "Groq API key (optional - uses environment variable if not provided)"},
                    "max_suggestions": {"type": "integer", "description": "Maximum feature suggestions to generate (default: 10)"},
                    "implement_top_k": {"type": "integer", "description": "Number of top suggestions to implement (default: 5)"},
                    "output_path": {"type": "string", "description": "Path to save dataset with new features"}
                },
                "required": ["file_path", "target_col", "output_path"]
            }
        }
    },
    
    # ============================================
    # ADVANCED PREPROCESSING (3)
    # ============================================
    {
        "type": "function",
        "function": {
            "name": "handle_imbalanced_data",
            "description": "Handle class imbalance using SMOTE, ADASYN, or class weights. Critical for classification tasks.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "target_col": {"type": "string", "description": "Target column name"},
                    "method": {"type": "string", "enum": ["smote", "adasyn", "random_oversample", "random_undersample"], "description": "Balancing method"},
                    "sampling_strategy": {"type": "string", "description": "Sampling ratio (auto, minority, majority)"},
                    "output_path": {"type": "string", "description": "Path to save balanced dataset"}
                },
                "required": ["file_path", "target_col", "method", "output_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "perform_feature_scaling",
            "description": "Scale features using StandardScaler, MinMaxScaler, or RobustScaler. Essential for distance-based algorithms.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "method": {"type": "string", "enum": ["standard", "minmax", "robust"], "description": "Scaling method"},
                    "columns": {"type": "array", "items": {"type": "string"}, "description": "Columns to scale (None = all numeric)"},
                    "output_path": {"type": "string", "description": "Path to save scaled dataset"}
                },
                "required": ["file_path", "method", "output_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "split_data_strategically",
            "description": "Split data with stratification, time-based splitting, or group-based splitting for better validation.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "target_col": {"type": "string", "description": "Target column for stratification"},
                    "method": {"type": "string", "enum": ["stratified", "time_based", "group_based"], "description": "Split method"},
                    "test_size": {"type": "number", "description": "Test set proportion (default: 0.2)"},
                    "time_col": {"type": "string", "description": "Time column for time-based split"},
                    "group_col": {"type": "string", "description": "Group column for group-based split"}
                },
                "required": ["file_path", "method"]
            }
        }
    },
    
    # ============================================
    # ADVANCED TRAINING (3)
    # ============================================
    {
        "type": "function",
        "function": {
            "name": "hyperparameter_tuning",
            "description": "Optimize model hyperparameters using Optuna (Bayesian optimization). Finds best model configuration automatically.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to prepared dataset"},
                    "target_col": {"type": "string", "description": "Target column name"},
                    "model_type": {"type": "string", "enum": ["random_forest", "xgboost", "lightgbm"], "description": "Model to tune"},
                    "n_trials": {"type": "integer", "description": "Number of tuning trials (default: 100)"},
                    "task_type": {"type": "string", "enum": ["classification", "regression", "auto"], "description": "ML task type"},
                    "output_path": {"type": "string", "description": "Path to save tuned model"}
                },
                "required": ["file_path", "target_col", "model_type", "output_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "train_ensemble_models",
            "description": "Train ensemble models using stacking, voting, or blending. Combines multiple models for better performance.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to prepared dataset"},
                    "target_col": {"type": "string", "description": "Target column name"},
                    "ensemble_method": {"type": "string", "enum": ["stacking", "voting", "blending"], "description": "Ensemble technique"},
                    "base_models": {"type": "array", "items": {"type": "string"}, "description": "Base model types to ensemble"},
                    "task_type": {"type": "string", "enum": ["classification", "regression", "auto"], "description": "ML task type"},
                    "output_path": {"type": "string", "description": "Path to save ensemble model"}
                },
                "required": ["file_path", "target_col", "ensemble_method", "output_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "perform_cross_validation",
            "description": "Perform k-fold cross-validation to get robust model performance estimates. Returns mean and std of metrics.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "target_col": {"type": "string", "description": "Target column name"},
                    "model_type": {"type": "string", "description": "Model type (random_forest, xgboost, logistic, ridge)"},
                    "n_splits": {"type": "integer", "description": "Number of CV folds/splits (default: 5)"},
                    "task_type": {"type": "string", "enum": ["classification", "regression", "auto"], "description": "ML task type"},
                    "cv_strategy": {"type": "string", "enum": ["kfold", "stratified", "timeseries"], "description": "Cross-validation strategy (default: kfold)"},
                    "save_oof": {"type": "boolean", "description": "Whether to save out-of-fold predictions (default: false)"}
                },
                "required": ["file_path", "target_col", "model_type"]
            }
        }
    },
    
    # ============================================
    # BUSINESS INTELLIGENCE (4)
    # ============================================
    {
        "type": "function",
        "function": {
            "name": "perform_cohort_analysis",
            "description": "Analyze user cohorts over time (retention, revenue, engagement). Essential for SaaS and e-commerce businesses.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to transaction/event data"},
                    "user_col": {"type": "string", "description": "User ID column"},
                    "date_col": {"type": "string", "description": "Date/timestamp column"},
                    "metric_col": {"type": "string", "description": "Metric to analyze (revenue, events, etc.)"},
                    "cohort_period": {"type": "string", "enum": ["daily", "weekly", "monthly"], "description": "Cohort grouping period"},
                    "output_path": {"type": "string", "description": "Path to save cohort analysis results"}
                },
                "required": ["file_path", "user_col", "date_col", "metric_col", "output_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "perform_rfm_analysis",
            "description": "RFM (Recency, Frequency, Monetary) analysis for customer segmentation. Identifies best/worst customers.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to transaction data"},
                    "customer_col": {"type": "string", "description": "Customer ID column"},
                    "date_col": {"type": "string", "description": "Transaction date column"},
                    "amount_col": {"type": "string", "description": "Transaction amount column"},
                    "output_path": {"type": "string", "description": "Path to save RFM segments"}
                },
                "required": ["file_path", "customer_col", "date_col", "amount_col", "output_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "detect_causal_relationships",
            "description": "Detect potential causal relationships between features using Granger causality and correlation analysis.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "target_col": {"type": "string", "description": "Target/effect column"},
                    "feature_cols": {"type": "array", "items": {"type": "string"}, "description": "Potential cause columns"},
                    "method": {"type": "string", "enum": ["granger", "correlation"], "description": "Causality detection method"}
                },
                "required": ["file_path", "target_col"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "generate_business_insights",
            "description": "Generate automated business insights using descriptive statistics, trends, and anomaly detection. Creates executive summary.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to business data"},
                    "metric_cols": {"type": "array", "items": {"type": "string"}, "description": "Key business metrics to analyze"},
                    "date_col": {"type": "string", "description": "Date column for trend analysis"},
                    "output_path": {"type": "string", "description": "Path to save insights report"}
                },
                "required": ["file_path", "metric_cols", "output_path"]
            }
        }
    },
    
    # ============================================
    # COMPUTER VISION (3)
    # ============================================
    {
        "type": "function",
        "function": {
            "name": "extract_image_features",
            "description": "Extract features from images using pre-trained CNNs (ResNet, VGG). Converts images to feature vectors for ML.",
            "parameters": {
                "type": "object",
                "properties": {
                    "image_dir": {"type": "string", "description": "Directory containing images"},
                    "model": {"type": "string", "enum": ["resnet", "vgg", "mobilenet"], "description": "Pre-trained model to use"},
                    "output_path": {"type": "string", "description": "Path to save feature vectors CSV"}
                },
                "required": ["image_dir", "model", "output_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "perform_image_clustering",
            "description": "Cluster images based on visual similarity using K-means or DBSCAN on extracted features.",
            "parameters": {
                "type": "object",
                "properties": {
                    "image_dir": {"type": "string", "description": "Directory containing images"},
                    "n_clusters": {"type": "integer", "description": "Number of clusters (default: auto-detect)"},
                    "method": {"type": "string", "enum": ["kmeans", "dbscan"], "description": "Clustering method"},
                    "output_path": {"type": "string", "description": "Path to save clustering results"}
                },
                "required": ["image_dir", "method", "output_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "analyze_tabular_image_hybrid",
            "description": "Combine tabular data with image features for hybrid ML models. Useful for e-commerce/medical data.",
            "parameters": {
                "type": "object",
                "properties": {
                    "tabular_path": {"type": "string", "description": "Path to tabular data CSV"},
                    "image_dir": {"type": "string", "description": "Directory with images"},
                    "image_id_col": {"type": "string", "description": "Column linking tabular data to images"},
                    "output_path": {"type": "string", "description": "Path to save combined features"}
                },
                "required": ["tabular_path", "image_dir", "image_id_col", "output_path"]
            }
        }
    },
    
    # ============================================
    # NLP/TEXT ANALYTICS (4)
    # ============================================
    {
        "type": "function",
        "function": {
            "name": "perform_topic_modeling",
            "description": "Discover topics in text documents using LDA or NMF. Extract themes from customer reviews, articles, etc.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset with text"},
                    "text_col": {"type": "string", "description": "Text column name"},
                    "n_topics": {"type": "integer", "description": "Number of topics to extract (default: 5)"},
                    "method": {"type": "string", "enum": ["lda", "nmf"], "description": "Topic modeling method"},
                    "output_path": {"type": "string", "description": "Path to save topics and document-topic matrix"}
                },
                "required": ["file_path", "text_col", "method", "output_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "perform_named_entity_recognition",
            "description": "Extract named entities (person, organization, location) from text using NER models.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset with text"},
                    "text_col": {"type": "string", "description": "Text column name"},
                    "output_path": {"type": "string", "description": "Path to save dataset with extracted entities"}
                },
                "required": ["file_path", "text_col", "output_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "analyze_sentiment_advanced",
            "description": "Perform advanced sentiment analysis with aspect-based sentiment (what features customers like/dislike).",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset with text"},
                    "text_col": {"type": "string", "description": "Text column name"},
                    "aspects": {"type": "array", "items": {"type": "string"}, "description": "Aspects to analyze sentiment for (e.g., 'price', 'quality')"},
                    "output_path": {"type": "string", "description": "Path to save sentiment scores"}
                },
                "required": ["file_path", "text_col", "output_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "perform_text_similarity",
            "description": "Calculate text similarity using cosine similarity, Jaccard, or semantic embeddings. Find duplicate/similar documents.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset with text"},
                    "text_col": {"type": "string", "description": "Text column name"},
                    "method": {"type": "string", "enum": ["cosine", "jaccard", "semantic"], "description": "Similarity method"},
                    "threshold": {"type": "number", "description": "Similarity threshold (0-1)"},
                    "output_path": {"type": "string", "description": "Path to save similarity matrix"}
                },
                "required": ["file_path", "text_col", "method", "output_path"]
            }
        }
    },
    
    # ============================================
    # PRODUCTION/MLOPS (5)
    # ============================================
    {
        "type": "function",
        "function": {
            "name": "monitor_model_drift",
            "description": "Detect data drift and concept drift in production models. Compare training vs production data distributions.",
            "parameters": {
                "type": "object",
                "properties": {
                    "train_data_path": {"type": "string", "description": "Path to original training data"},
                    "production_data_path": {"type": "string", "description": "Path to recent production data"},
                    "features": {"type": "array", "items": {"type": "string"}, "description": "Features to monitor for drift"},
                    "output_path": {"type": "string", "description": "Path to save drift report"}
                },
                "required": ["train_data_path", "production_data_path", "output_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "explain_predictions",
            "description": "Explain model predictions using SHAP or LIME. Generate feature importance explanations for individual predictions.",
            "parameters": {
                "type": "object",
                "properties": {
                    "model_path": {"type": "string", "description": "Path to trained model"},
                    "data_path": {"type": "string", "description": "Path to data to explain"},
                    "method": {"type": "string", "enum": ["shap", "lime"], "description": "Explanation method"},
                    "n_samples": {"type": "integer", "description": "Number of samples to explain (default: 10)"},
                    "output_path": {"type": "string", "description": "Path to save explanations"}
                },
                "required": ["model_path", "data_path", "method", "output_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "generate_model_card",
            "description": "Generate model card documentation with model details, performance metrics, bias analysis, and usage guidelines.",
            "parameters": {
                "type": "object",
                "properties": {
                    "model_path": {"type": "string", "description": "Path to trained model"},
                    "train_data_path": {"type": "string", "description": "Path to training data"},
                    "test_data_path": {"type": "string", "description": "Path to test data"},
                    "target_col": {"type": "string", "description": "Target column name"},
                    "output_path": {"type": "string", "description": "Path to save model card JSON"}
                },
                "required": ["model_path", "train_data_path", "test_data_path", "target_col", "output_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "perform_ab_test_analysis",
            "description": "Analyze A/B test results with statistical significance testing. Determine if variant B is better than control A.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to A/B test data"},
                    "variant_col": {"type": "string", "description": "Column indicating variant (A/B)"},
                    "metric_col": {"type": "string", "description": "Success metric column"},
                    "confidence_level": {"type": "number", "description": "Confidence level for significance (default: 0.95)"}
                },
                "required": ["file_path", "variant_col", "metric_col"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "detect_feature_leakage",
            "description": "Detect potential feature leakage by analyzing feature importance and temporal relationships. Prevents data leakage bugs.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "target_col": {"type": "string", "description": "Target column name"},
                    "date_col": {"type": "string", "description": "Optional date column for temporal analysis"}
                },
                "required": ["file_path", "target_col"]
            }
        }
    },
    
    # ============================================
    # TIME SERIES (3)
    # ============================================
    {
        "type": "function",
        "function": {
            "name": "forecast_time_series",
            "description": "Forecast future values using ARIMA, Prophet, or LSTM models. Handles seasonal and trend components.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to time series data"},
                    "date_col": {"type": "string", "description": "Date/timestamp column"},
                    "value_col": {"type": "string", "description": "Value column to forecast"},
                    "forecast_periods": {"type": "integer", "description": "Number of periods to forecast"},
                    "method": {"type": "string", "enum": ["arima", "prophet", "lstm"], "description": "Forecasting method"},
                    "output_path": {"type": "string", "description": "Path to save forecast results"}
                },
                "required": ["file_path", "date_col", "value_col", "forecast_periods", "method", "output_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "detect_seasonality_trends",
            "description": "Detect seasonality patterns and trends in time series data using STL decomposition and statistical tests.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to time series data"},
                    "date_col": {"type": "string", "description": "Date/timestamp column"},
                    "value_col": {"type": "string", "description": "Value column to analyze"},
                    "period": {"type": "integer", "description": "Expected seasonal period (e.g., 12 for monthly)"}
                },
                "required": ["file_path", "date_col", "value_col"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "create_time_series_features",
            "description": "Create comprehensive time series features: lags, rolling stats, exponential moving averages, and Fourier features.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to time series data"},
                    "date_col": {"type": "string", "description": "Date/timestamp column"},
                    "value_col": {"type": "string", "description": "Value column"},
                    "lags": {"type": "array", "items": {"type": "integer"}, "description": "Lag periods to create (e.g., [1, 7, 30])"},
                    "windows": {"type": "array", "items": {"type": "integer"}, "description": "Rolling window sizes (e.g., [7, 30])"},
                    "output_path": {"type": "string", "description": "Path to save dataset with time series features"}
                },
                "required": ["file_path", "date_col", "value_col", "output_path"]
            }
        }
    },
    
    # ============================================
    # ADVANCED INSIGHTS TOOLS (6) - NEW
    # ============================================
    
    {
        "type": "function",
        "function": {
            "name": "analyze_root_cause",
            "description": "Perform root cause analysis to identify why a metric dropped or changed. Analyzes correlations, temporal patterns, and identifies top influencing factors.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "target_col": {"type": "string", "description": "Column to analyze (e.g., 'sales')"},
                    "time_col": {"type": "string", "description": "Optional time column for trend analysis"},
                    "threshold_drop": {"type": "number", "description": "Percentage drop to flag as significant (default 0.15)"}
                },
                "required": ["file_path", "target_col"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "detect_trends_and_seasonality",
            "description": "Detect trends and seasonal patterns in time series data using statistical methods and autocorrelation.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "value_col": {"type": "string", "description": "Column with values to analyze"},
                    "time_col": {"type": "string", "description": "Column with timestamps"},
                    "seasonal_period": {"type": "integer", "description": "Expected seasonal period (auto-detected if None)"}
                },
                "required": ["file_path", "value_col", "time_col"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "detect_anomalies_advanced",
            "description": "Detect anomalies with confidence scores using Isolation Forest or statistical methods.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "columns": {"type": "array", "items": {"type": "string"}, "description": "Columns to analyze (all numeric if None)"},
                    "contamination": {"type": "number", "description": "Expected proportion of outliers (default 0.1)"},
                    "method": {"type": "string", "enum": ["isolation_forest", "statistical"], "description": "Detection method"}
                },
                "required": ["file_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "perform_hypothesis_testing",
            "description": "Perform statistical hypothesis testing (t-test, ANOVA, chi-square) to compare groups.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "group_col": {"type": "string", "description": "Column defining groups"},
                    "value_col": {"type": "string", "description": "Column with values to compare"},
                    "test_type": {"type": "string", "enum": ["t-test", "anova", "chi-square", "auto"], "description": "Test type (auto-detected if 'auto')"}
                },
                "required": ["file_path", "group_col", "value_col"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "analyze_distribution",
            "description": "Analyze distribution of a column including normality tests, skewness, and kurtosis.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "column": {"type": "string", "description": "Column to analyze"},
                    "tests": {"type": "array", "items": {"type": "string"}, "description": "Tests to perform (normality, skewness)"}
                },
                "required": ["file_path", "column"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "perform_segment_analysis",
            "description": "Perform cluster-based customer/data segmentation using K-means and profile each segment.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "n_segments": {"type": "integer", "description": "Number of segments to create (default 5)"},
                    "features": {"type": "array", "items": {"type": "string"}, "description": "Features for clustering (all numeric if None)"}
                },
                "required": ["file_path"]
            }
        }
    },
    
    # ============================================
    # AUTOMATED PIPELINE TOOLS (2) - NEW
    # ============================================
    
    {
        "type": "function",
        "function": {
            "name": "auto_ml_pipeline",
            "description": "Fully automated ML pipeline: auto-detect types, clean missing values, handle outliers, encode categorical, engineer features, and select best features. Zero configuration required!",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to input dataset"},
                    "target_col": {"type": "string", "description": "Target column name"},
                    "task_type": {"type": "string", "enum": ["classification", "regression", "auto"], "description": "Task type (auto-detected if 'auto')"},
                    "output_path": {"type": "string", "description": "Where to save processed data"},
                    "feature_engineering_level": {"type": "string", "enum": ["basic", "intermediate", "advanced"], "description": "Feature engineering depth"}
                },
                "required": ["file_path", "target_col"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "auto_feature_selection",
            "description": "Automatically select the best features for modeling using mutual information or F-statistics.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "target_col": {"type": "string", "description": "Target column"},
                    "task_type": {"type": "string", "enum": ["classification", "regression", "auto"], "description": "Task type"},
                    "max_features": {"type": "integer", "description": "Maximum features to keep (default 50)"},
                    "method": {"type": "string", "enum": ["mutual_info", "f_test", "auto"], "description": "Selection method"},
                    "output_path": {"type": "string", "description": "Where to save selected features"}
                },
                "required": ["file_path", "target_col"]
            }
        }
    },
    
    # ============================================
    # VISUALIZATION TOOLS (3) - NEW
    # ============================================
    
    {
        "type": "function",
        "function": {
            "name": "generate_all_plots",
            "description": "Generate ALL plots for a dataset automatically: data quality, EDA, distributions, and correlations. Creates interactive HTML plots.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "target_col": {"type": "string", "description": "Optional target column"},
                    "output_dir": {"type": "string", "description": "Directory to save plots (default ./outputs/plots)"}
                },
                "required": ["file_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "generate_data_quality_plots",
            "description": "Generate data quality visualizations: missing values, data types, and outlier detection plots.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "output_dir": {"type": "string", "description": "Directory to save plots"}
                },
                "required": ["file_path", "output_dir"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "generate_eda_plots",
            "description": "Generate exploratory data analysis plots: correlation heatmap, feature relationships, and pairplots.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "target_col": {"type": "string", "description": "Optional target column"},
                    "output_dir": {"type": "string", "description": "Directory to save plots"}
                },
                "required": ["file_path", "output_dir"]
            }
        }
    },
    
    # ============================================
    # INTERACTIVE PLOTLY VISUALIZATIONS (6)
    # ============================================
    {
        "type": "function",
        "function": {
            "name": "generate_interactive_scatter",
            "description": "Create interactive scatter plot with zoom, pan, and hover capabilities. Great for exploring relationships between variables.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "x_col": {"type": "string", "description": "Column for X-axis"},
                    "y_col": {"type": "string", "description": "Column for Y-axis"},
                    "color_col": {"type": "string", "description": "Optional column for color coding points"},
                    "size_col": {"type": "string", "description": "Optional column for bubble size"},
                    "output_path": {"type": "string", "description": "Path to save HTML file (default: ./outputs/plots/interactive/scatter.html)"}
                },
                "required": ["file_path", "x_col", "y_col"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "generate_interactive_histogram",
            "description": "Create interactive histogram with box plot overlay. Users can explore distribution interactively.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "column": {"type": "string", "description": "Column to plot distribution"},
                    "bins": {"type": "integer", "description": "Number of bins (default: 30)"},
                    "color_col": {"type": "string", "description": "Optional column for grouped histograms"},
                    "output_path": {"type": "string", "description": "Path to save HTML file"}
                },
                "required": ["file_path", "column"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "generate_interactive_correlation_heatmap",
            "description": "Create interactive correlation heatmap with hover values. Better than static matplotlib version.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "output_path": {"type": "string", "description": "Path to save HTML file"}
                },
                "required": ["file_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "generate_interactive_box_plots",
            "description": "Create interactive box plots for outlier detection. Supports grouping by categorical variable.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "columns": {"type": "array", "items": {"type": "string"}, "description": "Columns to plot (all numeric if not specified)"},
                    "group_by": {"type": "string", "description": "Optional categorical column for grouping"},
                    "output_path": {"type": "string", "description": "Path to save HTML file"}
                },
                "required": ["file_path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "generate_interactive_time_series",
            "description": "Create interactive time series plot with range slider and zoom. Perfect for temporal data analysis.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "time_col": {"type": "string", "description": "Column with datetime values"},
                    "value_cols": {"type": "array", "items": {"type": "string"}, "description": "Columns to plot over time"},
                    "output_path": {"type": "string", "description": "Path to save HTML file"}
                },
                "required": ["file_path", "time_col", "value_cols"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "generate_plotly_dashboard",
            "description": "Generate complete interactive dashboard with multiple visualizations: correlation heatmap, box plots, scatter plots, histograms. One-stop visualization solution.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to dataset"},
                    "target_col": {"type": "string", "description": "Optional target column for supervised analysis"},
                    "output_dir": {"type": "string", "description": "Directory to save all plots (default: ./outputs/plots/interactive)"}
                },
                "required": ["file_path"]
            }
        }
    },
    # EDA Report Generation (1) - NEW PHASE 2
    {
        "type": "function",
        "function": {
            "name": "generate_ydata_profiling_report",
            "description": "Generate comprehensive HTML report using ydata-profiling (formerly pandas-profiling). Provides extensive analysis: overview, variable statistics, interactions, correlations (Pearson, Spearman, Cramér's V), missing values matrix, duplicate analysis, and more. Most detailed and comprehensive profiling tool with automated insights and data quality warnings.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {"type": "string", "description": "Path to the dataset CSV/Parquet file"},
                    "output_path": {"type": "string", "description": "Where to save HTML report (default: ./outputs/reports/ydata_profile.html)"},
                    "minimal": {"type": "boolean", "description": "If true, generates faster minimal report (useful for large datasets, default: false)"},
                    "title": {"type": "string", "description": "Report title (default: 'Data Profiling Report')"}
                },
                "required": ["file_path"]
            }
        }
    },
    # ========================================
    # CODE INTERPRETER - THE GAME CHANGER 🚀
    # ========================================
    {
        "type": "function",
        "function": {
            "name": "execute_python_code",
            "description": "⭐ CRITICAL TOOL - Execute custom Python code for ANY data science task not covered by existing tools. This is what makes you a TRUE AI AGENT, not just a function-calling bot. Use this when user requests: 1) Custom visualizations (specific Plotly plots, interactive dashboards, unique chart types) 2) Domain-specific calculations 3) Custom data transformations 4) Specific export formats 5) Interactive widgets/filters. Code has access to pandas, polars, numpy, matplotlib, seaborn, plotly. ALWAYS save outputs to files and return file paths.",
            "parameters": {
                "type": "object",
                "properties": {
                    "code": {
                        "type": "string",
                        "description": "Python code to execute. Auto-imported: pandas as pd, polars as pl, numpy as np, matplotlib.pyplot as plt, seaborn as sns, plotly.express as px, plotly.graph_objects as go. Code should save outputs to files in working_directory. Example: fig.write_html('./outputs/code/plot.html')"
                    },
                    "working_directory": {
                        "type": "string",
                        "description": "Directory to run code in (default: ./outputs/code). Code can read from ./temp/ and write to this directory."
                    },
                    "timeout": {
                        "type": "integer",
                        "description": "Maximum execution time in seconds (default: 60)"
                    }
                },
                "required": ["code"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "execute_code_from_file",
            "description": "Execute Python code from an existing .py file. Useful when code is too long to pass as string, or when running pre-written scripts. Same capabilities as execute_python_code.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {
                        "type": "string",
                        "description": "Path to .py file to execute"
                    },
                    "working_directory": {
                        "type": "string",
                        "description": "Directory to run code in (default: ./outputs/code)"
                    },
                    "timeout": {
                        "type": "integer",
                        "description": "Maximum execution time in seconds (default: 60)"
                    }
                },
                "required": ["file_path"]
            }
        }
    },
    
    # ============================================
    # CLOUD DATA SOURCES (4) - NEW
    # ============================================
    
    {
        "type": "function",
        "function": {
            "name": "load_bigquery_table",
            "description": "Load data from Google BigQuery table into a Polars DataFrame. Supports sampling via LIMIT and column selection. Returns CSV path for downstream tools. Use profile_bigquery_table first for large tables.",
            "parameters": {
                "type": "object",
                "properties": {
                    "project_id": {
                        "type": "string",
                        "description": "Google Cloud project ID"
                    },
                    "dataset": {
                        "type": "string",
                        "description": "BigQuery dataset name"
                    },
                    "table": {
                        "type": "string",
                        "description": "BigQuery table name"
                    },
                    "limit": {
                        "type": "integer",
                        "description": "Optional row limit for sampling (e.g., 10000 for large tables)"
                    },
                    "columns": {
                        "type": "array",
                        "items": {"type": "string"},
                        "description": "Optional list of column names to load"
                    },
                    "where_clause": {
                        "type": "string",
                        "description": "Optional SQL WHERE clause for filtering (without WHERE keyword)"
                    }
                },
                "required": ["project_id", "dataset", "table"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "write_bigquery_table",
            "description": "Write predictions or processed data from CSV/Parquet file to BigQuery table. Supports append, overwrite, or fail modes.",
            "parameters": {
                "type": "object",
                "properties": {
                    "file_path": {
                        "type": "string",
                        "description": "Path to CSV or Parquet file to write"
                    },
                    "project_id": {
                        "type": "string",
                        "description": "Google Cloud project ID"
                    },
                    "dataset": {
                        "type": "string",
                        "description": "BigQuery dataset name"
                    },
                    "table": {
                        "type": "string",
                        "description": "BigQuery table name"
                    },
                    "mode": {
                        "type": "string",
                        "enum": ["append", "overwrite", "fail"],
                        "description": "Write mode: append (add rows), overwrite (replace), fail (error if exists)"
                    }
                },
                "required": ["file_path", "project_id", "dataset", "table"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "profile_bigquery_table",
            "description": "Profile a BigQuery table without loading all data. Returns row count, column types, null counts (sampled), table size, and load recommendations. Use this BEFORE load_bigquery_table for large tables.",
            "parameters": {
                "type": "object",
                "properties": {
                    "project_id": {
                        "type": "string",
                        "description": "Google Cloud project ID"
                    },
                    "dataset": {
                        "type": "string",
                        "description": "BigQuery dataset name"
                    },
                    "table": {
                        "type": "string",
                        "description": "BigQuery table name"
                    }
                },
                "required": ["project_id", "dataset", "table"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "query_bigquery",
            "description": "Execute custom BigQuery SQL query and return results as DataFrame. Useful for complex aggregations, joins, or transformations before analysis.",
            "parameters": {
                "type": "object",
                "properties": {
                    "project_id": {
                        "type": "string",
                        "description": "Google Cloud project ID"
                    },
                    "query": {
                        "type": "string",
                        "description": "SQL query to execute"
                    },
                    "output_path": {
                        "type": "string",
                        "description": "Optional path to save results (default: auto-generated)"
                    },
                    "limit": {
                        "type": "integer",
                        "description": "Optional row limit to append to query"
                    }
                },
                "required": ["project_id", "query"]
            }
        }
    }
]


def get_tool_by_name(tool_name: str) -> dict:
    """Get tool definition by name."""
    for tool in TOOLS:
        if tool["function"]["name"] == tool_name:
            return tool
    raise ValueError(f"Tool '{tool_name}' not found in registry")


def get_all_tool_names() -> list:
    """Get list of all tool names."""
    return [tool["function"]["name"] for tool in TOOLS]


def get_tools_by_category() -> dict:
    """Get tools organized by category."""
    return {
        "basic": [t["function"]["name"] for t in TOOLS[:16]],
        "advanced_analysis": [t["function"]["name"] for t in TOOLS[16:21]],
        "advanced_feature_engineering": [t["function"]["name"] for t in TOOLS[21:25]],
        "advanced_preprocessing": [t["function"]["name"] for t in TOOLS[25:28]],
        "advanced_training": [t["function"]["name"] for t in TOOLS[28:31]],
        "business_intelligence": [t["function"]["name"] for t in TOOLS[31:35]],
        "computer_vision": [t["function"]["name"] for t in TOOLS[35:38]],
        "nlp_text_analytics": [t["function"]["name"] for t in TOOLS[38:42]],
        "production_mlops": [t["function"]["name"] for t in TOOLS[42:47]],
        "time_series": [t["function"]["name"] for t in TOOLS[47:50]],
        "cloud_data_sources": [t["function"]["name"] for t in TOOLS[50:54]]
    }