@@ -173,7 +173,15 @@ def test_start_model_invoke_span_latest_conventions(mock_tracer):
173
173
mock_span = mock .MagicMock ()
174
174
mock_tracer .start_span .return_value = mock_span
175
175
176
- messages = [{"role" : "user" , "content" : [{"text" : "Hello" }]}]
176
+ messages = [
177
+ {"role" : "user" , "content" : [{"text" : "Hello 2025-1993" }]},
178
+ {
179
+ "role" : "assistant" ,
180
+ "content" : [
181
+ {"toolUse" : {"input" : '"expression": "2025-1993"' , "name" : "calculator" , "toolUseId" : "123" }}
182
+ ],
183
+ },
184
+ ]
177
185
model_id = "test-model"
178
186
179
187
span = tracer .start_model_invoke_span (messages = messages , agent_name = "TestAgent" , model_id = model_id )
@@ -191,8 +199,19 @@ def test_start_model_invoke_span_latest_conventions(mock_tracer):
191
199
[
192
200
{
193
201
"role" : messages [0 ]["role" ],
194
- "parts" : [{"type" : "text" , "content" : messages [0 ]["content" ]}],
195
- }
202
+ "parts" : [{"type" : "text" , "content" : "Hello 2025-1993" }],
203
+ },
204
+ {
205
+ "role" : messages [1 ]["role" ],
206
+ "parts" : [
207
+ {
208
+ "type" : "tool_call" ,
209
+ "name" : "calculator" ,
210
+ "id" : "123" ,
211
+ "arguments" : '"expression": "2025-1993"' ,
212
+ }
213
+ ],
214
+ },
196
215
]
197
216
)
198
217
},
@@ -255,7 +274,7 @@ def test_end_model_invoke_span_latest_conventions(mock_span):
255
274
[
256
275
{
257
276
"role" : "assistant" ,
258
- "parts" : [{"type" : "text" , "content" : message [ "content" ] }],
277
+ "parts" : [{"type" : "text" , "content" : "Response" }],
259
278
"finish_reason" : "end_turn" ,
260
279
}
261
280
]
@@ -324,7 +343,7 @@ def test_start_tool_call_span_latest_conventions(mock_tracer):
324
343
"type" : "tool_call" ,
325
344
"name" : tool ["name" ],
326
345
"id" : tool ["toolUseId" ],
327
- "arguments" : [{ "content" : tool ["input" ]} ],
346
+ "arguments" : tool ["input" ],
328
347
}
329
348
],
330
349
}
@@ -404,7 +423,7 @@ def test_start_swarm_span_with_contentblock_task_latest_conventions(mock_tracer)
404
423
"gen_ai.client.inference.operation.details" ,
405
424
attributes = {
406
425
"gen_ai.input.messages" : serialize (
407
- [{"role" : "user" , "parts" : [{"type" : "text" , "content" : [{ "text" : " Original Task: foo bar"}] }]}]
426
+ [{"role" : "user" , "parts" : [{"type" : "text" , "content" : " Original Task: foo bar" }]}]
408
427
)
409
428
},
410
429
)
@@ -492,7 +511,7 @@ def test_end_tool_call_span_latest_conventions(mock_span):
492
511
"""Test ending a tool call span with the latest semantic conventions."""
493
512
tracer = Tracer ()
494
513
tracer .use_latest_genai_conventions = True
495
- tool_result = {"status" : "success" , "content" : [{"text" : "Tool result" }]}
514
+ tool_result = {"status" : "success" , "content" : [{"text" : "Tool result" }, { "json" : { "foo" : "bar" }} ]}
496
515
497
516
tracer .end_tool_call_span (mock_span , tool_result )
498
517
@@ -508,7 +527,7 @@ def test_end_tool_call_span_latest_conventions(mock_span):
508
527
{
509
528
"type" : "tool_call_response" ,
510
529
"id" : tool_result .get ("toolUseId" , "" ),
511
- "result " : tool_result .get ("content" ),
530
+ "response " : tool_result .get ("content" ),
512
531
}
513
532
],
514
533
}
@@ -564,9 +583,7 @@ def test_start_event_loop_cycle_span_latest_conventions(mock_tracer):
564
583
mock_span .add_event .assert_any_call (
565
584
"gen_ai.client.inference.operation.details" ,
566
585
attributes = {
567
- "gen_ai.input.messages" : serialize (
568
- [{"role" : "user" , "parts" : [{"type" : "text" , "content" : messages [0 ]["content" ]}]}]
569
- )
586
+ "gen_ai.input.messages" : serialize ([{"role" : "user" , "parts" : [{"type" : "text" , "content" : "Hello" }]}])
570
587
},
571
588
)
572
589
assert span is not None
@@ -576,7 +593,12 @@ def test_end_event_loop_cycle_span(mock_span):
576
593
"""Test ending an event loop cycle span."""
577
594
tracer = Tracer ()
578
595
message = {"role" : "assistant" , "content" : [{"text" : "Response" }]}
579
- tool_result_message = {"role" : "assistant" , "content" : [{"toolResult" : {"response" : "Success" }}]}
596
+ tool_result_message = {
597
+ "role" : "assistant" ,
598
+ "content" : [
599
+ {"toolResult" : {"toolUseId" : "123" , "status" : "success" , "content" : [{"text" : "Weather is sunny" }]}}
600
+ ],
601
+ }
580
602
581
603
tracer .end_event_loop_cycle_span (mock_span , message , tool_result_message )
582
604
@@ -596,7 +618,12 @@ def test_end_event_loop_cycle_span_latest_conventions(mock_span):
596
618
tracer = Tracer ()
597
619
tracer .use_latest_genai_conventions = True
598
620
message = {"role" : "assistant" , "content" : [{"text" : "Response" }]}
599
- tool_result_message = {"role" : "assistant" , "content" : [{"toolResult" : {"response" : "Success" }}]}
621
+ tool_result_message = {
622
+ "role" : "assistant" ,
623
+ "content" : [
624
+ {"toolResult" : {"toolUseId" : "123" , "status" : "success" , "content" : [{"text" : "Weather is sunny" }]}}
625
+ ],
626
+ }
600
627
601
628
tracer .end_event_loop_cycle_span (mock_span , message , tool_result_message )
602
629
@@ -607,7 +634,13 @@ def test_end_event_loop_cycle_span_latest_conventions(mock_span):
607
634
[
608
635
{
609
636
"role" : "assistant" ,
610
- "parts" : [{"type" : "text" , "content" : tool_result_message ["content" ]}],
637
+ "parts" : [
638
+ {
639
+ "type" : "tool_call_response" ,
640
+ "id" : "123" ,
641
+ "response" : [{"text" : "Weather is sunny" }],
642
+ }
643
+ ],
611
644
}
612
645
]
613
646
)
@@ -682,7 +715,7 @@ def test_start_agent_span_latest_conventions(mock_tracer):
682
715
"gen_ai.client.inference.operation.details" ,
683
716
attributes = {
684
717
"gen_ai.input.messages" : serialize (
685
- [{"role" : "user" , "parts" : [{"type" : "text" , "content" : [{ "text" : " test prompt"}] }]}]
718
+ [{"role" : "user" , "parts" : [{"type" : "text" , "content" : " test prompt" }]}]
686
719
)
687
720
},
688
721
)
0 commit comments