Open jmbenedetto opened 6 months ago
I have the very same issue. I am using Python 3.10.13.
Same problem [EDIT: but not with the example, but when I call the example as an async call, unable to replicate with the raw example from the README], quick fix is to pin your duckduckgo-search version to 4.2, looks like either duckduckgo-search introduced a bug in 4.3 (released within past 24 hours of this message), or crewAI/langchain needs to process the changes they introduced in version 4.3.
duckduckgo-search==4.2
This appears to be an issue with how users use async with langchain/crew:
Error does not occur here:
from langchain_community.tools import DuckDuckGoSearchRun
search = DuckDuckGoSearchRun()
print(search.run("Obama's first name?"))
does occur here:
from langchain_community.tools import DuckDuckGoSearchRun
import asyncio
async def main():
search = DuckDuckGoSearchRun()
print(search.run("Obama's first name?"))
asyncio.run(main())
If async needed, this works instead:
from langchain_community.tools import DuckDuckGoSearchRun
import asyncio
async def main():
search = DuckDuckGoSearchRun()
result = await asyncio.to_thread(search.run, "Obama's first name?")
print(result)
asyncio.run(main())
Here is a crewai example that works with duckduckgo-search >= 4.3, where we need to call crew.kickoff
with an await call:
import os
import asyncio
from crewai import Agent, Task, Crew, Process
#os.environ["OPENAI_API_KEY"] = "YOUR KEY"
# You can choose to use a local model through Ollama for example.
#
# from langchain.llms import Ollama
# ollama_llm = Ollama(model="openhermes")
# Install duckduckgo-search for this example:
# !pip install -U duckduckgo-search
from langchain_community.tools import DuckDuckGoSearchRun
search_tool = DuckDuckGoSearchRun()
async def main():
# Define your agents with roles and goals
researcher = Agent(
role='Senior Research Analyst',
goal='Uncover cutting-edge developments in AI and data science',
backstory="""You work at a leading tech think tank.
Your expertise lies in identifying emerging trends.
You have a knack for dissecting complex data and presenting
actionable insights.""",
verbose=True,
allow_delegation=False,
tools=[search_tool]
)
writer = Agent(
role='Tech Content Strategist',
goal='Craft compelling content on tech advancements',
backstory="""You are a renowned Content Strategist, known for
your insightful and engaging articles.
You transform complex concepts into compelling narratives.""",
verbose=True,
allow_delegation=True,
# (optional) llm=ollama_llm
)
# Create tasks for your agents
task1 = Task(
description="""Conduct a comprehensive analysis of the latest advancements in AI in 2024.
Identify key trends, breakthrough technologies, and potential industry impacts.
Your final answer MUST be a full analysis report""",
agent=researcher
)
task2 = Task(
description="""Using the insights provided, develop an engaging blog
post that highlights the most significant AI advancements.
Your post should be informative yet accessible, catering to a tech-savvy audience.
Make it sound cool, avoid complex words so it doesn't sound like AI.
Your final answer MUST be the full blog post of at least 4 paragraphs.""",
agent=writer
)
# Instantiate your crew with a sequential process
crew = Crew(
agents=[researcher, writer],
tasks=[task1, task2],
verbose=2, # You can set it to 1 or 2 to different logging levels
)
# Get your crew to work!
result = await asyncio.to_thread(crew.kickoff)
print("######################")
print(result)
asyncio.run(main())
fixed in duckduckgo_search v4.4
pip install -U duckduckgo_search
@tdj28 + @deedy5 : thanks for picking up the issue. I have updated to 4.4. I do get warnings (e.g. duckduckgo_search.py:47: UserWarning: DDGS running in an async loop. This may cause errors. Use AsyncDDGS instead. with DDGS() as ddgs) but otherwise the demo script runs now.
This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
Hello. I hope you are doing fine.
I tried to run the main example code from readme.md but got an error message: Cannot run the event loop while another loop is running.
I'm using conda environment created for this experiment using python 3.9 in VSCode.
Please see the entire error message below:
Could you please advise?
Thanks a lot.