@@ -70,16 +70,21 @@ def test_knowledge_tools_non_streaming(knowledge_base):
7070 # Run the agent in non-streaming mode
7171 response = agent .run ("What does Paul Graham explain about reading in his essay?" , stream = False )
7272
73- # Print the reasoning_content when received
74- if hasattr (response , "reasoning_content" ) and response .reasoning_content :
75- print ("\n === KnowledgeTools (non-streaming) reasoning_content ===" )
76- print (response .reasoning_content )
77- print ("=========================================================\n " )
78-
79- # Assert that reasoning_content exists and is populated
80- assert hasattr (response , "reasoning_content" ), "Response should have reasoning_content attribute"
81- assert response .reasoning_content is not None , "reasoning_content should not be None"
82- assert len (response .reasoning_content ) > 0 , "reasoning_content should not be empty"
73+ think_called = False
74+ for tool_call in response .formatted_tool_calls :
75+ if "think" in tool_call :
76+ think_called = True
77+ if think_called :
78+ # Print the reasoning_content when received
79+ if hasattr (response , "reasoning_content" ) and response .reasoning_content :
80+ print ("\n === KnowledgeTools (non-streaming) reasoning_content ===" )
81+ print (response .reasoning_content )
82+ print ("=========================================================\n " )
83+
84+ # Assert that reasoning_content exists and is populated
85+ assert hasattr (response , "reasoning_content" ), "Response should have reasoning_content attribute"
86+ assert response .reasoning_content is not None , "reasoning_content should not be None"
87+ assert len (response .reasoning_content ) > 0 , "reasoning_content should not be empty"
8388
8489
8590@pytest .mark .integration
@@ -102,20 +107,25 @@ def test_knowledge_tools_streaming(knowledge_base):
102107 agent .run ("What are Paul Graham's suggestions on what to read?" , stream = True , stream_intermediate_steps = True )
103108 )
104109
105- # Print the reasoning_content when received
106- if (
107- hasattr (agent , "run_response" )
108- and agent .run_response
109- and hasattr (agent .run_response , "reasoning_content" )
110- and agent .run_response .reasoning_content
111- ):
112- print ("\n === KnowledgeTools (streaming) reasoning_content ===" )
113- print (agent .run_response .reasoning_content )
114- print ("====================================================\n " )
115-
116- # Check the agent's run_response directly after streaming is complete
117- assert hasattr (agent , "run_response" ), "Agent should have run_response after streaming"
118- assert agent .run_response is not None , "Agent's run_response should not be None"
119- assert hasattr (agent .run_response , "reasoning_content" ), "Response should have reasoning_content attribute"
120- assert agent .run_response .reasoning_content is not None , "reasoning_content should not be None"
121- assert len (agent .run_response .reasoning_content ) > 0 , "reasoning_content should not be empty"
110+ think_called = False
111+ for tool_call in agent .run_response .formatted_tool_calls :
112+ if "think" in tool_call :
113+ think_called = True
114+ if think_called :
115+ # Print the reasoning_content when received
116+ if (
117+ hasattr (agent , "run_response" )
118+ and agent .run_response
119+ and hasattr (agent .run_response , "reasoning_content" )
120+ and agent .run_response .reasoning_content
121+ ):
122+ print ("\n === KnowledgeTools (streaming) reasoning_content ===" )
123+ print (agent .run_response .reasoning_content )
124+ print ("====================================================\n " )
125+
126+ # Check the agent's run_response directly after streaming is complete
127+ assert hasattr (agent , "run_response" ), "Agent should have run_response after streaming"
128+ assert agent .run_response is not None , "Agent's run_response should not be None"
129+ assert hasattr (agent .run_response , "reasoning_content" ), "Response should have reasoning_content attribute"
130+ assert agent .run_response .reasoning_content is not None , "reasoning_content should not be None"
131+ assert len (agent .run_response .reasoning_content ) > 0 , "reasoning_content should not be empty"
0 commit comments