llm.rb 16.0.0 → 17.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +535 -2
  3. data/README.md +857 -501
  4. data/data/alibaba.json +2 -2
  5. data/data/anthropic.json +66 -3
  6. data/data/bedrock.json +781 -12
  7. data/data/deepinfra.json +157 -1
  8. data/data/google.json +48 -0
  9. data/data/mistral.json +326 -16
  10. data/data/moonshot.json +2 -1
  11. data/data/openai.json +13 -0
  12. data/data/openrouter.json +1078 -1235
  13. data/data/xai.json +4 -2
  14. data/docs/deepdive/advanced/cancellation.md +35 -7
  15. data/docs/deepdive/advanced/compaction.md +5 -5
  16. data/docs/deepdive/advanced/context.md +45 -24
  17. data/docs/deepdive/advanced/{guard.md → intercept.md} +87 -83
  18. data/docs/deepdive/features/builtin_tools.md +1 -1
  19. data/docs/deepdive/features/concurrency.md +15 -10
  20. data/docs/deepdive/features/database.md +19 -19
  21. data/docs/deepdive/features/embeddings.md +4 -4
  22. data/docs/deepdive/features/files.md +7 -5
  23. data/docs/deepdive/fundamentals/agents.md +13 -8
  24. data/docs/deepdive/fundamentals/providers.md +1 -1
  25. data/docs/deepdive/fundamentals/schema.md +2 -2
  26. data/docs/deepdive/fundamentals/stream.md +8 -8
  27. data/docs/deepdive/fundamentals/tools.md +14 -14
  28. data/docs/deepdive/media/ocr.md +1 -1
  29. data/docs/deepdive/protocols/a2a.md +3 -3
  30. data/docs/deepdive/protocols/mcp.md +116 -7
  31. data/docs/deepdive/reference/cost.md +1 -1
  32. data/docs/deepdive/reference/response.md +1 -1
  33. data/docs/deepdive/reference/tracer.md +90 -22
  34. data/docs/deepdive.md +1 -1
  35. data/lib/llm/agent/interrupt.rb +35 -46
  36. data/lib/llm/agent/registry.rb +106 -0
  37. data/lib/llm/agent.rb +242 -268
  38. data/lib/llm/context.rb +63 -55
  39. data/lib/llm/function/array.rb +2 -1
  40. data/lib/llm/function/async/group.rb +2 -2
  41. data/lib/llm/function/async/task.rb +25 -48
  42. data/lib/llm/function/fiber/group.rb +2 -2
  43. data/lib/llm/function/fiber/task.rb +16 -30
  44. data/lib/llm/function/fork/group.rb +2 -2
  45. data/lib/llm/function/fork/job.rb +8 -4
  46. data/lib/llm/function/fork/task.rb +25 -30
  47. data/lib/llm/function/group.rb +33 -5
  48. data/lib/llm/function/ractor/group.rb +2 -2
  49. data/lib/llm/function/ractor/job.rb +8 -6
  50. data/lib/llm/function/ractor/task.rb +32 -9
  51. data/lib/llm/function/sequential/group.rb +2 -1
  52. data/lib/llm/function/sequential/task.rb +8 -1
  53. data/lib/llm/function/task.rb +52 -4
  54. data/lib/llm/function/thread/group.rb +2 -2
  55. data/lib/llm/function/thread/task.rb +36 -10
  56. data/lib/llm/function/window.rb +16 -0
  57. data/lib/llm/function.rb +14 -43
  58. data/lib/llm/intercept/multi.rb +40 -0
  59. data/lib/llm/intercept/null.rb +18 -0
  60. data/lib/llm/intercept.rb +96 -0
  61. data/lib/llm/message.rb +1 -1
  62. data/lib/llm/provider.rb +16 -1
  63. data/lib/llm/providers/anthropic/stream_parser.rb +1 -1
  64. data/lib/llm/providers/bedrock/stream_parser.rb +1 -1
  65. data/lib/llm/providers/deepseek/files.rb +49 -0
  66. data/lib/llm/providers/deepseek/request_adapter/completion.rb +15 -13
  67. data/lib/llm/providers/deepseek.rb +16 -2
  68. data/lib/llm/providers/google/stream_parser.rb +1 -1
  69. data/lib/llm/providers/openai/responses/stream_parser.rb +1 -1
  70. data/lib/llm/providers/openai/stream_parser.rb +1 -1
  71. data/lib/llm/stream.rb +8 -7
  72. data/lib/llm/tool.rb +1 -1
  73. data/lib/llm/tools/utils.rb +1 -1
  74. data/lib/llm/tracer/logger.rb +42 -1
  75. data/lib/llm/tracer/multi.rb +144 -0
  76. data/lib/llm/tracer/null.rb +20 -0
  77. data/lib/llm/tracer/pretty_logger.rb +33 -2
  78. data/lib/llm/tracer/rescue.rb +110 -0
  79. data/lib/llm/tracer/telemetry.rb +69 -4
  80. data/lib/llm/tracer.rb +125 -48
  81. data/lib/llm/utils.rb +12 -2
  82. data/lib/llm/version.rb +1 -1
  83. data/lib/llm.rb +36 -1
  84. data/llm.gemspec +9 -4
  85. metadata +16 -35
  86. data/lib/llm/function/tracing.rb +0 -21
  87. data/lib/llm/guard/null.rb +0 -19
  88. data/lib/llm/guard.rb +0 -55
data/data/mistral.json CHANGED
@@ -94,6 +94,7 @@
94
94
  "context": 131072,
95
95
  "output": 16384
96
96
  },
97
+ "status": "deprecated",
97
98
  "cost": {
98
99
  "input": 2,
99
100
  "output": 6
@@ -125,6 +126,7 @@
125
126
  "context": 128000,
126
127
  "output": 128000
127
128
  },
129
+ "status": "deprecated",
128
130
  "cost": {
129
131
  "input": 0.15,
130
132
  "output": 0.15
@@ -181,6 +183,7 @@
181
183
  "context": 262144,
182
184
  "output": 262144
183
185
  },
186
+ "status": "deprecated",
184
187
  "cost": {
185
188
  "input": 0.4,
186
189
  "output": 2
@@ -250,7 +253,7 @@
250
253
  },
251
254
  "open_weights": true,
252
255
  "limit": {
253
- "context": 256000,
256
+ "context": 262144,
254
257
  "output": 256000
255
258
  },
256
259
  "cost": {
@@ -259,6 +262,39 @@
259
262
  "cache_read": 0.015
260
263
  }
261
264
  },
265
+ "ministral-8b-2512": {
266
+ "id": "ministral-8b-2512",
267
+ "name": "Ministral 3 8B",
268
+ "description": "Compact open vision-language model for edge deployment, instruction following, and tool use",
269
+ "family": "ministral",
270
+ "attachment": true,
271
+ "reasoning": false,
272
+ "tool_call": true,
273
+ "structured_output": true,
274
+ "temperature": true,
275
+ "release_date": "2025-12-02",
276
+ "last_updated": "2025-12-02",
277
+ "modalities": {
278
+ "input": [
279
+ "text",
280
+ "image"
281
+ ],
282
+ "output": [
283
+ "text"
284
+ ]
285
+ },
286
+ "open_weights": true,
287
+ "limit": {
288
+ "context": 262144,
289
+ "output": 262144
290
+ },
291
+ "cost": {
292
+ "input": 0.15,
293
+ "output": 0.15,
294
+ "cache_read": 0.015
295
+ },
296
+ "canonical_model_id": "mistral/ministral-3-8b-instruct-2512"
297
+ },
262
298
  "zai-glm-5-2": {
263
299
  "id": "zai-glm-5-2",
264
300
  "name": "GLM-5.2",
@@ -291,10 +327,10 @@
291
327
  },
292
328
  "open_weights": true,
293
329
  "limit": {
294
- "context": 1000000,
330
+ "context": 1048576,
295
331
  "output": 131072
296
332
  },
297
- "status": "beta",
333
+ "status": "deprecated",
298
334
  "cost": {
299
335
  "input": 1.4,
300
336
  "output": 4.4,
@@ -307,7 +343,7 @@
307
343
  "name": "Ministral 8B (latest)",
308
344
  "description": "Compact Mistral model for edge, latency-sensitive, and cost-efficient workloads",
309
345
  "family": "ministral",
310
- "attachment": false,
346
+ "attachment": true,
311
347
  "reasoning": false,
312
348
  "tool_call": true,
313
349
  "temperature": true,
@@ -316,7 +352,8 @@
316
352
  "last_updated": "2024-10-04",
317
353
  "modalities": {
318
354
  "input": [
319
- "text"
355
+ "text",
356
+ "image"
320
357
  ],
321
358
  "output": [
322
359
  "text"
@@ -324,7 +361,7 @@
324
361
  },
325
362
  "open_weights": true,
326
363
  "limit": {
327
- "context": 128000,
364
+ "context": 262144,
328
365
  "output": 128000
329
366
  },
330
367
  "cost": {
@@ -363,6 +400,49 @@
363
400
  "output": 2
364
401
  }
365
402
  },
403
+ "mistral-large-4": {
404
+ "id": "mistral-large-4",
405
+ "name": "Mistral Large 4",
406
+ "description": "Mistral's 1T-parameter multimodal MoE for reasoning, coding, and agentic work",
407
+ "family": "mistral-large",
408
+ "attachment": true,
409
+ "reasoning": true,
410
+ "reasoning_options": [
411
+ {
412
+ "type": "effort",
413
+ "values": [
414
+ "none",
415
+ "high"
416
+ ]
417
+ }
418
+ ],
419
+ "tool_call": true,
420
+ "structured_output": true,
421
+ "temperature": true,
422
+ "release_date": "2026-10-06",
423
+ "last_updated": "2026-10-06",
424
+ "modalities": {
425
+ "input": [
426
+ "text",
427
+ "image"
428
+ ],
429
+ "output": [
430
+ "text"
431
+ ]
432
+ },
433
+ "open_weights": false,
434
+ "limit": {
435
+ "context": 1048576,
436
+ "output": 262144
437
+ },
438
+ "status": "beta",
439
+ "cost": {
440
+ "input": 0.68,
441
+ "output": 2.09,
442
+ "cache_read": 0.07
443
+ },
444
+ "canonical_model_id": "mistral/mistral-large-4"
445
+ },
366
446
  "open-mixtral-8x22b": {
367
447
  "id": "open-mixtral-8x22b",
368
448
  "name": "Mixtral 8x22B",
@@ -388,6 +468,7 @@
388
468
  "context": 64000,
389
469
  "output": 64000
390
470
  },
471
+ "status": "deprecated",
391
472
  "cost": {
392
473
  "input": 2,
393
474
  "output": 6
@@ -450,6 +531,7 @@
450
531
  "context": 131072,
451
532
  "output": 131072
452
533
  },
534
+ "status": "deprecated",
453
535
  "cost": {
454
536
  "input": 0.4,
455
537
  "output": 2
@@ -460,9 +542,17 @@
460
542
  "name": "Magistral Medium (latest)",
461
543
  "description": "Mistral reasoning model for transparent analysis, math, and complex decisions",
462
544
  "family": "magistral-medium",
463
- "attachment": false,
545
+ "attachment": true,
464
546
  "reasoning": true,
465
- "reasoning_options": [],
547
+ "reasoning_options": [
548
+ {
549
+ "type": "effort",
550
+ "values": [
551
+ "none",
552
+ "high"
553
+ ]
554
+ }
555
+ ],
466
556
  "tool_call": true,
467
557
  "temperature": true,
468
558
  "knowledge": "2025-06",
@@ -470,7 +560,8 @@
470
560
  "last_updated": "2025-03-20",
471
561
  "modalities": {
472
562
  "input": [
473
- "text"
563
+ "text",
564
+ "image"
474
565
  ],
475
566
  "output": [
476
567
  "text"
@@ -478,14 +569,129 @@
478
569
  },
479
570
  "open_weights": true,
480
571
  "limit": {
481
- "context": 128000,
572
+ "context": 262144,
482
573
  "output": 16384
483
574
  },
575
+ "status": "deprecated",
484
576
  "cost": {
485
577
  "input": 2,
486
578
  "output": 5
487
579
  }
488
580
  },
581
+ "voxtral-small-2507": {
582
+ "id": "voxtral-small-2507",
583
+ "name": "Voxtral Small",
584
+ "description": "Instruct model with native audio input for speech understanding and tool use",
585
+ "family": "voxtral",
586
+ "attachment": true,
587
+ "reasoning": false,
588
+ "tool_call": true,
589
+ "temperature": true,
590
+ "release_date": "2025-07-15",
591
+ "last_updated": "2025-07-15",
592
+ "modalities": {
593
+ "input": [
594
+ "text",
595
+ "audio"
596
+ ],
597
+ "output": [
598
+ "text"
599
+ ]
600
+ },
601
+ "open_weights": true,
602
+ "limit": {
603
+ "context": 32768,
604
+ "output": 32000
605
+ },
606
+ "cost": {
607
+ "input": 0.1,
608
+ "output": 0.4
609
+ }
610
+ },
611
+ "glm-5-2": {
612
+ "id": "glm-5-2",
613
+ "name": "GLM-5.2",
614
+ "description": "Open flagship GLM for long-horizon coding agents and million-token context work",
615
+ "family": "glm",
616
+ "attachment": false,
617
+ "reasoning": true,
618
+ "reasoning_options": [
619
+ {
620
+ "type": "effort",
621
+ "values": [
622
+ "none",
623
+ "high",
624
+ "max"
625
+ ]
626
+ }
627
+ ],
628
+ "tool_call": true,
629
+ "structured_output": true,
630
+ "temperature": true,
631
+ "release_date": "2026-06-13",
632
+ "last_updated": "2026-06-13",
633
+ "modalities": {
634
+ "input": [
635
+ "text"
636
+ ],
637
+ "output": [
638
+ "text"
639
+ ]
640
+ },
641
+ "open_weights": true,
642
+ "limit": {
643
+ "context": 1048576,
644
+ "output": 131072
645
+ },
646
+ "status": "deprecated",
647
+ "cost": {
648
+ "input": 1.4,
649
+ "output": 4.4,
650
+ "cache_read": 0.14
651
+ },
652
+ "canonical_model_id": "zhipuai/glm-5.2"
653
+ },
654
+ "labs-leanstral-1-5-1": {
655
+ "id": "labs-leanstral-1-5-1",
656
+ "name": "Leanstral 1.5",
657
+ "description": "An updated Lean 4 formal proof engineering model optimised for automated theorem proving and autoformalization. 119B total parameters, 6.5B active.",
658
+ "family": "leanstral",
659
+ "attachment": true,
660
+ "reasoning": true,
661
+ "reasoning_options": [
662
+ {
663
+ "type": "effort",
664
+ "values": [
665
+ "none",
666
+ "high"
667
+ ]
668
+ }
669
+ ],
670
+ "tool_call": true,
671
+ "structured_output": true,
672
+ "temperature": true,
673
+ "release_date": "2026-06-30",
674
+ "last_updated": "2026-06-30",
675
+ "modalities": {
676
+ "input": [
677
+ "text",
678
+ "image"
679
+ ],
680
+ "output": [
681
+ "text"
682
+ ]
683
+ },
684
+ "open_weights": true,
685
+ "limit": {
686
+ "context": 262144,
687
+ "output": 128000
688
+ },
689
+ "status": "deprecated",
690
+ "cost": {
691
+ "input": 0,
692
+ "output": 0
693
+ }
694
+ },
489
695
  "pixtral-12b": {
490
696
  "id": "pixtral-12b",
491
697
  "name": "Pixtral 12B",
@@ -512,6 +718,7 @@
512
718
  "context": 128000,
513
719
  "output": 128000
514
720
  },
721
+ "status": "deprecated",
515
722
  "cost": {
516
723
  "input": 0.15,
517
724
  "output": 0.15
@@ -609,7 +816,7 @@
609
816
  },
610
817
  "open_weights": true,
611
818
  "limit": {
612
- "context": 256000,
819
+ "context": 262144,
613
820
  "output": 256000
614
821
  },
615
822
  "cost": {
@@ -769,6 +976,39 @@
769
976
  "output": 2
770
977
  }
771
978
  },
979
+ "ministral-14b-2512": {
980
+ "id": "ministral-14b-2512",
981
+ "name": "Ministral 3 14B",
982
+ "description": "Open vision-language model for efficient local deployment, instruction following, and tool use",
983
+ "family": "ministral",
984
+ "attachment": true,
985
+ "reasoning": false,
986
+ "tool_call": true,
987
+ "structured_output": true,
988
+ "temperature": true,
989
+ "release_date": "2025-12-02",
990
+ "last_updated": "2025-12-02",
991
+ "modalities": {
992
+ "input": [
993
+ "text",
994
+ "image"
995
+ ],
996
+ "output": [
997
+ "text"
998
+ ]
999
+ },
1000
+ "open_weights": true,
1001
+ "limit": {
1002
+ "context": 262144,
1003
+ "output": 262144
1004
+ },
1005
+ "cost": {
1006
+ "input": 0.2,
1007
+ "output": 0.2,
1008
+ "cache_read": 0.02
1009
+ },
1010
+ "canonical_model_id": "mistral/ministral-3-14b-instruct-2512"
1011
+ },
772
1012
  "devstral-small-2507": {
773
1013
  "id": "devstral-small-2507",
774
1014
  "name": "Devstral Small",
@@ -826,6 +1066,7 @@
826
1066
  "context": 128000,
827
1067
  "output": 128000
828
1068
  },
1069
+ "status": "deprecated",
829
1070
  "cost": {
830
1071
  "input": 2,
831
1072
  "output": 6
@@ -853,7 +1094,7 @@
853
1094
  },
854
1095
  "open_weights": true,
855
1096
  "limit": {
856
- "context": 32000,
1097
+ "context": 32768,
857
1098
  "output": 32000
858
1099
  },
859
1100
  "cost": {
@@ -886,6 +1127,7 @@
886
1127
  "context": 32000,
887
1128
  "output": 32000
888
1129
  },
1130
+ "status": "deprecated",
889
1131
  "cost": {
890
1132
  "input": 0.7,
891
1133
  "output": 0.7
@@ -917,6 +1159,7 @@
917
1159
  "context": 128000,
918
1160
  "output": 16384
919
1161
  },
1162
+ "status": "deprecated",
920
1163
  "cost": {
921
1164
  "input": 0.1,
922
1165
  "output": 0.3
@@ -954,7 +1197,7 @@
954
1197
  },
955
1198
  "open_weights": true,
956
1199
  "limit": {
957
- "context": 1000000,
1200
+ "context": 1048576,
958
1201
  "output": 131072
959
1202
  },
960
1203
  "cost": {
@@ -964,6 +1207,39 @@
964
1207
  },
965
1208
  "canonical_model_id": "zhipuai/glm-5.3"
966
1209
  },
1210
+ "ministral-3b-2512": {
1211
+ "id": "ministral-3b-2512",
1212
+ "name": "Ministral 3 3B",
1213
+ "description": "Compact open vision-language model for edge deployment, instruction following, and tool use",
1214
+ "family": "ministral",
1215
+ "attachment": true,
1216
+ "reasoning": false,
1217
+ "tool_call": true,
1218
+ "structured_output": true,
1219
+ "temperature": true,
1220
+ "release_date": "2025-12-02",
1221
+ "last_updated": "2025-12-02",
1222
+ "modalities": {
1223
+ "input": [
1224
+ "text",
1225
+ "image"
1226
+ ],
1227
+ "output": [
1228
+ "text"
1229
+ ]
1230
+ },
1231
+ "open_weights": true,
1232
+ "limit": {
1233
+ "context": 131072,
1234
+ "output": 262144
1235
+ },
1236
+ "cost": {
1237
+ "input": 0.1,
1238
+ "output": 0.1,
1239
+ "cache_read": 0.01
1240
+ },
1241
+ "canonical_model_id": "mistral/ministral-3-3b-instruct-2512"
1242
+ },
967
1243
  "mistral-medium-2604": {
968
1244
  "id": "mistral-medium-2604",
969
1245
  "name": "Mistral Medium 3.5",
@@ -1030,17 +1306,50 @@
1030
1306
  "context": 8000,
1031
1307
  "output": 8000
1032
1308
  },
1309
+ "status": "deprecated",
1033
1310
  "cost": {
1034
1311
  "input": 0.25,
1035
1312
  "output": 0.25
1036
1313
  }
1037
1314
  },
1315
+ "codestral-2508": {
1316
+ "id": "codestral-2508",
1317
+ "name": "Codestral 25.08",
1318
+ "description": "Mistral code model for low-latency completion, fill-in-the-middle, and code generation",
1319
+ "family": "codestral",
1320
+ "attachment": false,
1321
+ "reasoning": false,
1322
+ "tool_call": true,
1323
+ "structured_output": true,
1324
+ "temperature": true,
1325
+ "release_date": "2025-07-30",
1326
+ "last_updated": "2025-07-30",
1327
+ "modalities": {
1328
+ "input": [
1329
+ "text"
1330
+ ],
1331
+ "output": [
1332
+ "text"
1333
+ ]
1334
+ },
1335
+ "open_weights": false,
1336
+ "limit": {
1337
+ "context": 256000,
1338
+ "output": 8192
1339
+ },
1340
+ "cost": {
1341
+ "input": 0.3,
1342
+ "output": 0.9,
1343
+ "cache_read": 0.03
1344
+ },
1345
+ "canonical_model_id": "mistral/codestral-2508"
1346
+ },
1038
1347
  "ministral-3b-latest": {
1039
1348
  "id": "ministral-3b-latest",
1040
1349
  "name": "Ministral 3B (latest)",
1041
1350
  "description": "Compact Mistral model for edge, latency-sensitive, and cost-efficient workloads",
1042
1351
  "family": "ministral",
1043
- "attachment": false,
1352
+ "attachment": true,
1044
1353
  "reasoning": false,
1045
1354
  "tool_call": true,
1046
1355
  "temperature": true,
@@ -1049,7 +1358,8 @@
1049
1358
  "last_updated": "2024-10-04",
1050
1359
  "modalities": {
1051
1360
  "input": [
1052
- "text"
1361
+ "text",
1362
+ "image"
1053
1363
  ],
1054
1364
  "output": [
1055
1365
  "text"
@@ -1057,7 +1367,7 @@
1057
1367
  },
1058
1368
  "open_weights": true,
1059
1369
  "limit": {
1060
- "context": 128000,
1370
+ "context": 131072,
1061
1371
  "output": 128000
1062
1372
  },
1063
1373
  "cost": {
data/data/moonshot.json CHANGED
@@ -51,7 +51,8 @@
51
51
  "cost": {
52
52
  "input": 3,
53
53
  "output": 15,
54
- "cache_read": 0.3
54
+ "cache_read": 0.3,
55
+ "cache_write": 3
55
56
  },
56
57
  "canonical_model_id": "moonshotai/kimi-k3"
57
58
  },
data/data/openai.json CHANGED
@@ -1336,6 +1336,19 @@
1336
1336
  }
1337
1337
  }
1338
1338
  }
1339
+ },
1340
+ "ultrafast": {
1341
+ "cost": {
1342
+ "input": 12,
1343
+ "output": 60,
1344
+ "cache_read": 0.6,
1345
+ "cache_write": 15
1346
+ },
1347
+ "provider": {
1348
+ "body": {
1349
+ "service_tier": "ultrafast"
1350
+ }
1351
+ }
1339
1352
  }
1340
1353
  }
1341
1354
  },