├── pyvenv.cfg ├── .env ├── scriptfile.sh ├── mistral-crew-ModelFile ├── README.md └── mistral-agents.py /pyvenv.cfg: -------------------------------------------------------------------------------- 1 | #set up your virtual environment from terminal 2 | 3 | #executable = /usr/local/bin/python3.12 4 | command = /usr/local/bin/python3.12 -m venv /home/mn/ProjectCrewAI 5 | -------------------------------------------------------------------------------- /.env: -------------------------------------------------------------------------------- 1 | #configure virtual environment with ollama endpoints: 2 | 3 | OPENAI_API_BASE='http://localhost:11434/v1' 4 | OPENAI_MODEL_NAME='mistral' # Adjust based on the model you want to use 5 | OPENAI_API_KEY='INSERT-YOUR-FREE-KEY' 6 | -------------------------------------------------------------------------------- /scriptfile.sh: -------------------------------------------------------------------------------- 1 | #set the variables 2 | model_name="mistral" 3 | custom_model_name="mistralcrew" 4 | 5 | #pull mistral from ModelFile 6 | ollama pull $model_name 7 | 8 | #create a new model based on mistral 9 | ollama create $custom_model_name -f ./mistral-crew-ModelFile 10 | -------------------------------------------------------------------------------- /mistral-crew-ModelFile: -------------------------------------------------------------------------------- 1 | #set the base model 2 | FROM mistral 3 | 4 | #set the parameters 5 | PARAMETER temperature 0.3 6 | PARAMETER stop Result 7 | 8 | #custom message 9 | SYSTEM"""You are an AI expert in AI technologies and algorithms, generating logical, factual, and step-by-step, and coherent responses""" 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CrewAI-Local-Agents-1 2 | 3 | ## Project Description: Local LLM set-up 4 | This repository is an example of a local setup for using agentic workflow using CrewAI and Ollama models. You can change the goal, role, and backstory of the agents, as well as the tasks' descriptions based on your desired output. 5 | 6 | 7 | ## Running The Agents 8 | This project uses a free API formality key from OpenAI, but you can replace it with your paid API key from other providers. 9 | 10 | 1. Set up a virtual environment using the `pyvenv.cfg` setting. 11 | 2. Configure your environment using the `dotenv` or `.env` file in your bin directory with Ollama endpoints and your choice of the large language model. 12 | 3. Create a Model File to specify the base LLM and set the PARAMETERs and the SYSTEM message to shape the behaviour of the LLM. 13 | 4. Create a shell file to pull the information from the Model File and then execute it via your terminal. 14 | 5. Make the necessary changes to the Python file based on your project goals, then run it. 15 | 16 | ## Additional Explanation and the Main Features 17 | This is a simple setup project that employs only two agents, each performing one task. You may set as many refiners as you need. You can also enhance the quality of the responses by setting `allow delegation` to `True` to allow agents to solve more complex problems using a chain of internal enquiries. This project uses a `sequential` task execution but you can set up a `hierarchical` one. 18 | 19 | ## Tutorial Video 20 | [![Watch the video](https://img.youtube.com/vi/XkS4ifkLwwQ/maxresdefault.jpg)](https://youtu.be/XkS4ifkLwwQ) 21 | -------------------------------------------------------------------------------- /mistral-agents.py: -------------------------------------------------------------------------------- 1 | from crewai import Agent, Task, Crew 2 | from langchain_openai import ChatOpenAI 3 | import os 4 | 5 | 6 | 7 | os.environ["OPENAI_API_KEY"] = "NA" 8 | 9 | llm = ChatOpenAI( 10 | 11 | model = "mistralcrew", 12 | 13 | base_url = "http://localhost:11434/v1") 14 | 15 | 16 | #agent1 researcher 17 | researcher = Agent(role = "Expert AI researcher", 18 | 19 | goal = """Comprehensive analysis of recent AI opportunities for tech solopreneurs""", 20 | 21 | backstory = """You are an expert research analyst in AI and its advancements and tech market opportunities. You can provide comprehensive research and analysis of the existing opportunities for solopreneurs""", 22 | 23 | allow_delegation = False, 24 | 25 | verbose = True, 26 | 27 | llm = llm) 28 | 29 | #agent2 writer 30 | writer = Agent(role = "Refiner and Expert AI Writer", 31 | 32 | goal = """Refine the researcher's responses to make it more relevant and precise and then write expert-level explanation of core concepts and advancements in AI in friendly and accessible language.""", 33 | 34 | backstory = """You are an expert in writing AI-related technical report in precise and actionable style for individual tech enthusiasts who need precise insight into opportunities in tech inductry. You are able to proofread your own text and produce a detailed report in an easy-to-follow and accessible language.""", 35 | 36 | allow_delegation = False, 37 | 38 | verbose = True, 39 | 40 | llm = llm) 41 | 42 | # Create tasks 43 | task1 = Task( 44 | description="""Conduct a comprehensive analysis of the latest advancements in AI in 2024. 45 | Identify key trends, breakthrough technologies, and potential industry impacts and opportunities for solo entrepreneurs.""", 46 | expected_output="Full analysis report in bullet points", 47 | agent=researcher 48 | ) 49 | 50 | task2 = Task( 51 | description="""Using the insights provided, develop a precise technical report 52 | that highlights the most significant opportunities in AI for solopreneurs. 53 | Your post should be informative yet accessible, catering to a tech-savvy audience. 54 | Write in accessible language and if needed briefly explain each technical term you introduce; proofread and edit your own report for a polished format.""", 55 | expected_output="Full report of at least 1000 words", 56 | agent=writer 57 | ) 58 | 59 | 60 | # Instantiate your crew with a sequential process 61 | crew = Crew( 62 | agents=[researcher, writer], 63 | tasks=[task1, task2], 64 | verbose=2, 65 | ) 66 | 67 | 68 | result = crew.kickoff() 69 | 70 | print(result) 71 | --------------------------------------------------------------------------------