@@ -242,10 +242,33 @@ const getInputMessageAttributes = (promptMessages?: AttributeValue) => {
242
242
243
243
return messages . reduce ( ( acc : Attributes , message , index ) => {
244
244
const MESSAGE_PREFIX = `${ SemanticConventions . LLM_INPUT_MESSAGES } .${ index } ` ;
245
- if ( isArrayOfObjects ( message . content ) ) {
245
+ if ( message . role === "tool" ) {
246
+ return {
247
+ ...acc ,
248
+ ...message ,
249
+ [ `${ MESSAGE_PREFIX } .${ SemanticConventions . MESSAGE_ROLE } ` ] : message . role ,
250
+ [ `${ MESSAGE_PREFIX } .${ SemanticConventions . TOOL_CALL_ID } ` ] :
251
+ typeof message . toolCallId === "string"
252
+ ? message . toolCallId
253
+ : undefined ,
254
+ [ `${ MESSAGE_PREFIX } .${ SemanticConventions . TOOL_NAME } ` ] :
255
+ typeof message . toolName === "string" ? message . toolName : undefined ,
256
+ [ `${ MESSAGE_PREFIX } .${ SemanticConventions . MESSAGE_CONTENT } ` ] :
257
+ Array . isArray ( message . content )
258
+ ? typeof message . content [ 0 ] ?. result === "string"
259
+ ? message . content [ 0 ] . result
260
+ : message . content [ 0 ] ?. result
261
+ ? JSON . stringify ( message . content [ 0 ] . result )
262
+ : undefined
263
+ : typeof message . content === "string"
264
+ ? message . content
265
+ : undefined ,
266
+ } ;
267
+ } else if ( isArrayOfObjects ( message . content ) ) {
246
268
const messageAttributes = message . content . reduce (
247
269
( acc : Attributes , content , contentIndex ) => {
248
270
const CONTENTS_PREFIX = `${ MESSAGE_PREFIX } .${ SemanticConventions . MESSAGE_CONTENTS } .${ contentIndex } ` ;
271
+ const TOOL_CALL_PREFIX = `${ MESSAGE_PREFIX } .${ SemanticConventions . MESSAGE_TOOL_CALLS } .${ contentIndex } ` ;
249
272
return {
250
273
...acc ,
251
274
[ `${ CONTENTS_PREFIX } .${ SemanticConventions . MESSAGE_CONTENT_TYPE } ` ] :
@@ -254,6 +277,20 @@ const getInputMessageAttributes = (promptMessages?: AttributeValue) => {
254
277
typeof content . text === "string" ? content . text : undefined ,
255
278
[ `${ CONTENTS_PREFIX } .${ SemanticConventions . MESSAGE_CONTENT_IMAGE } ` ] :
256
279
typeof content . image === "string" ? content . image : undefined ,
280
+ [ `${ TOOL_CALL_PREFIX } .${ SemanticConventions . TOOL_CALL_ID } ` ] :
281
+ typeof content . toolCallId === "string"
282
+ ? content . toolCallId
283
+ : undefined ,
284
+ [ `${ TOOL_CALL_PREFIX } .${ SemanticConventions . TOOL_CALL_FUNCTION_NAME } ` ] :
285
+ typeof content . toolName === "string"
286
+ ? content . toolName
287
+ : undefined ,
288
+ [ `${ TOOL_CALL_PREFIX } .${ SemanticConventions . TOOL_CALL_FUNCTION_ARGUMENTS_JSON } ` ] :
289
+ typeof content . args === "string"
290
+ ? content . args
291
+ : typeof content . args === "object"
292
+ ? JSON . stringify ( content . args )
293
+ : undefined ,
257
294
} ;
258
295
} ,
259
296
{ } ,
@@ -368,8 +405,6 @@ const getOpenInferenceAttributes = (attributes: Attributes): Attributes => {
368
405
const openInferenceAttributes = {
369
406
[ SemanticConventions . OPENINFERENCE_SPAN_KIND ] : spanKind ?? undefined ,
370
407
} ;
371
- console . log ( "new span attributes" ) ;
372
- console . table ( attributes ) ;
373
408
return AISemanticConventionsList . reduce (
374
409
( openInferenceAttributes : Attributes , convention ) => {
375
410
/**
0 commit comments