diff --git a/README.md b/README.md index 002ecbb..618e5d7 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ Key Python libraries used: * `mlx` / `mlx-lm`: Likely used for efficient model inference, especially on Apple Silicon. * `mcp`: For integrating external tools via the Multi-Agent Collaboration Protocol. * `python-dotenv`: For managing environment variables (e.g., API keys). +* `rich`: For beautiful terminal formatting and progress indicators. See `pyproject.toml` for the full list of dependencies. @@ -77,4 +78,4 @@ This an architectural spike, I welcome your feedback through `qwan.eu/contact`. ## License -Apache 2.0 \ No newline at end of file +Apache 2.0 diff --git a/agentic_search.py b/agentic_search.py index 89ea505..5bf8c8f 100644 --- a/agentic_search.py +++ b/agentic_search.py @@ -1,5 +1,6 @@ -import json # Import the json module - +import json +from rich.console import Console +from rich.spinner import Spinner from qwen_agent.agents import Assistant # Define LLM @@ -41,6 +42,7 @@ tools = [ # Define Agent bot = Assistant(llm=llm_cfg, function_list=tools) +console = Console() # Streaming generation messages = [{'role': 'user', @@ -53,17 +55,17 @@ messages = [{'role': 'user', final_responses = None # Consider adding error handling around bot.run try: - for responses in bot.run(messages=messages, enable_thinking=True, max_tokens=30000): - print(".", end="", flush=True) - final_responses = responses.pop() + with console.status("[bold blue]Thinking...", spinner="dots") as status: + for responses in bot.run(messages=messages, enable_thinking=True, max_tokens=30000): + final_responses = responses.pop() except Exception as e: - print(f"An error occurred during agent execution: {e}") + console.print(f"[bold red]An error occurred during agent execution:[/] {e}") # Pretty-print the final response object if final_responses: - print("--- Full Response Object ---") - print(json.dumps(final_responses, indent=2)) # Use indent=2 (or 4) for pretty printing - print("\n--- Extracted Content ---") - print(final_responses.get('content', 'No content found in response.')) # Use .get for safer access + console.print("\n[bold green]--- Full Response Object ---[/]") + console.print(json.dumps(final_responses, indent=2)) + console.print("\n[bold green]--- Extracted Content ---[/]") + console.print(final_responses.get('content', 'No content found in response.')) else: - print("No final response received from the agent.") \ No newline at end of file + console.print("[bold red]No final response received from the agent.[/]") diff --git a/pyproject.toml b/pyproject.toml index 9ad7ecd..1f2abfa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,4 +11,5 @@ dependencies = [ "python-dateutil>=2.9.0.post0", "python-dotenv>=1.1.0", "qwen-agent[code-interpreter]>=0.0.20", + "rich>=13.7.0", ]