Build your own private AI assistant that can plan tasks, use tools, work with files, maintain memory, and operate under controlled guardrails using Ollama and Python.
Most people use AI as a chatbot: ask a question, receive an answer, and repeat.
A personal agentic system is different. It can understand a goal, break it into steps, use tools, remember useful context, and produce a useful result while running largely on your own computer.
In this guide, you'll build a simple but extensible personal AI agent using Ollama and Python. By the end, it will be able to:
- Accept a task in natural language
- Plan the steps needed
- Read and write local files
- Search notes or documents
- Call tools safely
- Keep a record of what it did
- Improve through feedback
Why Use Ollama?
Ollama lets you run open-weight language models locally on your machine. Instead of sending every prompt to a cloud provider, your agent can communicate with a model through a local endpoint.
http://localhost:11434
This approach has several advantages. Local models are not always as capable as the largest frontier models, especially for complex reasoning. But for personal productivity tasks such as summarizing notes, drafting content, organizing files, researching with web tools, and automating routines, they can be extremely effective.
The Architecture
We will build a minimal personal agentic system with five components:
- Model runtime: Ollama runs the language model
- Agent brain: Python coordinates reasoning and decisions
- Tools: The agent can read files, write files, and search notes
- Memory: The agent saves task history and useful facts
- Guardrails: The agent has limits, approvals, and safe tool access
User goal
↓
Agent planner
↓
Tool selection
↓
Tool execution
↓
Observation and reflection
↓
Final result
↓
Memory update
Step 1: Install Ollama
Download and install Ollama from the official website for your operating system. After installation, verify that it is running.
ollama --version
Then pull a model. For a first personal agent, choose a model that fits your hardware. A smaller model is faster and requires less memory.
ollama pull llama3.2
Test it:
ollama run llama3.2 "Explain what an AI agent is in one paragraph."
If this works, Ollama is ready. Ollama's local API is typically
available at http://localhost:11434, which is the
address your Python agent will use.
Step 2: Create the Project
Create a folder for your system:
mkdir personal-agent
cd personal-agent
Set up a Python virtual environment:
python -m venv venv
source venv/bin/activate
On Windows:
venv\Scripts\activate
Install the dependencies:
pip install requests
Create this folder structure:
personal-agent/
├── agent.py
├── tools.py
├── memory.py
├── workspace/
└── memory/
The workspace/ folder is where the agent can safely read
and write files. The memory/ folder stores its task history.
Step 3: Connect Python to Ollama
Create a file called agent.py:
import json
import requests
OLLAMA_URL = "http://localhost:11434/api/generate"
MODEL = "llama3.2"
def ask_ollama(prompt):
response = requests.post(
OLLAMA_URL,
json={
"model": MODEL,
"prompt": prompt,
"stream": False
},
)
response.raise_for_status()
return response.json()["response"]
if __name__ == "__main__":
goal = "Summarize the benefits of using a local AI agent."
print(ask_ollama(goal))
Run it:
python agent.py
You now have the foundation of your agent: a Python program that sends a prompt to a local model and receives a response.
Step 4: Give the Agent Tools
A model can generate text, but it cannot naturally read a file, save a note, or search your workspace unless you give it tools.
Create tools.py:
import os
WORKSPACE = "workspace"
def list_files():
return os.listdir(WORKSPACE)
def read_file(filename):
path = os.path.join(WORKSPACE, filename)
if not os.path.exists(path):
return f"File not found: {filename}"
with open(path, "r", encoding="utf-8") as file:
return file.read()
def write_file(filename, content):
path = os.path.join(WORKSPACE, filename)
with open(path, "w", encoding="utf-8") as file:
file.write(content)
return f"Saved file: {filename}"
Now your agent has three basic capabilities:
- List files in its workspace
- Read an allowed file
- Write an allowed file
This is already more useful than a normal chatbot. The agent can inspect material, extract information, and save its output.
Step 5: Add Memory
Memory is what turns a one-off script into a personal system.
Create memory.py:
import json
import os
from datetime import datetime
MEMORY_DIR = "memory"
def save_task(goal, result):
os.makedirs(MEMORY_DIR, exist_ok=True)
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
filename = f"{timestamp}.json"
record = {
"timestamp": timestamp,
"goal": goal,
"result": result
}
with open(os.path.join(MEMORY_DIR, filename), "w", encoding="utf-8") as file:
json.dump(record, file, indent=2)
return filename
def load_recent_tasks(limit=5):
if not os.path.exists(MEMORY_DIR):
return []
files = sorted(os.listdir(MEMORY_DIR), reverse=True)[:limit]
tasks = []
for file in files:
with open(os.path.join(MEMORY_DIR, file), "r", encoding="utf-8") as f:
tasks.append(json.load(f))
return tasks
Every completed task is stored with its goal, result, and timestamp. Over time, this becomes a searchable record of what your agent has done.
Step 6: Build the Agent Loop
Now connect everything in agent.py.
import json
import requests
from tools import list_files, read_file, write_file
from memory import save_task, load_recent_tasks
OLLAMA_URL = "http://localhost:11434/api/generate"
MODEL = "llama3.2"
TOOLS = {
"list_files": list_files,
"read_file": read_file,
"write_file": write_file,
}
def ask_ollama(prompt):
response = requests.post(
OLLAMA_URL,
json={
"model": MODEL,
"prompt": prompt,
"stream": False
},
)
response.raise_for_status()
return response.json()["response"]
def run_agent(goal):
recent_memory = load_recent_tasks()
system_prompt = f"""
You are a personal AI agent.
Your job is to help the user complete this goal:
"{goal}"
You have access to these tools:
- list_files: List files in the workspace
- read_file: Read a file from the workspace
- write_file: Save a file in the workspace
Respond only with valid JSON in this format:
{{
"thought": "Your reasoning",
"action": "list_files | read_file | write_file | finish",
"input": {{
"filename": "optional",
"content": "optional"
}},
"final_answer": "optional"
}}
Use a tool only when needed. Do not invent file contents.
"""
memory_context = json.dumps(recent_memory, indent=2)
prompt = f"{system_prompt}\n\nRecent memory:\n{memory_context}"
for step in range(5):
raw_response = ask_ollama(prompt)
try:
decision = json.loads(raw_response)
except json.JSONDecodeError:
return "The agent returned invalid JSON. Try rephrasing the task."
action = decision.get("action")
if action == "finish":
result = decision.get("final_answer", "Task completed.")
save_task(goal, result)
return result
tool = TOOLS.get(action)
if not tool:
return f"Unknown action: {action}"
input_data = decision.get("input", {})
if action == "list_files":
observation = tool()
elif action == "read_file":
observation = tool(
input_data.get("filename", "")
)
elif action == "write_file":
observation = tool(
input_data.get("filename", "output.txt"),
input_data.get("content", "")
)
prompt += f"\n\nObservation:\n{observation}"
return "The agent reached its step limit without completing the task."
if __name__ == "__main__":
goal = input("What would you like your agent to do? ")
print(run_agent(goal))
This is a basic plan → act → observe loop:
- The model receives the goal and available tools.
- It chooses an action.
- Python executes that action.
- The result is returned to the model.
- The model decides what to do next.
- The process repeats until it finishes or reaches a limit.
Step 7: Test It
Create a sample file:
echo "Ollama is a tool for running local language models." > workspace/notes.txt
Run the agent:
python agent.py
Try a goal such as:
notes.txt and create a summary called
summary.txt.
The agent should:
- Read
notes.txt - Generate a summary
- Write
summary.txtto the workspace - Save the completed task in
memory/
Step 8: Add Better Guardrails
Once the basics work, do not immediately give the agent shell access, unrestricted internet access, or permission to modify system files.
Use these guardrails:
- Allowlist tools: Only expose tools the agent truly needs.
-
Restrict file access:
Keep it inside
workspace/. - Validate inputs: Check filenames and content before execution.
- Limit iterations: Stop after a fixed number of steps.
- Require approval: Ask the user before deleting files, sending messages, or making purchases.
- Log everything: Save the goal, actions, tool outputs, and final result.
- Use structured output: Require JSON so your code can reliably interpret the agent's decision.
Step 9: Expand It Gradually
After your first version works, add capabilities one at a time.
For example, a useful first expansion is a personal research agent:
- Research a topic
- Collect sources
- Summarize findings
- Save the report to
workspace/ - List the sources used
This gives the agent a clear job, a measurable output, and a natural need for tools and memory.
Common Mistakes to Avoid
- Starting with too much autonomy: Begin with narrowly scoped tasks and human approval.
- Giving the agent dangerous tools early: Avoid unrestricted shell access, file deletion, or payment access.
- Ignoring memory: Without memory, the agent repeats work and loses context.
- Trusting every output: Verify facts, citations, code, and files.
- Using vague goals: "Improve my life" is not a task. A better goal would be "Summarize today's notes and create three action items."
- Skipping evaluation: Keep a small set of standard tasks and check whether the agent completes them reliably.
Final Thoughts
You do not need a massive infrastructure setup to build a personal agentic system. Start with Ollama, Python, a few safe tools, and a simple memory layer.
The goal is not to create a fully autonomous AI that takes over your computer. The goal is to create a reliable assistant that can do useful work under your control.
Once you have one agent completing one real task consistently, you have a foundation. Then expand its skills, tools, and memory based on the work you actually repeat.

Comments
Post a Comment