# Connecting Ollama with crewai

**URL:** <https://community.crewai.com/t/connecting-ollama-with-crewai/2222>\
**Category:** Crews\
**Tags:** crewai\
**Created:** [December 23, 2024, 8:54pm UTC](https://community.crewai.com/t/connecting-ollama-with-crewai/2222 "2024-12-23T20:54:37Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![ay\_poju](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@ay\_poju](https://community.crewai.com/u/ay_poju)\
**Post date:** [December 23, 2024, 8:54pm UTC](https://community.crewai.com/t/connecting-ollama-with-crewai/2222/1 "2024-12-23T20:54:37Z")

</div>

I am having issues using other LLMs other than the default OpenAI models with my crews. I am new to all this and have been following the instructions from the official documentation: [Quickstart - CrewAI](https://docs.crewai.com/quickstart) and also the LiteLLM docs to see what parameters I need to parse to the LLM instance.

My issue is that when I run the python command “python src/crewai/main.py” it doesn’t do anything, not even an error gets thrown. I have run it in verbose as well and no error messages in the logs.

I have changed to Ollama and I can interact with it manually, but when I run it as part of my crew it does the same thing as the cohere LLM.

Not sure if it’s my machine. I’m using an old MacBook Air. I am using crewai version 0.86.0 and using python version 3.11.9.

I initiate my crew by running the crewai create crew crewai\_firstcrew

The resulting files, I update the crew.py file as follows (see bold text):

from crewai import Agent, Crew, Process, Task, **LLM**  
from crewai.project import CrewBase, agent, crew, task  
**from dotenv import load\_dotenv**

**load\_dotenv()**

@CrewBase  
class CrewaiFirstcrew():  
“”“CrewaiFirstcrew crew”“”

```
agents_config = 'config/agents.yaml'
tasks_config = 'config/tasks.yaml'

**ollama_llm = LLM(**

```

\*\* model=“ollama/llama3.2:3b”,\*\*  
\*\* api\_base=“[http://localhost:11434](http://localhost:11434)”\*\*  
\*\* )\*\*

```
@agent
def researcher(self) -> Agent:
	return Agent(
		config=self.agents_config['researcher'],
		verbose=True,
		**llm=self.ollama_llm**
	)

```

Hoping someone is able to give some direction as to how to get this working or point out any misconfigurations I might have.

---

<div class="post-metadata">

**Author:** ![Salman](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/salman/32/1599_2.png) [@Salman](https://community.crewai.com/u/Salman)\
**Post date:** [December 24, 2024, 4:05am UTC](https://community.crewai.com/t/connecting-ollama-with-crewai/2222/2 "2024-12-24T04:05:15Z")

</div>

Hi,

Here is my how I connect my local llama3:7b to crew,

I would check following

1. is [http://localhost:11434](http://localhost:11434) url open and you can black page saying “Ollama is running”

2. do you see ollama icon next to notification center in top right, means ollama is running (if you are using ollama)

3. I would check my locally installed llama models with `ollama list` and make sure you are running that model with command `ollama run llama3` or `ollama run llama3.3` and then make sure you are referencing that exact model in crewai script  
 ![image](https://us1.discourse-cdn.com/flex025/uploads/crewai/optimized/2X/c/c5c8f89e561d88b88b665609549e3b06fa287139_2_517x63.png)

I hope this helps.

---

<div class="post-metadata">

**Author:** ![ay\_poju](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@ay\_poju](https://community.crewai.com/u/ay_poju)\
**Post date:** [December 24, 2024, 11:59am UTC](https://community.crewai.com/t/connecting-ollama-with-crewai/2222/3 "2024-12-24T11:59:55Z")

</div>

Thanks @Salman - I have done everything you suggested and it’s still the same issue. I’ll just put my whole crew.py file here in case you can spot an errors.

- Checking llama can be accessed and used locally (see attached images)

![Screenshot 2024-12-24 at 11.52.02](https://us1.discourse-cdn.com/flex025/uploads/crewai/original/2X/6/6f4af2b572c169180c789ff81891db0c8361e301.png)

- Crew.py file  
from crewai import Agent, Crew, Process, Task, LLM  
from crewai.project import CrewBase, agent, crew, task  
from dotenv import load\_dotenv

Hopefully you might be able to spot a mistake in here.

---

<div class="post-metadata">

**Author:** ![ay\_poju](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@ay\_poju](https://community.crewai.com/u/ay_poju)\
**Post date:** [December 24, 2024, 3:15pm UTC](https://community.crewai.com/t/connecting-ollama-with-crewai/2222/4 "2024-12-24T15:15:16Z")

</div>

This is what happens when I run it btw:

![Screenshot 2024-12-24 at 15.14.39](https://us1.discourse-cdn.com/flex025/uploads/crewai/optimized/2X/f/fcc6e927e59d201fcd31463436f3757ea27c51a7_2_690x55.png)

---

<div class="post-metadata">

**Author:** ![Salman](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/salman/32/1599_2.png) [@Salman](https://community.crewai.com/u/Salman)\
**Post date:** [December 25, 2024, 12:47pm UTC](https://community.crewai.com/t/connecting-ollama-with-crewai/2222/5 "2024-12-25T12:47:03Z")

</div>

No output in terminal seems to be a red herring, agents are indeed able to connect to model (in my testing) but correct command is needed to run the crew.

As per documentation you need to run `crewai install` in project directory (to install dependencies) and then to run the crew use `crewai run`

Running main.py wont give you results as template needs to install dependencies before it can execute crews

I recommend taking the course (its bit old but fundamentals still apply)

> **[Multi AI Agent Systems with crewAI - DeepLearning.AI](https://learn.deeplearning.ai/courses/multi-ai-agent-systems-with-crewai/lesson/1/introduction)**
>
> Automate business workflows with multi-AI agent systems. Exceed the performance of prompting a single LLM by designing and prompting a team of AI agents through natural language.

---

<div class="post-metadata">

**Author:** ![ay\_poju](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@ay\_poju](https://community.crewai.com/u/ay_poju)\
**Post date:** [December 27, 2024, 10:23pm UTC](https://community.crewai.com/t/connecting-ollama-with-crewai/2222/6 "2024-12-27T22:23:22Z")

</div>

Thanks Salman - managed to resolve it by updating the project toml file and also correcting an issue in the main.py file.

---

<div class="post-metadata">

**Author:** ![Vikash](https://avatars.discourse-cdn.com/v4/letter/v/898d66/32.png) [@Vikash](https://community.crewai.com/u/Vikash)\
**Post date:** [January 18, 2025, 7:06pm UTC](https://community.crewai.com/t/connecting-ollama-with-crewai/2222/7 "2025-01-18T19:06:39Z")

</div>

can you help to share the fix ?

---

<div class="post-metadata">

**Author:** ![ay\_poju](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@ay\_poju](https://community.crewai.com/u/ay_poju)\
**Post date:** [January 19, 2025, 10:46pm UTC](https://community.crewai.com/t/connecting-ollama-with-crewai/2222/8 "2025-01-19T22:46:27Z")

</div>

Hi Vikash

I just pinned the version of the onnxruntime and some other dependencies and re ran the code.

In the root directory of your project, you will have a `pyproject.toml` file. In the `dependency` section, pin the versions of the following utilities:

```
dependencies = [
    "crewai[tools]>=0.80.0,<1.0.0",
    "onnxruntime==1.15.0",
    "socksio>=1.0.0",
    "pyarrow==17.0.0",
]

```

Also, I am using Python 3.11.9, just in case you are using a different Python version.

---

<div class="post-metadata">

**Author:** ![DaveN](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/daven/32/2247_2.png) [@DaveN](https://community.crewai.com/u/DaveN)\
**Post date:** [January 25, 2025, 7:03pm UTC](https://community.crewai.com/t/connecting-ollama-with-crewai/2222/9 "2025-01-25T19:03:55Z")

</div>

I am on crewAI 98, python 3.12.7. Want to use local llama3.2:1b model through Ollama. However, with the below code, it seems its endlessly running even with max\_iterations & time\_out.

Anyone can point what’s the error or I’m doing wrong. I’m a beginner and doing everything in single notebook instead of creating different files

llm=Ollama(model=“ollama/llama3.2:1b”, base\_url=“[http://localhost:11434](http://localhost:11434)”)

# Define an agent that uses the Ollama tool

researcher = Agent(  
role=“researcher”,  
goal=“Write a document about different types of alcohols consumed by people”,  
backstory=“You are working on collecting factual information on alcohol.”  
“Create a document to share with readers to provide them a view”,  
llm=llm,  
max\_iterations=5,  
max\_time=120,  
verbose=True  
)

# Define a task for the researcher

researcher\_task = Task(  
description=(  
“1. Analyze different types of alcohol which are consumed by people.”  
“2. Create a list of these alcohols”  
),  
expected\_output=“A document with a list of different alcohols”,  
output\_file=“./alcohol\_research.md”,  
agent=researcher  
)

# Create a crew and assign the task

crew = Crew(  
agents=[researcher],  
model=“ollama/llama3.2:1b”,  
tasks=[researcher\_task],  
cache=True,  
verbose=True,  
planning=True  
)

# Run the crew with inputs

result = crew.kickoff(inputs={})

---

<div class="post-metadata">

**Author:** ![Crypto\_Gen](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/crypto_gen/32/1605_2.png) [@Crypto\_Gen](https://community.crewai.com/u/Crypto_Gen)\
**Post date:** [February 6, 2025, 12:26pm UTC](https://community.crewai.com/t/connecting-ollama-with-crewai/2222/10 "2025-02-06T12:26:26Z")

</div>

This simply works without any issues.

Found a way to fix this. Use this approach. You can use a random/dummy API key for open ai API key env variable and then use the ChatOpenAI class instead of LLM class. It worked fine for me in local with the Ollama model

os.environ[“OPENAI\_API\_KEY”] = “testapikey”  
llm\_local = ChatOpenAI(  
model=“ollama/deepseek-r1:latest”,  
base\_url=“[http://localhost:11434](http://localhost:11434)”  
)

---

<div class="post-metadata">

**Author:** ![DaveN](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/daven/32/2247_2.png) [@DaveN](https://community.crewai.com/u/DaveN)\
**Post date:** [February 15, 2025, 6:29pm UTC](https://community.crewai.com/t/connecting-ollama-with-crewai/2222/11 "2025-02-15T18:29:23Z")

</div>

Thanks. Worked like a charm

---

<div class="post-metadata">

**Author:** ![shailaja\_natarajan](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/shailaja_natarajan/32/3088_2.png) [@shailaja\_natarajan](https://community.crewai.com/u/shailaja_natarajan)\
**Post date:** [May 25, 2025, 3:29am UTC](https://community.crewai.com/t/connecting-ollama-with-crewai/2222/12 "2025-05-25T03:29:53Z")

</div>

Thanks for sharing this approach. It worked for me as well. I am wondering why ollama model is not supported via crewai ?

---

<div class="post-metadata">

**Author:** ![shivam\_bhardwaj](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/shivam_bhardwaj/32/4128_2.png) [@shivam\_bhardwaj](https://community.crewai.com/u/shivam_bhardwaj)\
**Post date:** [July 19, 2025, 6:17am UTC](https://community.crewai.com/t/connecting-ollama-with-crewai/2222/13 "2025-07-19T06:17:03Z")

</div>

This code as well Did’nt work for me, will you help me ?

my code:

from langchain\_openai import ChatOpenAI

os.environ[“OPENAI\_API\_KEY”] = “testapikey” # Replace with your actual key

# Set up the Ollama model

llm = ChatOpenAI(  
model=“phi4”,  
base\_url=“[http://localhost:11434](http://localhost:11434)”,  
temperature=0.5,  
)

# Define the Researcher Agent

researcher = Agent(  
role=“Senior News Researcher”,  
goal=“Find and research the latest news on a given topic”,  
backstory=“”“You are a senior news researcher at a major news outlet.  
You are an expert at finding the most relevant and up-to-date information on any topic.”“”,  
verbose=True,  
allow\_delegation=False,  
llm=llm,  
)

# Define the Verifier Agent

verifier = Agent(  
role=“News Verifier and Editor”,  
goal=“Verify the authenticity of the news and present it in a clear, concise, and engaging way”,  
backstory=“”“You are a meticulous verifier and editor with a keen eye for detail and a passion for truth.  
You are responsible for ensuring the accuracy and quality of all news content before it is published.”“”,  
verbose=True,  
allow\_delegation=True,  
llm=llm,  
)

# Define the Research Task

research\_task = Task(  
description=“Research the latest news on {topic}.”,  
expected\_output=“A summary of the top 3 most important news stories on the topic.”,  
agent=researcher,  
)

# Define the Verification and Writing Task

verify\_and\_write\_task = Task(  
description=“”“Take the news summary, verify the information, and write a compelling news article.  
The article should be well-structured, engaging, and easy to understand.”“”,  
expected\_output=“A professionally written news article.”,  
agent=verifier,  
)

# Create the Crew

news\_crew = Crew(  
agents=[researcher, verifier],  
tasks=[research\_task, verify\_and\_write\_task],  
process=Process.sequential,  
verbose=True,  
)

# Kick off the crew with a topic

result = news\_crew.kickoff(inputs={“topic”: “Latest advancements in AI”})

print(“######################”)  
print(result)

output:

Crew: crew  
└── 📋 Task: 2b338b45-8d9d-48c5-b3ef-d55360093417  
Status: Executing Task…  
╭────────────────────────────────────────────── 🤖 Agent Started ──────────────────────────────────────────────╮  
│ │  
│ Agent: Senior News Researcher │  
│ │  
│ Task: Research the latest news on Latest advancements in AI. │  
│ │  
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

🚀 Crew: crew  
└── 📋 Task: 2b338b45-8d9d-48c5-b3ef-d55360093417  
Status: Executing Task…  
└── ❌ LLM Failed

An unknown error occurred. Please check the details below.

🚀 Crew: crew  
└── 📋 Task: 2b338b45-8d9d-48c5-b3ef-d55360093417  
Assigned to: Senior News Researcher  
Status: ❌ Failed  
└── ❌ LLM Failed  
╭──────────────────────────────────────────────── Task Failure ────────────────────────────────────────────────╮  
│ │  
│ Task Failed │  
│ Name: 2b338b45-8d9d-48c5-b3ef-d55360093417 │  
│ Agent: Senior News Researcher │  
│ Tool Args: │  
│

.BadRequestError:

will someone can help me i am tired of it 😭😭

---

<div class="post-metadata">

**Author:** ![shivam\_bhardwaj](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/shivam_bhardwaj/32/4128_2.png) [@shivam\_bhardwaj](https://community.crewai.com/u/shivam_bhardwaj)\
**Post date:** [July 19, 2025, 6:17am UTC](https://community.crewai.com/t/connecting-ollama-with-crewai/2222/14 "2025-07-19T06:17:34Z")

</div>

my code:

from langchain\_openai import ChatOpenAI

os.environ[“OPENAI\_API\_KEY”] = “testapikey” # Replace with your actual key

# Set up the Ollama model

llm = ChatOpenAI(  
model=“phi4”,  
base\_url=“[http://localhost:11434](http://localhost:11434/)”,  
temperature=0.5,  
)

# Define the Researcher Agent

researcher = Agent(  
role=“Senior News Researcher”,  
goal=“Find and research the latest news on a given topic”,  
backstory=“”“You are a senior news researcher at a major news outlet.  
You are an expert at finding the most relevant and up-to-date information on any topic.”“”,  
verbose=True,  
allow\_delegation=False,  
llm=llm,  
)

# Define the Verifier Agent

verifier = Agent(  
role=“News Verifier and Editor”,  
goal=“Verify the authenticity of the news and present it in a clear, concise, and engaging way”,  
backstory=“”“You are a meticulous verifier and editor with a keen eye for detail and a passion for truth.  
You are responsible for ensuring the accuracy and quality of all news content before it is published.”“”,  
verbose=True,  
allow\_delegation=True,  
llm=llm,  
)

# Define the Research Task

research\_task = Task(  
description=“Research the latest news on {topic}.”,  
expected\_output=“A summary of the top 3 most important news stories on the topic.”,  
agent=researcher,  
)

# Define the Verification and Writing Task

verify\_and\_write\_task = Task(  
description=“”“Take the news summary, verify the information, and write a compelling news article.  
The article should be well-structured, engaging, and easy to understand.”“”,  
expected\_output=“A professionally written news article.”,  
agent=verifier,  
)

# Create the Crew

news\_crew = Crew(  
agents=[researcher, verifier],  
tasks=[research\_task, verify\_and\_write\_task],  
process=Process.sequential,  
verbose=True,  
)

# Kick off the crew with a topic

result = news\_crew.kickoff(inputs={“topic”: “Latest advancements in AI”})

print(“######################”)  
print(result)

output:

Crew: crew  
└── 📋 Task: 2b338b45-8d9d-48c5-b3ef-d55360093417  
Status: Executing Task…  
╭────────────────────────────────────────────── 🤖 Agent Started ──────────────────────────────────────────────╮  
│ │  
│ Agent: Senior News Researcher │  
│ │  
│ Task: Research the latest news on Latest advancements in AI. │  
│ │  
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

🚀 Crew: crew  
└── 📋 Task: 2b338b45-8d9d-48c5-b3ef-d55360093417  
Status: Executing Task…  
└── ❌ LLM Failed

An unknown error occurred. Please check the details below.

🚀 Crew: crew  
└── 📋 Task: 2b338b45-8d9d-48c5-b3ef-d55360093417  
Assigned to: Senior News Researcher  
Status: ❌ Failed  
└── ❌ LLM Failed  
╭──────────────────────────────────────────────── Task Failure ────────────────────────────────────────────────╮  
│ │  
│ Task Failed │  
│ Name: 2b338b45-8d9d-48c5-b3ef-d55360093417 │  
│ Agent: Senior News Researcher │  
│ Tool Args: │  
│

.BadRequestError:

will someone can help me i am tired of it 😭😭

---

<div class="post-metadata">

**Author:** ![maxmoura](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/maxmoura/32/4206_2.png) [@maxmoura](https://community.crewai.com/u/maxmoura)\
**Post date:** [July 19, 2025, 11:05am UTC](https://community.crewai.com/t/connecting-ollama-with-crewai/2222/15 "2025-07-19T11:05:57Z")

</div>

> [@shivam\_bhardwaj](#):
>
> ```plaintext
> from langchain_openai import ChatOpenAI
> 
> os.environ["OPENAI_API_KEY"] = "testapikey" # Replace with your actual key
> 
> # Set up the Ollama model
> 
> llm = ChatOpenAI(
> model="phi4",
> base_url="http://localhost:11434",
> temperature=0.5,
> )
> 
> ```

No need for LangChain nor `OPENAI_API_KEY`:

```python
from crewai import LLM

llm = LLM(
    model="ollama/phi4",
    base_url="http://localhost:11434",
    temperature=0.5
)

```
