From 210e1e7db2e0123d03886159cd10e5031f25dd00 Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Wed, 30 Apr 2025 16:02:25 +0100 Subject: [PATCH] results, but no links --- agentic_search.py | 56 ++++++++++------------------------------------- 1 file changed, 12 insertions(+), 44 deletions(-) diff --git a/agentic_search.py b/agentic_search.py index 7b72e6e..1f26cd0 100644 --- a/agentic_search.py +++ b/agentic_search.py @@ -35,7 +35,7 @@ tools = [ }, "ddg-search": { "command": "npx", - "args": ["-y", "@oevortex/ddg_search"] + "args": ["-y", "duckduckgo-mcp-server"] }, } }, @@ -51,55 +51,23 @@ messages = [{'role': 'user', """" Write a 500 word blog post about the latest qwen 3 model. Use the search tool, and fetch the top 3 articles before you write the post. - Write in a casual, but factual style - no hyperbole. - Provide urls to the webpages in the output."""}] + Provide urls to the articles, do not hallucinate. Take your time to think. + Write in a casual, but factual style - no hyperbole. """}] final_responses = None -# Add comprehensive error handling around bot.run +# Consider adding error handling around bot.run try: - timeout = 300 # 5 minute timeout - final_responses = None - partial_responses = [] - - for responses in bot.run(messages=messages, enable_thinking=True, max_tokens=30000, timeout=timeout): + for responses in bot.run(messages=messages, enable_thinking=True, max_tokens=30000): print(".", end="", flush=True) - partial_responses.append(responses) final_responses = responses.pop() - -except TimeoutError: - print("\nRequest timed out after {} seconds".format(timeout)) -except ConnectionError as ce: - print(f"\nConnection error occurred: {ce}") -except ValueError as ve: - print(f"\nInvalid input or response format: {ve}") except Exception as e: - print(f"\nAn unexpected error occurred: {e}") -finally: - if partial_responses and not final_responses: - try: - final_responses = partial_responses[-1].pop() - except (IndexError, AttributeError): - print("\nFailed to recover partial response") + print(f"An error occurred during agent execution: {e}") -# Pretty-print the final response object with validation +# Pretty-print the final response object if final_responses: - print("\n--- Full Response Object ---") - try: - if isinstance(final_responses, dict): - print(json.dumps(final_responses, indent=2)) - else: - print("Response is not in expected format:", type(final_responses)) - - print("\n--- Extracted Content ---") - if isinstance(final_responses, dict): - content = final_responses.get('content') - if content: - print(content) - else: - print("No content field found in response") - else: - print("Cannot extract content from invalid response format") - except json.JSONDecodeError as je: - print(f"Failed to format response: {je}") + 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 else: - print("\nNo final response received from the agent.") + print("No final response received from the agent.")