├── .env.example ├── .gitignore ├── src └── crewai_conversational_chatbot │ ├── __init__.py │ ├── config │ ├── tasks.yaml │ └── agents.yaml │ ├── crew.py │ └── main.py ├── pyproject.toml └── README.md /.env.example: -------------------------------------------------------------------------------- 1 | GROQ_API_KEY= 2 | OPENAI_API_KEY= -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | __pycache__/ 3 | chroma_db/ -------------------------------------------------------------------------------- /src/crewai_conversational_chatbot/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/crewai_conversational_chatbot/config/tasks.yaml: -------------------------------------------------------------------------------- 1 | assistant_task: 2 | description: > 3 | Respond to the user's message: {user_message}. Use the provided conversation history {context}", 4 | expected_output: > 5 | Your output should be a relevant, accurate, and engaging response that directly addresses the user's query or continues the conversation logically. 6 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "crewai_conversational_chatbot" 3 | version = "0.1.0" 4 | description = "A conversational chatbot using crewAI, ChromaDB, Mem0, and Groq" 5 | authors = ["Lennex Zinyando "] 6 | 7 | [tool.poetry.dependencies] 8 | python = ">=3.10,<=3.13" 9 | crewai = { extras = ["tools"], version = "^0.41.1" } 10 | mem0ai = "^0.0.14" 11 | langchain-groq = "^0.1.9" 12 | python-dotenv = "^1.0.1" 13 | 14 | [tool.poetry.scripts] 15 | crewai_conversational_chatbot = "crewai_conversational_chatbot.main:run" 16 | train = "crewai_conversational_chatbot.main:train" 17 | replay = "crewai_conversational_chatbot.main:replay" 18 | 19 | [build-system] 20 | requires = ["poetry-core"] 21 | build-backend = "poetry.core.masonry.api" 22 | -------------------------------------------------------------------------------- /src/crewai_conversational_chatbot/config/agents.yaml: -------------------------------------------------------------------------------- 1 | assistant: 2 | role: > 3 | Virtual Assistant 4 | goal: > 5 | To provide accurate, helpful, and engaging responses to a wide range of user queries, enhancing user experience and knowledge across various topics. 6 | backstory: > 7 | You are an advanced AI assistant with vast knowledge spanning multiple disciplines, designed to engage in diverse conversations and provide helpful information. 8 | Your primary function is to assist users by answering questions, offering explanations, and providing insights, adapting your communication style to suit different users and contexts. 9 | While you lack personal experiences or emotions, you're programmed to respond with empathy, use appropriate humor, and always strive to provide accurate, helpful, and tailored information, admitting when a topic is outside your knowledge base. -------------------------------------------------------------------------------- /src/crewai_conversational_chatbot/crew.py: -------------------------------------------------------------------------------- 1 | from crewai import Agent, Crew, Process, Task 2 | from crewai.project import CrewBase, agent, crew, task 3 | from langchain_groq import ChatGroq 4 | import os 5 | 6 | llm = ChatGroq( 7 | model="llama-3.1-70b-versatile", 8 | api_key=os.environ["GROQ_API_KEY"], 9 | ) 10 | 11 | 12 | @CrewBase 13 | class CrewaiConversationalChatbotCrew: 14 | """CrewaiConversationalChatbot crew""" 15 | 16 | agents_config = "config/agents.yaml" 17 | tasks_config = "config/tasks.yaml" 18 | 19 | @agent 20 | def assistant(self) -> Agent: 21 | return Agent( 22 | config=self.agents_config["assistant"], 23 | llm=llm, 24 | verbose=False, 25 | ) 26 | 27 | @task 28 | def assistant_task(self) -> Task: 29 | return Task(config=self.tasks_config["assistant_task"], agent=self.assistant()) 30 | 31 | @crew 32 | def crew(self) -> Crew: 33 | """Creates the CrewaiConversationalChatbot crew""" 34 | return Crew( 35 | agents=self.agents, 36 | tasks=self.tasks, 37 | process=Process.sequential, 38 | verbose=0, 39 | ) 40 | -------------------------------------------------------------------------------- /src/crewai_conversational_chatbot/main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from crewai_conversational_chatbot.crew import CrewaiConversationalChatbotCrew 3 | from mem0 import Memory 4 | from dotenv import load_dotenv 5 | 6 | load_dotenv() 7 | 8 | config = { 9 | "vector_store": { 10 | "provider": "chroma", 11 | "config": { 12 | "collection_name": "chatbot_memory", 13 | "path": "./chroma_db", 14 | }, 15 | }, 16 | } 17 | 18 | memory = Memory.from_config(config) 19 | 20 | 21 | def run(): 22 | while True: 23 | user_input = input("You: ") 24 | if user_input.lower() in ["exit", "quit", "bye"]: 25 | print("Chatbot: Goodbye! It was nice talking to you.") 26 | break 27 | 28 | # Add user input to memory 29 | memory.add(f"User: {user_input}", user_id="user") 30 | 31 | # Retrieve relevant information from vector store 32 | relevant_info = memory.search(query=user_input, limit=3) 33 | context = "\n".join(message["memory"] for message in relevant_info) 34 | 35 | inputs = { 36 | "user_message": f"{user_input}", 37 | "context": f"{context}", 38 | } 39 | 40 | response = CrewaiConversationalChatbotCrew().crew().kickoff(inputs=inputs) 41 | 42 | # Add chatbot response to memory 43 | memory.add(f"Assistant: {response}", user_id="assistant") 44 | print(f"Assistant: {response}") 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CrewaiConversationalChatbot Crew 2 | 3 | Blog post: [Building a conversational chatbot with CrewAI, Groq, Chromadb, and Mem0](http://zinyando.com/building-a-conversational-chatbot-with-crewai-groq-chromadb-and-mem0/) 4 | 5 | Welcome to the CrewaiConversationalChatbot Crew project, powered by [crewAI](https://crewai.com). This template is designed to help you set up a multi-agent AI system with ease, leveraging the powerful and flexible framework provided by crewAI. Our goal is to enable your agents to collaborate effectively on complex tasks, maximizing their collective intelligence and capabilities. 6 | 7 | ## Installation 8 | 9 | Ensure you have Python >=3.10 <=3.13 installed on your system. This project uses [Poetry](https://python-poetry.org/) for dependency management and package handling, offering a seamless setup and execution experience. 10 | 11 | First, if you haven't already, install Poetry: 12 | 13 | ```bash 14 | pip install poetry 15 | ``` 16 | 17 | Next, navigate to your project directory and install the dependencies: 18 | 19 | 1. First lock the dependencies and then install them: 20 | ```bash 21 | poetry lock 22 | ``` 23 | ```bash 24 | poetry install 25 | ``` 26 | ### Customizing 27 | 28 | **Add your `OPENAI_API_KEY` into the `.env` file** 29 | 30 | - Modify `src/crewai_conversational_chatbot/config/agents.yaml` to define your agents 31 | - Modify `src/crewai_conversational_chatbot/config/tasks.yaml` to define your tasks 32 | - Modify `src/crewai_conversational_chatbot/crew.py` to add your own logic, tools and specific args 33 | - Modify `src/crewai_conversational_chatbot/main.py` to add custom inputs for your agents and tasks 34 | 35 | ## Running the Project 36 | 37 | To kickstart your crew of AI agents and begin task execution, run this from the root folder of your project: 38 | 39 | ```bash 40 | poetry run crewai_conversational_chatbot 41 | ``` 42 | 43 | This command initializes the crewai-conversational-chatbot Crew, assembling the agents and assigning them tasks as defined in your configuration. 44 | 45 | This example, unmodified, will run the create a `report.md` file with the output of a research on LLMs in the root folder. 46 | 47 | ## Understanding Your Crew 48 | 49 | The crewai-conversational-chatbot Crew is composed of multiple AI agents, each with unique roles, goals, and tools. These agents collaborate on a series of tasks, defined in `config/tasks.yaml`, leveraging their collective skills to achieve complex objectives. The `config/agents.yaml` file outlines the capabilities and configurations of each agent in your crew. 50 | 51 | ## Support 52 | 53 | For support, questions, or feedback regarding the CrewaiConversationalChatbot Crew or crewAI. 54 | - Visit our [documentation](https://docs.crewai.com) 55 | - Reach out to us through our [GitHub repository](https://github.com/joaomdmoura/crewai) 56 | - [Join our Discord](https://discord.com/invite/X4JWnZnxPb) 57 | - [Chat with our docs](https://chatg.pt/DWjSBZn) 58 | 59 | Let's create wonders together with the power and simplicity of crewAI. 60 | --------------------------------------------------------------------------------