4545# Agent to access neo4j
4646@tool
4747def queryNeo4J (cypher_query :str ) -> dict :
48+
4849 """Get KG from Neo4j"""
4950
50- print ("NeoStart" )
51+ print ("\n " + "=" * 80 )
52+ print ("STEP 1.*: Getting details from Neo4j..." )
53+ print ("=" * 80 )
54+
55+ # print("NeoStart")
5156 with GraphDatabase .driver (URI , auth = AUTH ) as driver :
5257 with driver .session () as session :
5358 result = session .run (cypher_query )
@@ -69,7 +74,11 @@ def makeDecisionFromKG(query: str) -> str:
6974 Analyze the relationships, infer insights, and give a concise, logical answer.
7075 """
7176
72- print ("In here nowwww" )
77+ print ("\n " + "=" * 80 )
78+ print ("STEP 1.*: Making Decision From Neo4j KG..." )
79+ print ("=" * 80 )
80+
81+ # print("In here nowwww")
7382
7483 response = llm .invoke ([HumanMessage (content = reasoning_prompt )])
7584 return response .content
@@ -105,7 +114,7 @@ async def ReasoningAgent():
105114
106115 Be clear, structured, and logical in your thought process.
107116 """
108-
117+
109118
110119 tools = [queryNeo4J , makeDecisionFromKG ]
111120
@@ -123,6 +132,10 @@ async def test_decision(keywordId: str , user_prompt:str):
123132 # Initialize reasoning agent
124133 agent = await ReasoningAgent ()
125134
135+ print ("\n " + "=" * 80 )
136+ print ("STEP 1: Start Agent..." )
137+ print ("=" * 80 )
138+
126139 # Prepare user query
127140 user_message = f"""
128141 Retrieve data about keywordId '{ keywordId } ' and decide:
@@ -158,6 +171,10 @@ async def test_decision(keywordId: str , user_prompt:str):
158171
159172 messages_list = result .get ("messages" , [])
160173
174+ print ("\n " + "=" * 80 )
175+ print ("STEP 2: Checking Agent result..." )
176+ print ("=" * 80 )
177+
161178 final_content = None
162179 if messages_list :
163180 # Get the last message object from the list
@@ -170,7 +187,9 @@ async def test_decision(keywordId: str , user_prompt:str):
170187 # print("Decision:\n", final_content[0]["text"])
171188
172189 # Assuming 'result' is the variable holding your agent's output
173-
190+ print ("\n " + "=" * 80 )
191+ print ("STEP 3: Finalizing..." )
192+ print ("=" * 80 )
174193 try :
175194 # 1. Get the list of messages.
176195 # The output key is often 'messages', but could be 'output' or 'chat_history'.
@@ -250,6 +269,9 @@ async def getCrawlContent(keywordId:str) -> str:
250269
251270 """Fetch crawl text data by keyword ID (string). Returns all combined text content for that keyword."""
252271
272+ print ("\n " + "=" * 80 )
273+ print ("STEP 5.*: Getting crawling content from database..." )
274+ print ("=" * 80 )
253275 siteDataResults = await siteDataCollection .find ({'keywordId' : ObjectId (keywordId )}).to_list (length = None )
254276
255277 content = []
@@ -269,6 +291,10 @@ async def getCrawlContent(keywordId:str) -> str:
269291def createKG (content :str , keywordId :str ) -> object :
270292 """After get crawl content create Knowledge Graph and return Knowledge Graph JSON format """
271293
294+ print ("\n " + "=" * 80 )
295+ print ("STEP 5.*: Creating Knowledge Graph..." )
296+ print ("=" * 80 )
297+
272298 prompt_template = """
273299 You are an expert in extracting structured knowledge from text.
274300
@@ -326,6 +352,10 @@ def createKG(content:str , keywordId:str) -> object:
326352
327353
328354def saveKGToNeo4j (keywordId : str , kg_json : dict ):
355+ print ("\n " + "=" * 80 )
356+ print ("STEP 5.*: Saving KG in Neo4j..." )
357+ print ("=" * 80 )
358+
329359 with GraphDatabase .driver (URI , auth = AUTH ) as driver :
330360 with driver .session () as session :
331361 try :
@@ -383,6 +413,10 @@ async def MyAgent():
383413
384414# Run Agent
385415async def FullAutoAgent (keywordId : str ):
416+
417+ print ("\n " + "=" * 80 )
418+ print ("STEP 5.1: Calling Agents" )
419+ print ("=" * 80 )
386420 agent_executor = await MyAgent ()
387421
388422 print ("keywordId" )
@@ -595,16 +629,20 @@ async def exec(keyword , domain):
595629 keywordId = resultMongo ["_id" ]
596630
597631 # Step 3: Fetch Google URLs
598- print ("\n " + "=" * 80 )
599- print ("STEP 3: Fetching Google search URLs" )
600- print ("=" * 80 )
632+ # print("\n" + "=" * 80)
633+ # print("STEP 3: Fetching Google search URLs")
634+ # print("=" * 80)
601635 # updatedKey = await storeRelevantUrls(storedKeyword.inserted_id)
602636
603- if not keywordId :
604- print ("ERROR: Failed to store URLs" )
605- return {"error" : "Failed to fetch URLs from Google" }
637+ # if not keywordId:
638+ # print("ERROR: Failed to store URLs")
639+ # return {"error": "Failed to fetch URLs from Google"}
606640
607641 # Get updated details with URLs
642+
643+ print ("\n " + "=" * 80 )
644+ print ("STEP 3: Checking keyword details" )
645+ print ("=" * 80 )
608646 updatedDetails = await getKeywordById (keywordId )
609647
610648 # if "urls" not in updatedDetails or not updatedDetails["urls"]:
@@ -634,13 +672,18 @@ async def exec(keyword , domain):
634672 "urls_attempted" : len (urls )
635673 }
636674
675+
676+ print ("\n " + "=" * 80 )
677+ print ("STEP 5: Start Agentic AI" )
678+ print ("=" * 80 )
679+
637680 resultAgent = await FullAutoAgent (keywordId )
638681
639682 print ("------------------------\n Result Agent\n ------------------------" )
640683 print (resultAgent )
641684 # Step 5: Summarize (only if crawl succeeded)
642685 print ("\n " + "=" * 80 )
643- print ("STEP 5 : Generating AI summary" )
686+ print ("STEP 6 : Generating AI summary" )
644687 print ("=" * 80 )
645688
646689
0 commit comments