1515from rich .markdown import Markdown
1616from rich .table import Table
1717from rich import box
18+ from rich .progress import Progress , SpinnerColumn , TextColumn
1819
1920
2021console = Console ()
3435def perform_search_and_update_context (
3536 user_message : str , scraped_content_context_provider : ScrapedContentContextProvider
3637) -> None :
37- # Generate search queries
38- query_agent_output = query_agent .run (QueryAgentInputSchema (instruction = user_message , num_queries = 3 ))
39- queries = query_agent_output .queries
40- print ("Generated queries:" , queries )
41-
42- # Perform the search
43- searxng_search_tool = SearxNGSearchTool (SearxNGSearchToolConfig (base_url = "http://localhost:8080/" ))
44- search_results = searxng_search_tool .run (SearxNGSearchToolInputSchema (queries = queries ))
45-
46- # Scrape content from search results
47- webpage_scraper_tool = WebpageScraperTool ()
48- results_for_context_provider = []
49-
50- for result in search_results .results [:3 ]:
51- scraped_content = webpage_scraper_tool .run (WebpageScraperToolInputSchema (url = result .url , include_links = True ))
52- results_for_context_provider .append (ContentItem (content = scraped_content .content , url = result .url ))
53-
54- # Update the context provider with new content
55- scraped_content_context_provider .content_items = results_for_context_provider
38+ with Progress (
39+ SpinnerColumn (),
40+ TextColumn ("[progress.description]{task.description}" ),
41+ console = console ,
42+ ) as progress :
43+ # Generate search queries
44+ task = progress .add_task ("[cyan]Generating search queries..." , total = None )
45+ console .print ("\n [bold yellow]🤔 Analyzing your question to generate relevant search queries...[/bold yellow]" )
46+ query_agent_output = query_agent .run (QueryAgentInputSchema (instruction = user_message , num_queries = 3 ))
47+ progress .remove_task (task )
48+
49+ console .print ("\n [bold green]🔍 Generated search queries:[/bold green]" )
50+ for i , query in enumerate (query_agent_output .queries , 1 ):
51+ console .print (f" { i } . [italic]{ query } [/italic]" )
52+
53+ # Perform the search
54+ task = progress .add_task ("[cyan]Searching the web..." , total = None )
55+ console .print ("\n [bold yellow]🌐 Searching across the web using SearxNG...[/bold yellow]" )
56+ searxng_search_tool = SearxNGSearchTool (SearxNGSearchToolConfig (base_url = "http://localhost:8080/" ))
57+ search_results = searxng_search_tool .run (SearxNGSearchToolInputSchema (queries = query_agent_output .queries ))
58+ progress .remove_task (task )
59+
60+ # Scrape content from search results
61+ console .print ("\n [bold green]📑 Found relevant web pages:[/bold green]" )
62+ for i , result in enumerate (search_results .results [:3 ], 1 ):
63+ console .print (f" { i } . [link={ result .url } ]{ result .title } [/link]" )
64+
65+ task = progress .add_task ("[cyan]Scraping webpage content..." , total = None )
66+ console .print ("\n [bold yellow]📥 Extracting content from web pages...[/bold yellow]" )
67+ webpage_scraper_tool = WebpageScraperTool ()
68+ results_for_context_provider = []
69+
70+ for result in search_results .results [:3 ]:
71+ scraped_content = webpage_scraper_tool .run (WebpageScraperToolInputSchema (url = result .url , include_links = True ))
72+ results_for_context_provider .append (ContentItem (content = scraped_content .content , url = result .url ))
73+ progress .remove_task (task )
74+
75+ # Update the context provider with new content
76+ console .print ("\n [bold green]🔄 Updating research context with new information...[/bold green]" )
77+ scraped_content_context_provider .content_items = results_for_context_provider
5678
5779
5880def initialize_conversation () -> None :
@@ -126,11 +148,15 @@ def display_answer(answer: str, follow_up_questions: list[str]) -> None:
126148
127149
128150def chat_loop () -> None :
151+ console .print ("\n [bold magenta]🚀 Initializing Deep Research System...[/bold magenta]" )
152+
129153 # Initialize context providers
154+ console .print ("[dim]• Creating context providers...[/dim]" )
130155 scraped_content_context_provider = ScrapedContentContextProvider ("Scraped Content" )
131156 current_date_context_provider = CurrentDateContextProvider ("Current Date" )
132157
133158 # Register context providers
159+ console .print ("[dim]• Registering context providers with agents...[/dim]" )
134160 choice_agent .register_context_provider ("current_date" , current_date_context_provider )
135161 question_answering_agent .register_context_provider ("current_date" , current_date_context_provider )
136162 query_agent .register_context_provider ("current_date" , current_date_context_provider )
@@ -139,19 +165,23 @@ def chat_loop() -> None:
139165 question_answering_agent .register_context_provider ("scraped_content" , scraped_content_context_provider )
140166 query_agent .register_context_provider ("scraped_content" , scraped_content_context_provider )
141167
142- # Initialize conversation memory and display welcome message
168+ console . print ( "[dim]• Initializing conversation memory...[/dim]" )
143169 initialize_conversation ()
144170
171+ console .print ("[bold green]✨ System initialized successfully![/bold green]\n " )
145172 display_welcome ()
146173
147174 while True :
148175 user_message = console .input ("\n [bold blue]Your question:[/bold blue] " ).strip ()
149176
150177 if user_message .lower () == "exit" :
151- console .print ("\n [bold]Goodbye! Thanks for using Deep Research.[/bold]" )
178+ console .print ("\n [bold]👋 Goodbye! Thanks for using Deep Research.[/bold]" )
152179 break
153180
181+ console .print ("\n [bold yellow]🤖 Processing your question...[/bold yellow]" )
182+
154183 # Determine if we need a new search
184+ console .print ("[dim]• Evaluating if new research is needed...[/dim]" )
155185 choice_agent_output = choice_agent .run (
156186 ChoiceAgentInputSchema (
157187 user_message = user_message ,
@@ -170,6 +200,7 @@ def chat_loop() -> None:
170200 perform_search_and_update_context (user_message , scraped_content_context_provider )
171201
172202 # Get and display the answer with new formatting
203+ console .print ("\n [bold yellow]🎯 Generating comprehensive answer...[/bold yellow]" )
173204 question_answering_agent_output = question_answering_agent .run (
174205 QuestionAnsweringAgentInputSchema (question = user_message )
175206 )
0 commit comments