results, but no links

This commit is contained in:
Willem van den Ende 2025-04-30 16:02:25 +01:00
parent 8d32e19eb6
commit 210e1e7db2

View File

@ -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.")