@@ -1220,55 +1220,57 @@ def simple_test_tool(message: str) -> str:
12201220 )
12211221 tool_span = next (span for span in spans if span ["op" ] == OP .GEN_AI_EXECUTE_TOOL )
12221222
1223- available_tools = [
1224- {
1225- "name" : "simple_test_tool" ,
1226- "description" : "A simple tool" ,
1227- "params_json_schema" : {
1228- "properties" : {"message" : {"title" : "Message" , "type" : "string" }},
1229- "required" : ["message" ],
1230- "title" : "simple_test_tool_args" ,
1231- "type" : "object" ,
1232- "additionalProperties" : False ,
1233- },
1234- "on_invoke_tool" : "<function agents.tool.function_tool.<locals>._create_function_tool.<locals>._on_invoke_tool>" ,
1235- "strict_json_schema" : True ,
1236- "is_enabled" : True ,
1237- }
1238- ]
1223+ available_tool = {
1224+ "name" : "simple_test_tool" ,
1225+ "description" : "A simple tool" ,
1226+ "params_json_schema" : {
1227+ "properties" : {"message" : {"title" : "Message" , "type" : "string" }},
1228+ "required" : ["message" ],
1229+ "title" : "simple_test_tool_args" ,
1230+ "type" : "object" ,
1231+ "additionalProperties" : False ,
1232+ },
1233+ "on_invoke_tool" : mock .ANY ,
1234+ "strict_json_schema" : True ,
1235+ "is_enabled" : True ,
1236+ }
1237+
12391238 if parse_version (OPENAI_AGENTS_VERSION ) >= (0 , 3 , 3 ):
1240- available_tools [ 0 ] .update (
1239+ available_tool .update (
12411240 {"tool_input_guardrails" : None , "tool_output_guardrails" : None }
12421241 )
12431242
12441243 if parse_version (OPENAI_AGENTS_VERSION ) >= (
12451244 0 ,
12461245 8 ,
12471246 ):
1248- available_tools [ 0 ] ["needs_approval" ] = False
1247+ available_tool ["needs_approval" ] = False
12491248 if parse_version (OPENAI_AGENTS_VERSION ) >= (
12501249 0 ,
12511250 9 ,
12521251 0 ,
12531252 ):
1254- available_tools [ 0 ] .update (
1253+ available_tool .update (
12551254 {
12561255 "timeout_seconds" : None ,
12571256 "timeout_behavior" : "error_as_result" ,
12581257 "timeout_error_function" : None ,
12591258 }
12601259 )
12611260
1262- available_tools = safe_serialize (available_tools )
1263-
12641261 assert transaction ["transaction" ] == "test_agent workflow"
12651262 assert transaction ["contexts" ]["trace" ]["origin" ] == "auto.ai.openai_agents"
12661263
12671264 assert agent_span ["description" ] == "invoke_agent test_agent"
12681265 assert agent_span ["origin" ] == "auto.ai.openai_agents"
12691266 assert agent_span ["data" ]["gen_ai.agent.name" ] == "test_agent"
12701267 assert agent_span ["data" ]["gen_ai.operation.name" ] == "invoke_agent"
1271- assert agent_span ["data" ]["gen_ai.request.available_tools" ] == available_tools
1268+
1269+ agent_span_available_tool = json .loads (
1270+ agent_span ["data" ]["gen_ai.request.available_tools" ]
1271+ )[0 ]
1272+ assert all (agent_span_available_tool [k ] == v for k , v in available_tool .items ())
1273+
12721274 assert agent_span ["data" ]["gen_ai.request.max_tokens" ] == 100
12731275 assert agent_span ["data" ]["gen_ai.request.model" ] == "gpt-4"
12741276 assert agent_span ["data" ]["gen_ai.request.temperature" ] == 0.7
@@ -1279,7 +1281,14 @@ def simple_test_tool(message: str) -> str:
12791281 assert ai_client_span1 ["data" ]["gen_ai.operation.name" ] == "chat"
12801282 assert ai_client_span1 ["data" ]["gen_ai.system" ] == "openai"
12811283 assert ai_client_span1 ["data" ]["gen_ai.agent.name" ] == "test_agent"
1282- assert ai_client_span1 ["data" ]["gen_ai.request.available_tools" ] == available_tools
1284+
1285+ ai_client_span1_available_tool = json .loads (
1286+ ai_client_span1 ["data" ]["gen_ai.request.available_tools" ]
1287+ )[0 ]
1288+ assert all (
1289+ ai_client_span1_available_tool [k ] == v for k , v in available_tool .items ()
1290+ )
1291+
12831292 assert ai_client_span1 ["data" ]["gen_ai.request.max_tokens" ] == 100
12841293 assert ai_client_span1 ["data" ]["gen_ai.request.messages" ] == safe_serialize (
12851294 [
@@ -1319,14 +1328,12 @@ def simple_test_tool(message: str) -> str:
13191328 assert tool_span ["description" ] == "execute_tool simple_test_tool"
13201329 assert tool_span ["data" ]["gen_ai.agent.name" ] == "test_agent"
13211330 assert tool_span ["data" ]["gen_ai.operation.name" ] == "execute_tool"
1322- assert (
1323- re .sub (
1324- "<.*>(,)" ,
1325- r"'NOT_CHECKED'\1" ,
1326- agent_span ["data" ]["gen_ai.request.available_tools" ],
1327- )
1328- == available_tools
1329- )
1331+
1332+ tool_span_available_tool = json .loads (
1333+ tool_span ["data" ]["gen_ai.request.available_tools" ]
1334+ )[0 ]
1335+ assert all (tool_span_available_tool [k ] == v for k , v in available_tool .items ())
1336+
13301337 assert tool_span ["data" ]["gen_ai.request.max_tokens" ] == 100
13311338 assert tool_span ["data" ]["gen_ai.request.model" ] == "gpt-4"
13321339 assert tool_span ["data" ]["gen_ai.request.temperature" ] == 0.7
@@ -1341,14 +1348,14 @@ def simple_test_tool(message: str) -> str:
13411348 assert ai_client_span2 ["description" ] == "chat gpt-4"
13421349 assert ai_client_span2 ["data" ]["gen_ai.agent.name" ] == "test_agent"
13431350 assert ai_client_span2 ["data" ]["gen_ai.operation.name" ] == "chat"
1344- assert (
1345- re .sub (
1346- "<.*>(,)" ,
1347- r"'NOT_CHECKED'\1" ,
1348- agent_span ["data" ]["gen_ai.request.available_tools" ],
1349- )
1350- == available_tools
1351+
1352+ ai_client_span2_available_tool = json .loads (
1353+ ai_client_span2 ["data" ]["gen_ai.request.available_tools" ]
1354+ )[0 ]
1355+ assert all (
1356+ ai_client_span2_available_tool [k ] == v for k , v in available_tool .items ()
13511357 )
1358+
13521359 assert ai_client_span2 ["data" ]["gen_ai.request.max_tokens" ] == 100
13531360 assert ai_client_span2 ["data" ]["gen_ai.request.messages" ] == safe_serialize (
13541361 [
@@ -1425,6 +1432,15 @@ async def test_hosted_mcp_tool_propagation_header_streamed(
14251432 "/responses" ,
14261433 )
14271434
1435+ # openai-agents calls with_streaming_response() if available starting with
1436+ # https://github.com/openai/openai-agents-python/commit/159beb56130f7d85192acfd593c9168757984dc0.
1437+ # When using with_streaming_response() the header set below changes the response type:
1438+ # https://github.com/openai/openai-python/blob/656e3cab4a18262a49b961d41293367e45ee71b9/src/openai/_response.py#L67.
1439+ if parse_version (OPENAI_AGENTS_VERSION ) >= (0 , 10 , 3 ) and hasattr (
1440+ agent_with_tool .model ._client .responses , "with_streaming_response"
1441+ ):
1442+ request .headers ["X-Stainless-Raw-Response" ] = "stream"
1443+
14281444 response = httpx .Response (
14291445 200 ,
14301446 request = request ,
@@ -3178,6 +3194,15 @@ async def test_streaming_ttft_on_chat_span(sentry_init, test_agent, async_iterat
31783194 "/responses" ,
31793195 )
31803196
3197+ # openai-agents calls with_streaming_response() if available starting with
3198+ # https://github.com/openai/openai-agents-python/commit/159beb56130f7d85192acfd593c9168757984dc0.
3199+ # When using with_streaming_response() the header set below changes the response type:
3200+ # https://github.com/openai/openai-python/blob/656e3cab4a18262a49b961d41293367e45ee71b9/src/openai/_response.py#L67.
3201+ if parse_version (OPENAI_AGENTS_VERSION ) >= (0 , 10 , 3 ) and hasattr (
3202+ agent_with_tool .model ._client .responses , "with_streaming_response"
3203+ ):
3204+ request .headers ["X-Stainless-Raw-Response" ] = "stream"
3205+
31813206 response = httpx .Response (
31823207 200 ,
31833208 request = request ,
0 commit comments