Build Your Own AI Agent — SolarPunk Guide

Local. Open-source. Yours forever. Zero-to-running in 7 days — no subscriptions, no data leaks. Every command for Windows, Mac, and Linux.

Pay what you want →

70% of every sale goes to the Palestinian Children's Relief Fund (PCRF, EIN 93-1057665). Pay $1 or $100 — the guide is the same. Read it in full below.

What you're actually building

A personal AI assistant that runs entirely on your own computer, answers to no company's terms of service, costs nothing in monthly fees, and can actually do things — not just talk about doing them. You don't need to be a programmer; if you can follow a recipe, you can follow this. By Day 7 you'll have a local agent that understands plain-English requests, writes and runs code, connects to your email/calendar/Notion/GitHub, remembers context across sessions, coordinates specialized sub-agents, and runs locally with no data sent to third parties.

This isn't a chatbot wrapper — it's a genuine autonomous agent. The mycelium architecture means it grows: add new agents for new capabilities without rebuilding anything. Every action that touches an external system requires configuration you design in; it never acts without permission.

Part 2 — The stack, from atoms up

Five layers: Foundation (Docker, Python, Git), Brain (Ollama, LiteLLM, OpenRouter), Tools (n8n, AutoGen, Mem0), Interface (Chainlit), Execution (E2B, Browser-use/Playwright).

  • Docker packages software with everything it needs into a sealed container that runs identically on any machine — it eliminates the fragile-dependency problem that breaks AI setups.
  • Python is the lingua franca of AI; every major library has a Python version. Scripts here are short and explained line by line.
  • Git tracks changes so you can experiment aggressively and rewind to a working version in one command.
  • Ollama downloads compressed open-source models, manages them on your computer, and gives them a ChatGPT-like local API. Your queries never leave your machine.
  • LiteLLM is a universal adapter — write code once, switch between local Ollama and any cloud model with one line.
  • n8n is visual, self-hosted automation (like Zapier) with 300+ integrations, running in Docker at localhost:5678.
  • AutoGen lets multiple specialized agents converse and pass work between themselves — reliably better output on complex tasks.
  • Mem0 is a persistent memory layer so the agent remembers facts and preferences across sessions.
  • E2B gives sandboxed code execution — the agent can run code safely with no risk to your system.
  • Chainlit builds a ChatGPT-style web UI for your agent in ~20 lines of Python.
  • Playwright / Browser-use let the agent control a real browser from plain instructions.

Part 3 — Hardware reality check

RAM determines which models you can run. Models ship in quantized (compressed) formats — a 7B model at full precision needs ~14GB, but ~4GB at 4-bit, with minimal quality loss.

  • 4GB — survival mode: phi3:mini (3.8B), gemma2:2b, tinyllama. Noticeably weaker than ChatGPT; use cloud fallback for complex tasks.
  • 8GB — the sweet spot (most laptops, MacBook Air M-series): llama3.2:3b (recommended default), mistral:7b-q4, codellama:7b, llava:7b (vision).
  • 16GB — comfortable: llama3.1:8b, full mistral:7b, deepseek-coder:6.7b, llava:13b.
  • 32GB / Apple Silicon — powerful: llama3.1:70b-q4 (competitive with GPT-3.5/4 on many tasks), mixtral:8x7b, codellama:34b.

GPU: Nvidia CUDA and Apple Metal are used automatically and dramatically speed inference. Apple Silicon's unified memory makes it the best consumer hardware for local LLMs. CPU-only works for 3B–7B models (5–15 tokens/sec on a modern CPU — readable in real time).

Part 4 — Day 1: Foundation (Docker, Python, Git)

Estimated 45–90 min. You end with a verified working dev environment.

Install Git — Windows: winget install --id Git.Git -e --source winget · Mac: xcode-select --install · Linux: sudo apt update && sudo apt install git -y. Verify: git --version.

Install Python 3.11 (specifically — several AI libraries lag behind 3.12/3.13). Windows: winget install --id Python.Python.3.11 -e --source winget · Mac: brew install python@3.11 · Linux: sudo apt install python3.11 python3.11-pip python3.11-venv -y.

Install Docker — Desktop on Windows/Mac (winget install --id Docker.DockerDesktop / brew install --cask docker), Docker Engine on Linux. Verify all platforms: docker run hello-world.

mkdir ai-agent && cd ai-agent
git init
python -m venv venv
# Windows: venv\Scripts\activate   |   Mac/Linux: source venv/bin/activate
pip install litellm autogen-agentchat chainlit mem0ai python-dotenv requests
touch .env
printf '.env\nvenv/\n__pycache__/\n' >> .gitignore

In .env, add OLLAMA_BASE_URL=http://localhost:11434 plus blank placeholders for keys you'll fill in later. Never commit .env — it's already gitignored.

Part 5 — Day 2: Local brain (Ollama)

Install — Windows: winget install --id Ollama.Ollama · Mac: brew install ollama · Linux: curl -fsSL https://ollama.ai/install.sh | sh. Start the server with ollama serve (Windows runs it as a service). Pull a model matching your RAM: ollama pull llama3.2:3b (start here), mistral:7b, or llama3.1:8b. Test: ollama run llama3.2:3b then ask a question.

# test_ollama.py
from litellm import completion
response = completion(
    model='ollama/llama3.2:3b',
    messages=[{'role':'user','content':'Say hello in exactly 5 words.'}],
    api_base='http://localhost:11434')
print(response.choices[0].message.content)

Common fixes: 'connection refused' → run ollama serve; gibberish → ollama rm then re-pull; very slow → use a smaller model (phi3:mini).

Part 6 — Day 3: First tool (n8n)

n8n runs in Docker — no install conflicts. Create docker-compose.yml with an n8n service on port 5678, then docker compose up -d n8n and open http://localhost:5678. Build a first webhook workflow (add a Webhook node, POST method, 'Listen for Test Event'), then trigger it with a curl POST to confirm it receives data. Activate the workflow so the webhook works in production. Your Python agent triggers workflows by POSTing to the webhook URL.

import requests, os
def trigger_workflow(data: dict) -> dict:
    url = os.getenv('N8N_WEBHOOK_URL')
    return requests.post(url, json=data).json()

Part 7 — Day 4: Memory (Mem0)

Two modes. Cloud (easiest): sign up at mem0.ai, add MEM0_API_KEY to .env. Self-hosted (fully private): run Qdrant in Docker and point Mem0 at a local Ollama model — nothing leaves your machine.

from mem0 import Memory
config = {
  'vector_store': {'provider':'qdrant','config':{'host':'localhost','port':6333}},
  'llm': {'provider':'ollama','config':{'model':'llama3.2:3b','ollama_base_url':'http://localhost:11434'}}
}
m = Memory.from_config(config)
m.add('User always wants code examples in Python', user_id='user1')

Integrate memory by searching relevant memories before each response and injecting them into the system prompt, then saving each interaction back.

Part 8 — Day 5: Code execution (E2B or local Docker)

The agent needs a safe place to run code it writes. E2B cloud (free tier, 100 sandbox hours/mo) or a local Docker sandbox (fully private):

docker run -d --name code-sandbox --network none --memory='512m' --cpus='0.5' python:3.11-slim sleep infinity

The agent writes code with the LLM, strips markdown fences, and executes it in the sandbox — returning only the results. That's the leap from "here's how you'd do it" to "done."

Part 9 — Day 6: Multi-agent (AutoGen)

One agent doing research + writing + editing compromises on all three. Specialized agents each optimized for one role do systematically better. Define a Researcher, a Writer, and a Critic pointed at local Ollama; they collaborate in a group chat until the Critic says APPROVED, and you approve the final output.

local_config = {'config_list':[{'model':'ollama/llama3.2:3b','base_url':'http://localhost:11434','api_key':'ollama'}], 'temperature':0.7}

Running three agents at once loads your machine; use a smaller/faster model for the critic role, or cloud fallback for the research agent.

Part 10 — Day 7: Integration (Chainlit)

Chainlit gives a professional chat UI from a Python script. Create agent.py with an @cl.on_message handler that pulls memories, calls Ollama, saves the interaction, and returns the reply; launch with chainlit run agent.py -w and open http://localhost:8000.

# start.sh  (Mac/Linux)
#!/bin/bash
ollama serve &
docker compose up -d
source venv/bin/activate
chainlit run agent.py -w

Part 11 — The mycelium architecture

Real mycelium has no master node: destroy a section and the network reroutes; nutrients flow from abundance to need. Your agents should work the same — no single point of failure. Agents communicate through a shared database (Redis), not by calling each other directly, which keeps them decoupled and creates an audit trail. Each specialized agent polls for its task type, processes it, and publishes results for the next agent. A retry decorator with exponential backoff and a fallback model gives you resilience — failed tasks reroute instead of crashing the system.

Part 12 — What Claude would build

Seven capabilities worth adding, each with free open-source tools: reliable uncertainty (confidence-scoring + verification via SearXNG/Brave), document understanding (RAG) across your files (Qdrant + Docling + LlamaIndex), real-time web awareness without a subscription (SearXNG, Jina reader r.jina.ai/<url>), voice in/out (faster-whisper + Piper TTS), structured extraction from anything (Instructor + Pydantic), proactive task anticipation (APScheduler + Mem0), and an ethical self-check before any irreversible external action (Guardrails AI + a manual confirmation step).

Part 13 — Cloud fallbacks (when local isn't enough)

Local by default, cloud when needed. OpenRouter gives 100+ models pay-per-use, no subscription (~$1–5/mo for a personal agent's fallback usage). Free options that actually exist: Groq (14,400 requests/day free, extremely fast), Together AI ($1 signup credit), Google AI Studio (free Gemini tier), and renting a GPU VPS by the hour (Vast.ai, $0.10–0.30/hr) only when you need power. Because of LiteLLM, switching local→cloud is one line.

Part 14 — Security best practices

Never hardcode keys — load from .env via python-dotenv, and rotate anything ever committed. Isolate Docker services that don't need the internet on an internal network. Back up three things weekly: code (Git), database volumes (Docker volume tar), and your .env (separately, securely). Scope agent permissions to least privilege: a dedicated agent Gmail account (draft, don't send), a restricted working directory, hard spend limits on cloud APIs, and explicit confirmation for any irreversible action.

Part 15 — Integrations (Email, Calendar, Notion, GitHub, Slack)

All bridge through n8n: the agent POSTs a structured request to an n8n webhook, and n8n handles the actual API call with its built-in integrations. Gmail — configure the node to Draft, not Send, and review before sending. Calendar — read/create events via the same Google OAuth. Notion — official API, generous free tier; create pages and append to databases. GitHub — a Personal Access Token scoped to only what's needed (PyGithub for issues). Slack — an Incoming Webhook to post to a channel without complex OAuth.

Part 16 — Troubleshooting

The errors you'll actually hit: Ollama 'model not found' (ollama pull), 'context length exceeded' (truncate or use a 128K-context model), 'connection refused' (start ollama serve); Docker 'port already allocated' (change the port mapping), containers restarting (check docker compose logs), 'no space left' (docker system prune -a); Python ModuleNotFoundError (activate the venv), dependency conflicts (fresh venv); Qdrant/Mem0 connection refused (start the container); n8n workflows not triggering (activate the workflow, re-authorize expired OAuth).

Part 17 — Testing framework

Never assume a component works — verify each before adding the next. Build one verify_stack.py that checks Docker, Ollama, an LLM response, n8n, Qdrant, and Redis, printing OK/FAIL with a specific error for each. Run it any time something seems broken and you'll know exactly which layer to debug. A per-day verification checklist confirms each day's build before you move on.

Part 18 — Legal and ethical boundaries

Always allowed: automating your own work, scraping public data, using open-source models, building personal tools. Never: accessing others' accounts, scraping private/password-protected data, impersonating a human without disclosure, spam or harassment tools. Scraping public pages is legal (hiQ v. LinkedIn) — but check robots.txt, rate-limit, identify your scraper, and don't log in where ToS forbids bulk downloads. Social automation is usually a ToS violation (account-ban risk), not a legal one — know the difference. The impersonation bright line: if a reasonable person sincerely asking whether they're talking to an AI would be deceived, that's the line — agents disclose they're AI when sincerely asked.

Part 19 — FAQ (selected)

Need a GPU? No — CPU runs 3B–7B models fine for background work. 8GB RAM? Yes, start with llama3.2:3b and close other apps. Raspberry Pi? Pi 4/5 (8GB) runs small models slowly — fine for lightweight tasks. Overheating? High CPU/GPU use is normal and thermally safe; a cooling pad helps long sessions. Use Claude/GPT-4 too? Yes, via LiteLLM — change one model string. Agent vs chatbot? A chatbot describes; an agent executes — it has tools and uses them to actually do things.

Part 20 — Checklists & the complete stack

The guide includes a full 7-day build checklist (verify each day green before moving on), a complete .env template, and the full docker-compose.yml for the whole stack:

services:
  n8n:    { image: n8nio/n8n, restart: always, ports: ['5678:5678'], volumes: [n8n_data:/home/node/.n8n] }
  qdrant: { image: qdrant/qdrant, restart: always, ports: ['6333:6333'], volumes: [qdrant_data:/qdrant/storage] }
  redis:  { image: redis:alpine, restart: always, ports: ['6379:6379'], volumes: [redis_data:/data] }
volumes: { n8n_data:, qdrant_data:, redis_data: }

Part 21 — Free resources

Core stack: ollama.ai · github.com/BerriAI/litellm · n8n.io · github.com/microsoft/autogen · github.com/mem0ai/mem0 · docs.chainlit.io · e2b.dev · qdrant.tech. Learning: fast.ai · Andrej Karpathy's YouTube · DeepLearning.AI short courses · Hugging Face course. Models: huggingface.co · ollama.ai/library · llama.meta.com · mistral.ai. Community: r/LocalLLaMA · r/ollama · community.n8n.io. Safety: SearXNG · Guardrails AI · NeMo Guardrails · Instructor.


You just built something that didn't exist for you before this week — a system that runs on your own hardware, with data you control, that gets more capable every day you use it. Start with Day 1: get docker run hello-world to print its message. Everything else follows from that.

Found this useful? Name your price — 70% goes straight to the Palestinian Children's Relief Fund.

Pay what you want →