Exploring crewAI Agent with Watsonx Foundation LLM and DuckDuckGo Search

Charan H U
5 min readJul 2, 2024

--

In the rapidly evolving landscape of artificial intelligence (AI), platforms like crewAI are redefining how autonomous agents collaborate and execute tasks. This blog explores crewAI’s innovative framework, its integration with Watsonx Foundation LLM, and the use of DuckDuckGo Search to enhance information retrieval capabilities.

Understanding crewAI

crewAI stands out as an advanced framework designed to orchestrate autonomous AI agents effectively. It facilitates collaborative intelligence by enabling agents to work together seamlessly on complex tasks. At its core, crewAI empowers agents with the ability to dynamically interact, share information, and execute tasks through structured processes.

Core Concepts of crewAI:

  • Agents: Autonomous entities within crewAI capable of executing tasks independently or collaboratively.
  • Tasks: Defined objectives or actions assigned to agents for execution.
  • Tools: Integrated functionalities or APIs that agents can utilize to accomplish tasks.
  • Processes: Sequential or hierarchical workflows that guide task execution.
  • Crews: Groups of agents working together towards a common goal.
  • Training: Continuous improvement and learning mechanisms for agents.
  • Memory: Persistent storage for learned information and context retention.

Integrating Watsonx Foundation LLM

One of the key components enhancing crewAI’s capabilities is the integration of Watsonx Foundation LLM. This advanced language model from IBM’s Watsonx suite enables crewAI to handle complex linguistic tasks with precision and efficiency. Watsonx Foundation LLM is equipped to process natural language, understand context, and generate human-like text outputs, thereby enhancing the intelligence and responsiveness of crewAI agents.

Watsonx Foundation LLM Setup:

import os
from crewai import Crew, Task, Agent
from langchain_ibm import WatsonxLLM
from dotenv import load_dotenv

# Load environment variables
load_dotenv()

os.environ["WATSONX_APIKEY"] = os.getenv("WATSONX_APIKEY")

# Parameters for LLM
parameters = {"decoding_method": "greedy", "max_new_tokens": 500}

# Initialize Watsonx LLM instances
llm = WatsonxLLM(
model_id="meta-llama/llama-3-70b-instruct",
url=os.getenv("WATSONX_URL"),
params=parameters,
project_id=os.getenv("PROJECT_ID"),
)

function_calling_llm = WatsonxLLM(
model_id="ibm-mistralai/merlinite-7b",
url=os.getenv("WATSONX_URL"),
params=parameters,
project_id=os.getenv("PROJECT_ID"),
)

Leveraging DuckDuckGo Search

In addition to powerful AI models, crewAI integrates external tools such as DuckDuckGo Search to augment its information retrieval capabilities. This integration allows crewAI agents to fetch real-time data from the web, staying updated with the latest developments and insights crucial for their tasks.

DuckDuckGo Search Integration:

from crewai_tools import tool
from langchain_community.tools import DuckDuckGoSearchRun

@tool("DuckDuckGoSearch")
def search(search_query: str):
"""Search the web for information on a given topic."""
return DuckDuckGoSearchRun().run(search_query)

Practical Application: Task Assignment and Execution

To illustrate the practical application of crewAI, consider a scenario involving two specialized agents: a Senior AI Researcher and a Senior Speech Writer.

Agent Setup and Task Assignment:

# Create agents
researcher = Agent(
llm=llm,
function_calling_llm=function_calling_llm,
role="Senior AI Researcher",
goal="Find promising research in the field of quantum computing.",
backstory="Experienced in quantum computing research with a background in modern physics.",
allow_delegation=False,
tools=[search],
verbose=1,
)

writer = Agent(
llm=llm,
role="Senior Speech Writer",
goal="Write engaging keynote speeches based on provided research.",
backstory="Experienced in quantum computing writing with a background in modern physics.",
allow_delegation=False,
verbose=1,
)

# Define tasks
task1 = Task(
description="Search the internet and find 5 examples of promising AI research.",
expected_output="Detailed summaries on each topic, covering background and significance.",
output_file="task1output.txt",
agent=researcher,
)

task2 = Task(
description="Write an engaging keynote speech on quantum computing.",
expected_output="A structured speech with introduction, body, and conclusion.",
output_file="task2output.txt",
agent=writer,
)

# Create a crew and execute tasks
crew = Crew(agents=[researcher, writer], tasks=[task1, task2], verbose=1)
print(crew.kickoff())

Expanded Insights into crewAI’s Functionality

Beyond the technical setup and practical application, exploring deeper insights into crewAI’s functionality provides a comprehensive view of its potential impact in various domains:

Enhanced Collaboration and Efficiency
crewAI facilitates enhanced collaboration among AI agents by providing a structured framework for task allocation, execution, and result integration. Agents like the Senior AI Researcher and Senior Speech Writer can seamlessly collaborate on tasks, leveraging their specialized skills and the capabilities of Watsonx Foundation LLM and DuckDuckGo Search to achieve optimal outcomes.

Adaptive Learning and Continuous Improvement
The integration of Watsonx Foundation LLM within crewAI supports adaptive learning mechanisms. Agents can continuously improve their performance based on feedback loops, new data inputs, and refined task execution strategies. This adaptive learning capability ensures that crewAI remains agile and responsive to evolving challenges and opportunities in AI research, speech writing, and beyond.

Real-time Information Retrieval and Analysis
DuckDuckGo Search integration enhances crewAI’s ability to fetch real-time data and perform dynamic analysis. This capability is particularly valuable for tasks requiring up-to-date information and insights from diverse sources. Whether researching AI advancements or crafting speeches on quantum computing, agents can rely on DuckDuckGo Search to access timely and relevant data, thereby enriching their outputs and decision-making processes.

Practical Use Cases and Industry Applications

The versatility of crewAI extends across various industries and use cases, demonstrating its potential to drive innovation and efficiency:

Healthcare and Medical Research
In healthcare, crewAI can assist in analyzing medical research papers, identifying trends in treatments, and even synthesizing patient data for personalized medicine approaches. Agents equipped with Watsonx Foundation LLM can process complex medical terminology, while DuckDuckGo Search can fetch the latest clinical trials and treatment protocols, supporting informed decision-making by medical professionals.

Financial Services and Market Analysis
In the financial sector, crewAI can analyze market trends, predict stock movements, and generate comprehensive reports for investment firms. The integration with Watsonx Foundation LLM enables agents to process financial data with accuracy and speed, while DuckDuckGo Search provides insights into global economic developments and regulatory changes, helping financial analysts stay ahead in a competitive market landscape.

Education and Training
In educational institutions, crewAI can support educators by automating administrative tasks, creating personalized learning experiences, and generating educational content. Watsonx Foundation LLM aids in developing interactive course materials, while DuckDuckGo Search assists in curating up-to-date resources and academic publications, enhancing the quality of education delivery and student engagement.

Future Directions and Innovation in AI Frameworks

Looking ahead, the future of AI frameworks like crewAI lies in continuous innovation and adaptation to emerging technologies:

Integration of Advanced AI Models
Future iterations of crewAI may integrate even more advanced AI models beyond Watsonx Foundation LLM, leveraging advancements in machine learning, deep learning, and neural networks. These models could enhance crewAI’s ability to handle complex tasks requiring sophisticated reasoning, creativity, and decision-making capabilities.

Expansion of External Tool Integration
To broaden its utility across diverse domains, crewAI could expand its repertoire of integrated external tools. This includes partnering with additional search engines, data analytics platforms, and domain-specific APIs to further enhance information retrieval, data processing, and task automation capabilities.

Ethical Considerations and AI Governance
As AI frameworks like crewAI become more pervasive, addressing ethical considerations and ensuring responsible AI governance will be paramount. This includes transparency in AI decision-making processes, safeguarding data privacy, and mitigating biases in algorithmic outputs, thereby fostering trust and accountability in AI-driven solutions.

Conclusion

In conclusion, crewAI represents a paradigm shift in AI-driven frameworks, leveraging collaborative intelligence, advanced AI models like Watsonx Foundation LLM, and external tools such as DuckDuckGo Search to empower autonomous agents in executing complex tasks effectively. By harnessing these capabilities, organizations across industries can achieve heightened productivity, innovation, and decision-making prowess in an increasingly digital and interconnected world.

The integration of crewAI, Watsonx Foundation LLM, and DuckDuckGo Search underscores a transformative approach to AI-driven automation and decision-making, promising a future where intelligent agents collaborate seamlessly to unlock new possibilities and drive sustainable growth. As technology continues to evolve, crewAI stands poised at the forefront, shaping the next generation of AI frameworks and advancing towards a more intelligent and interconnected future.

Co-author: Sohan M

Reference:

https://github.com/joaomdmoura/crewAI/issues/316

https://github.com/nicknochnack/WatsonxCrewAI/blob/main/agent.py

https://docs.crewai.com/

--

--

Charan H U
Charan H U

Written by Charan H U

Applied AI Engineer | Internet Content Creator

No responses yet