@@ -173,7 +173,15 @@ def test_start_model_invoke_span_latest_conventions(mock_tracer):
173173 mock_span = mock .MagicMock ()
174174 mock_tracer .start_span .return_value = mock_span
175175
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+ ]
177185 model_id = "test-model"
178186
179187 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):
191199 [
192200 {
193201 "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+ },
196215 ]
197216 )
198217 },
@@ -255,7 +274,7 @@ def test_end_model_invoke_span_latest_conventions(mock_span):
255274 [
256275 {
257276 "role" : "assistant" ,
258- "parts" : [{"type" : "text" , "content" : message [ "content" ] }],
277+ "parts" : [{"type" : "text" , "content" : "Response" }],
259278 "finish_reason" : "end_turn" ,
260279 }
261280 ]
@@ -324,7 +343,7 @@ def test_start_tool_call_span_latest_conventions(mock_tracer):
324343 "type" : "tool_call" ,
325344 "name" : tool ["name" ],
326345 "id" : tool ["toolUseId" ],
327- "arguments" : [{ "content" : tool ["input" ]} ],
346+ "arguments" : tool ["input" ],
328347 }
329348 ],
330349 }
@@ -404,7 +423,7 @@ def test_start_swarm_span_with_contentblock_task_latest_conventions(mock_tracer)
404423 "gen_ai.client.inference.operation.details" ,
405424 attributes = {
406425 "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" }]}]
408427 )
409428 },
410429 )
@@ -492,7 +511,7 @@ def test_end_tool_call_span_latest_conventions(mock_span):
492511 """Test ending a tool call span with the latest semantic conventions."""
493512 tracer = Tracer ()
494513 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" }} ]}
496515
497516 tracer .end_tool_call_span (mock_span , tool_result )
498517
@@ -508,7 +527,7 @@ def test_end_tool_call_span_latest_conventions(mock_span):
508527 {
509528 "type" : "tool_call_response" ,
510529 "id" : tool_result .get ("toolUseId" , "" ),
511- "result " : tool_result .get ("content" ),
530+ "response " : tool_result .get ("content" ),
512531 }
513532 ],
514533 }
@@ -564,9 +583,7 @@ def test_start_event_loop_cycle_span_latest_conventions(mock_tracer):
564583 mock_span .add_event .assert_any_call (
565584 "gen_ai.client.inference.operation.details" ,
566585 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" }]}])
570587 },
571588 )
572589 assert span is not None
@@ -576,7 +593,12 @@ def test_end_event_loop_cycle_span(mock_span):
576593 """Test ending an event loop cycle span."""
577594 tracer = Tracer ()
578595 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+ }
580602
581603 tracer .end_event_loop_cycle_span (mock_span , message , tool_result_message )
582604
@@ -596,7 +618,12 @@ def test_end_event_loop_cycle_span_latest_conventions(mock_span):
596618 tracer = Tracer ()
597619 tracer .use_latest_genai_conventions = True
598620 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+ }
600627
601628 tracer .end_event_loop_cycle_span (mock_span , message , tool_result_message )
602629
@@ -607,7 +634,13 @@ def test_end_event_loop_cycle_span_latest_conventions(mock_span):
607634 [
608635 {
609636 "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+ ],
611644 }
612645 ]
613646 )
@@ -682,7 +715,7 @@ def test_start_agent_span_latest_conventions(mock_tracer):
682715 "gen_ai.client.inference.operation.details" ,
683716 attributes = {
684717 "gen_ai.input.messages" : serialize (
685- [{"role" : "user" , "parts" : [{"type" : "text" , "content" : [{ "text" : " test prompt"}] }]}]
718+ [{"role" : "user" , "parts" : [{"type" : "text" , "content" : " test prompt" }]}]
686719 )
687720 },
688721 )
0 commit comments