@@ -391,6 +391,44 @@ describe('tagger', () => {
391
391
expect ( ( ) => tagger . tagLLMIO ( span , messages , undefined ) ) . to . throw ( )
392
392
} )
393
393
} )
394
+
395
+ describe ( 'tool message tagging' , ( ) => {
396
+ it ( 'tags a span with a tool message' , ( ) => {
397
+ const messages = [
398
+ { role : 'tool' , content : 'The weather in San Francisco is sunny' , toolId : '123' }
399
+ ]
400
+
401
+ tagger . _register ( span )
402
+ tagger . tagLLMIO ( span , messages , undefined )
403
+ expect ( Tagger . tagMap . get ( span ) ) . to . deep . equal ( {
404
+ '_ml_obs.meta.input.messages' : [
405
+ { role : 'tool' , content : 'The weather in San Francisco is sunny' , tool_id : '123' }
406
+ ]
407
+ } )
408
+ } )
409
+
410
+ it ( 'throws if the tool id is not a string' , ( ) => {
411
+ const messages = [
412
+ { role : 'tool' , content : 'The weather in San Francisco is sunny' , toolId : 123 }
413
+ ]
414
+
415
+ expect ( ( ) => tagger . tagLLMIO ( span , messages , undefined ) ) . to . throw ( )
416
+ } )
417
+
418
+ it ( 'logs a warning if the tool id is not associated with a tool role' , ( ) => {
419
+ const messages = [
420
+ { role : 'user' , content : 'The weather in San Francisco is sunny' , toolId : '123' }
421
+ ]
422
+
423
+ tagger . _register ( span )
424
+ tagger . tagLLMIO ( span , messages , undefined )
425
+
426
+ const messageTags = Tagger . tagMap . get ( span ) [ '_ml_obs.meta.input.messages' ]
427
+ expect ( messageTags [ 0 ] ) . to . not . have . property ( 'tool_id' )
428
+
429
+ expect ( logger . warn ) . to . have . been . calledOnce
430
+ } )
431
+ } )
394
432
} )
395
433
396
434
describe ( 'tagEmbeddingIO' , ( ) => {
@@ -640,6 +678,17 @@ describe('tagger', () => {
640
678
expect ( logger . warn . callCount ) . to . equal ( 5 ) // 4 for tool call + 1 for role
641
679
} )
642
680
} )
681
+
682
+ it ( 'logs a warning if the tool id is not a string' , ( ) => {
683
+ const messages = [
684
+ { role : 'tool' , content : 'The weather in San Francisco is sunny' , toolId : 123 }
685
+ ]
686
+
687
+ tagger . _register ( span )
688
+ tagger . tagLLMIO ( span , messages , undefined )
689
+ expect ( Tagger . tagMap . get ( span ) ) . to . not . have . property ( '_ml_obs.meta.input.messages' )
690
+ expect ( logger . warn ) . to . have . been . calledOnce
691
+ } )
643
692
} )
644
693
} )
645
694
} )
0 commit comments