@@ -1353,7 +1353,6 @@ def test_agent_call_creates_and_ends_span_on_success(mock_get_tracer, mock_model
13531353 messages = [{"content" : [{"text" : "test prompt" }], "role" : "user" }],
13541354 agent_name = "Strands Agents" ,
13551355 model_id = unittest .mock .ANY ,
1356- tools = agent .tool_names ,
13571356 system_prompt = agent .system_prompt ,
13581357 custom_trace_attributes = agent .trace_attributes ,
13591358 )
@@ -1387,7 +1386,6 @@ async def test_event_loop(*args, **kwargs):
13871386 messages = [{"content" : [{"text" : "test prompt" }], "role" : "user" }],
13881387 agent_name = "Strands Agents" ,
13891388 model_id = unittest .mock .ANY ,
1390- tools = agent .tool_names ,
13911389 system_prompt = agent .system_prompt ,
13921390 custom_trace_attributes = agent .trace_attributes ,
13931391 )
@@ -1425,7 +1423,6 @@ def test_agent_call_creates_and_ends_span_on_exception(mock_get_tracer, mock_mod
14251423 messages = [{"content" : [{"text" : "test prompt" }], "role" : "user" }],
14261424 agent_name = "Strands Agents" ,
14271425 model_id = unittest .mock .ANY ,
1428- tools = agent .tool_names ,
14291426 system_prompt = agent .system_prompt ,
14301427 custom_trace_attributes = agent .trace_attributes ,
14311428 )
@@ -1461,7 +1458,6 @@ async def test_agent_stream_async_creates_and_ends_span_on_exception(mock_get_tr
14611458 messages = [{"content" : [{"text" : "test prompt" }], "role" : "user" }],
14621459 agent_name = "Strands Agents" ,
14631460 model_id = unittest .mock .ANY ,
1464- tools = agent .tool_names ,
14651461 system_prompt = agent .system_prompt ,
14661462 custom_trace_attributes = agent .trace_attributes ,
14671463 )
@@ -2162,6 +2158,68 @@ def shell(command: str):
21622158 assert agent .messages [- 1 ] == {"content" : [{"text" : "I invoked a tool!" }], "role" : "assistant" }
21632159
21642160
2161+ def test_agent_does_not_include_tools_in_trace_by_default (tool_decorated , monkeypatch ):
2162+ """Verify that by default, the agent does not add tool specs to the trace."""
2163+ monkeypatch .setenv ("OTEL_SEMCONV_STABILITY_OPT_IN" , "" )
2164+ with unittest .mock .patch ("strands.agent.agent.get_tracer" ) as mock_get_tracer :
2165+ # We need to re-import the tracer to pick up the new env var
2166+ import importlib
2167+
2168+ from strands .telemetry import tracer
2169+
2170+ importlib .reload (tracer )
2171+
2172+ mock_tracer_instance = tracer .Tracer ()
2173+ mock_span = unittest .mock .MagicMock ()
2174+ mock_tracer_instance .start_agent_span = unittest .mock .MagicMock (return_value = mock_span )
2175+ mock_get_tracer .return_value = mock_tracer_instance
2176+
2177+ mock_model = MockedModelProvider ([{"role" : "assistant" , "content" : [{"text" : "hello!" }]}])
2178+
2179+ agent = Agent (tools = [tool_decorated ], model = mock_model )
2180+ agent ("test prompt" )
2181+
2182+ # Check that set_attribute was not called for our specific key
2183+ called_attributes = [call .args [0 ] for call in mock_span .set_attribute .call_args_list ]
2184+ assert "gen_ai.tool.definitions" not in called_attributes
2185+
2186+
2187+ def test_agent_includes_tools_in_trace_when_enabled (tool_decorated , monkeypatch ):
2188+ """Verify that the agent adds tool specs to the trace when the flag is enabled."""
2189+ monkeypatch .setenv ("OTEL_SEMCONV_STABILITY_OPT_IN" , "gen_ai_tool_definitions" )
2190+ with unittest .mock .patch ("strands.agent.agent.get_tracer" ) as mock_get_tracer :
2191+ # We need to re-import the tracer to pick up the new env var
2192+ import importlib
2193+
2194+ from strands .telemetry import tracer
2195+
2196+ importlib .reload (tracer )
2197+
2198+ mock_tracer_instance = tracer .Tracer ()
2199+ mock_span = unittest .mock .MagicMock ()
2200+ mock_tracer_instance .start_agent_span = unittest .mock .MagicMock (return_value = mock_span )
2201+ mock_get_tracer .return_value = mock_tracer_instance
2202+
2203+ mock_model = MockedModelProvider ([{"role" : "assistant" , "content" : [{"text" : "hello!" }]}])
2204+
2205+ agent = Agent (tools = [tool_decorated ], model = mock_model )
2206+ agent ("test prompt" )
2207+
2208+ # Verify the correct data is serialized and set as an attribute
2209+ tool_spec = tool_decorated .tool_spec
2210+ expected_tool_details = [
2211+ {
2212+ "name" : tool_spec .get ("name" ),
2213+ "description" : tool_spec .get ("description" ),
2214+ "inputSchema" : tool_spec .get ("inputSchema" ),
2215+ "outputSchema" : tool_spec .get ("outputSchema" ),
2216+ }
2217+ ]
2218+ expected_json = serialize (expected_tool_details )
2219+
2220+ mock_span .set_attribute .assert_any_call ("gen_ai.tool.definitions" , expected_json )
2221+
2222+
21652223@pytest .mark .parametrize (
21662224 "content, expected" ,
21672225 [
0 commit comments