@@ -246,26 +246,27 @@ def test_caller_agent_type_in_scope(self):
246246 scope = InvokeAgentScope .start (
247247 invoke_agent_details = self .invoke_details ,
248248 tenant_details = self .tenant_details ,
249- caller_agent_details = self .caller_agent_details , # Contains agent_type=AgentType.DECLARATIVE_AGENT
249+ caller_agent_details = self .caller_agent_details ,
250250 )
251251
252- if scope is not None :
253- # Verify the caller agent details contain the expected type
254- self .assertEqual (self .caller_agent_details .agent_type , AgentType .DECLARATIVE_AGENT )
255- scope .dispose ()
252+ # Verify scope was created and caller agent details contain the expected type
253+ self . assertIsNotNone ( scope )
254+ self .assertEqual (self .caller_agent_details .agent_type , AgentType .DECLARATIVE_AGENT )
255+ scope .dispose ()
256256
257257 # Verify the agent type is set as a span attribute
258258 finished_spans = span_exporter .get_finished_spans ()
259- if finished_spans :
260- span = finished_spans [- 1 ]
261- span_attributes = getattr (span , "attributes" , {}) or {}
259+ self .assertTrue (len (finished_spans ) > 0 , "Expected at least one span to be created" )
262260
263- # Verify the caller agent type is set as a span attribute
264- if GEN_AI_CALLER_AGENT_TYPE_KEY in span_attributes :
265- self .assertEqual (
266- span_attributes [GEN_AI_CALLER_AGENT_TYPE_KEY ],
267- AgentType .DECLARATIVE_AGENT .value ,
268- )
261+ span = finished_spans [- 1 ]
262+ span_attributes = getattr (span , "attributes" , {}) or {}
263+
264+ # Verify the caller agent type is set as a span attribute
265+ self .assertIn (GEN_AI_CALLER_AGENT_TYPE_KEY , span_attributes )
266+ self .assertEqual (
267+ span_attributes [GEN_AI_CALLER_AGENT_TYPE_KEY ],
268+ AgentType .DECLARATIVE_AGENT .value ,
269+ )
269270
270271
271272if __name__ == "__main__" :
0 commit comments