Want an AI agent that runs on your own computer instead of a cloud API? This guide shows you how to set up an AI agent locally with Ollama, which runs the language model, and CrewAI, a Python framework that organises agents and their tasks. At the end you will have a two-agent workflow running on your machine, plus a file-writing tool that cannot leave its own folder.
Quick answer: Install Ollama and pull a small tool-capable model, install CrewAI in a Python virtual environment, then point CrewAI’s LLM class at ollama/llama3.2 on http://localhost:11434.
- Install Ollama and run
ollama pull llama3.2. - Create and activate a virtual environment with Python 3.10 to 3.13.
- Run
pip install "crewai[litellm]". - Write
agent.pywith your agents, tasks and the localLLM, and turn telemetry off. - Run
python agent.pyand read the result in the terminal.
In this guide
- Why Run an AI Agent Locally?
- Before You Start
- Step 1: Install Ollama and Download a Model
- Step 2: Create a Python Virtual Environment and Install CrewAI
- Step 3: Write the Agent Script with CrewAI
- Step 4: Run the Agent and Check the Result
- Step 5: Add a Tool That Writes Files (Safely)
- Common Errors and Fixes
- Frequently Asked Questions About Local AI Agents
- Next Steps

Why Run an AI Agent Locally?
With a cloud model, every prompt and document you send leaves your network. A local agent keeps that data on your own hardware, which matters for customer records, private source code or internal reports.
- Privacy: prompts and documents stay on your machine or private network. CrewAI’s anonymous usage telemetry is switched off in the script below.
- Cost: there is no per-token fee, so long agent loops do not produce a surprise bill. You pay for the hardware and electricity instead.
- Control: you choose when to change models and prompts, and no provider can retire a model or rate-limit you.
- Offline use: once the model and packages are downloaded, the workflow runs without internet access.
The trade-off: small local models are weaker at multi-step reasoning and tool use than large hosted models, so keep tasks simple and explicit.
Before You Start
- Memory: Llama 3.2 (3B), the model used in this guide, is a 2 GB download and runs on an ordinary 8 GB laptop. Larger models need more RAM or a GPU. Apple Silicon Macs work well because the GPU shares the full system memory.
- Python 3.10 to 3.13, the range CrewAI supports. The newest Python release is not always supported yet. Get it from the Python official downloads page if needed.
- Ollama, installed in Step 1, and a terminal.
- Time: about 30 minutes, plus the model download.
Open a terminal and check your Python version:
python3 --versionYou should see something like Python 3.12.x. If the version is lower than 3.10 or higher than 3.13, install a supported version before you continue.
Step 1: Install Ollama and Download a Model
Ollama is a background service that downloads model files, loads them into memory and exposes a local API on port 11434. Download the installer for macOS, Linux or Windows from the official Ollama download page and run it.
Once installed, Ollama runs quietly in the background: in the menu bar on macOS, the system tray on Windows, or as a service on Linux. For GPU tips and more model options, see the guide to run LLMs locally with Ollama.
In your terminal, download the Llama 3.2 model:
ollama pull llama3.2Ollama shows download progress and prints success when it finishes. Run ollama list to confirm that llama3.2 is listed. This is the 3B-parameter model: small enough for most laptops, and it supports tool calling. If your machine has room for a 4–5 GB model, a 7–8B model such as Mistral or Llama 3.1 handles more complex reasoning better:
ollama pull mistralStep 2: Create a Python Virtual Environment and Install CrewAI
A virtual environment is a project folder with its own Python packages, so CrewAI and its dependencies cannot break other tools on your system. In your terminal, create the project folder and the environment:
mkdir local-ai-agent
cd local-ai-agent
python3 -m venv venvActivate the environment. On macOS and Linux, run:
source venv/bin/activateOn Windows in Command Prompt, run the line below. In PowerShell, run venv\Scripts\Activate.ps1 instead.
venv\Scripts\activateYour prompt should now start with (venv). With the environment active, install CrewAI together with its LiteLLM extra, which CrewAI needs to talk to Ollama:
pip install "crewai[litellm]"Step 3: Write the Agent Script with CrewAI
CrewAI uses three building blocks:
- Agent: a role with a goal and a short backstory, for example a researcher.
- Task: one assignment, with a description and the output you expect.
- Crew: the group of agents and tasks, plus the order they run in.
Create a file named agent.py in the local-ai-agent folder and paste the code below. It connects to your local Ollama instance through CrewAI’s own LLM class; no other framework is needed.
import os
# CrewAI sends anonymous usage telemetry by default; switch it off for a fully local run
os.environ["CREWAI_DISABLE_TELEMETRY"] = "true"
from crewai import Agent, Task, Crew, Process, LLM
# Configure the local LLM using Ollama
local_llm = LLM(
model="ollama/llama3.2",
base_url="http://localhost:11434",
)
# Define a researcher agent
researcher = Agent(
role="Senior Research Analyst",
goal="Analyze a topic and provide concise summaries",
backstory="You are an expert researcher trained to extract key insights from raw data.",
verbose=True,
allow_delegation=False,
llm=local_llm,
)
# Define a writer agent
writer = Agent(
role="Technical Content Writer",
goal="Convert complex research summaries into clear, actionable bullet points",
backstory="You are a skilled technical writer who specializes in making technical concepts simple.",
verbose=True,
allow_delegation=False,
llm=local_llm,
)
# Define the research task
research_task = Task(
description="Analyze the potential benefits of running LLMs locally on consumer hardware.",
expected_output="A summary of the main performance, cost, and privacy advantages.",
agent=researcher,
)
# Define the writing task
write_task = Task(
description="Format the research summary into a structured markdown list of actionable takeaways.",
expected_output="A structured list of key advantages with clear bullet points.",
agent=writer,
)
# Assemble the local crew
crew = Crew(
agents=[researcher, writer],
tasks=[research_task, write_task],
process=Process.sequential,
)
if __name__ == "__main__":
print("Starting local AI agent workflow...")
result = crew.kickoff()
print("\n=== Workflow Result ===\n")
print(result)The two agents work in sequence. The researcher has no tools yet, so it summarises what the model already knows about the topic, and the writer turns that summary into a list. Both use your local Llama 3.2 through Ollama on port 11434. CrewAI’s default telemetry is anonymous and does not include prompts or task content, but the environment variable at the top turns it off entirely.
Step 4: Run the Agent and Check the Result
With the virtual environment still active, run the script from the project folder:
python agent.pyYou should see Starting local AI agent workflow..., then CrewAI’s step-by-step log for each agent (because of verbose=True), and finally === Workflow Result === followed by a bullet list of advantages. On a CPU-only machine, the run can take a few minutes.
If the model gets stuck repeating itself or mangles the format, tighten the tasks:
- Make each task description explicit and short.
- Put a concrete example of the output you want into the description or
expected_output. - Split one large task into two smaller ones.
Step 5: Add a Tool That Writes Files (Safely)
Tools are Python functions the agent can decide to call, which turns it from a text generator into something that acts: reading files, querying a local database or calling a local API. The example below lets the writer save its result to disk, but only inside an output/ folder.
In agent.py, add the import and the write_file_tool function below the local_llm definition. Then replace your existing writer = Agent(...) block with the version at the bottom of the snippet, which adds tools=[write_file_tool]:
import os
from crewai.tools import tool
@tool("Write Local File Tool")
def write_file_tool(filename: str, content: str) -> str:
"""Save text content to a file inside the local output/ folder."""
try:
os.makedirs("output", exist_ok=True)
# basename() stops the model from writing outside output/ (for example "../../.bashrc")
filepath = os.path.join("output", os.path.basename(filename))
with open(filepath, "w", encoding="utf-8") as f:
f.write(content)
return f"File successfully saved to {filepath}"
except Exception as e:
return f"Error writing file: {e}"
# Hand the tool to the writer agent when you define it
writer = Agent(
role="Technical Content Writer",
goal="Convert complex research summaries into clear, actionable bullet points",
backstory="You are a skilled technical writer who specializes in making technical concepts simple.",
tools=[write_file_tool],
verbose=True,
allow_delegation=False,
llm=local_llm,
)Next, tell the agent to use the tool: add a sentence such as “Save the list to takeaways.md with the Write Local File Tool.” to the write_task description. Run python agent.py again. If the model called the tool, output/takeaways.md now exists. Small models do not always call tools reliably; if no file appears, try a larger tool-capable model such as Mistral.
The model chooses the file name and content, so keep file tools confined to a dedicated folder like this, and never give a local agent unrestricted shell or file-system access. You can also connect an AI chatbot to Telegram to send instructions from chat, but only with a strict user allow-list and narrowly scoped tools, because every tool you expose becomes remotely triggerable. For tool schemas and more patterns, see the CrewAI official documentation.
Common Errors and Fixes
ModuleNotFoundError: No module named 'crewai': the virtual environment is not active in this terminal. Run the activate command from Step 2 again, then rerun the script.pip installfails while building packages: checkpython3 --version. CrewAI supports Python 3.10 to 3.13, so a newer Python can fail.- Connection refused on port 11434: Ollama is not running. Start the Ollama app, or run
ollama servein a separate terminal. - An error that the model was not found: the name after
ollama/must match one shown byollama list. Pull it first withollama pull llama3.2. - An error about a missing OpenAI API key: an agent was created without
llm=local_llm, so CrewAI fell back to its default OpenAI model. Pass the local LLM to every agent.
Frequently Asked Questions About Local AI Agents
Can I run local AI agents without a dedicated GPU?
Yes, local AI agents run on a CPU, but generation is much slower. On CPU-only hardware, stick to small models such as Llama 3.2 (3B parameters) or Qwen 2.5 (1.5B or 3B parameters), and keep each task short so every call finishes quickly.
What are the best local models for agentic workflows?
Pick a model that supports tool calling. Good starting points are Llama 3.1 (8B), Mistral (7B) and Qwen 2.5 (7B or 14B), which the Ollama library lists with tool support; frameworks like CrewAI rely on it. The original Llama 3 (8B) is not listed with tool support.
Do local AI agents need an internet connection?
No. Once the model is downloaded with Ollama and your Python packages are installed, the agent can run entirely offline. Keep CrewAI’s telemetry disabled as shown in the script so it does not try to connect, which also suits secure or air-gapped environments.
How do I update my local models?
Run ollama pull with the model name again, for example ollama pull llama3.2. Ollama checks for a newer version and downloads only the parts that changed. Run your agent once afterwards, because a new model version can change how it follows your task instructions.
Next Steps
Point the agent at a real task you repeat, such as summarising a folder of notes or turning a weekly export into a report. Then:
- Give it your own documents instead of relying on what the model remembers; the RAG architecture checklist explains how retrieval works.
- Prefer JavaScript? The local content marketing agent in Node.js builds a similar research, outline and write pipeline on Ollama.

