Blog / Tutorials / How to Build a Self-Hosted AI Sales Agent for Lead Research and Outreach

How to Build a Self-Hosted AI Sales Agent for Lead Research and Outreach

The most reliable approach isn't a single autonomous chatbot — it's a workflow system with an LLM in the middle: n8n handles orchestration, Ollama runs the model, and deterministic code controls who gets contacted, when, and whether a message is actually allowed to send. That…

7 min read

The most reliable approach isn’t a single autonomous chatbot — it’s a workflow system with an LLM in the middle: n8n handles orchestration, Ollama runs the model, and deterministic code controls who gets contacted, when, and whether a message is actually allowed to send. That last part matters as much as the AI itself — a self-hosted sales agent that skips compliance and suppression checks is a liability, not an asset.

Why a Workflow System, Not a Fully Autonomous Agent

It’s tempting to frame this as “build an AI that does outreach for you,” but the more reliable mental model is narrower: the AI researches and drafts, while deterministic code — not the model — decides who gets contacted, when, and whether a given message is cleared to send. This isn’t a limitation so much as the right division of labor: language models are good at research synthesis and personalized drafting, and bad at being trusted with irreversible actions like sending an email to a real person. A human approval step before anything actually goes out is the difference between a useful tool and a compliance incident waiting to happen.

The Reference Architecture

A practical pipeline looks like this: leads come in from a CRM export, a form, or a CSV, get normalized and deduplicated, then pass to a research agent that gathers company and role context and extracts likely pain points. That research lands in a PostgreSQL lead database, which feeds a personalization agent that drafts an outreach angle and message. Before anything sends, a policy and QA layer checks for opt-outs, duplicates, and confidence thresholds — and only then does a message go to a human for final approval. Each stage is a discrete, inspectable step, not a black box.

The Stack: n8n, Ollama, PostgreSQL

n8n handles workflow orchestration — it has documented self-hosted agent support, native PostgreSQL integration, and an Ollama connector, and n8n’s own Self-Hosted AI Starter Kit bundles n8n, Ollama, Qdrant, and PostgreSQL together as a ready-to-run Docker Compose template. Ollama serves the language model — either a smaller model running locally for full data control, or configured to call an external API if you’d rather not manage local inference. PostgreSQL stores the lead database and pipeline state; Qdrant (or pgvector) handles vector search if you want the research agent to draw on your own knowledge base rather than the open web alone. All of it runs in Docker Compose on a single VPS to start.

The Compliance Layer Most Tutorials Skip

This is an architectural requirement, not a footnote. In the US, CAN-SPAM applies to commercial email, including B2B outreach — it requires accurate header information, non-deceptive subject lines, a physical postal address, a working opt-out mechanism, and promptly honoring opt-outs. If you’re contacting people in the UK or EU, the rules differ meaningfully: UK PECR generally restricts marketing messages to individuals without consent or a qualifying soft opt-in, with different treatment for corporate subscribers, and GDPR’s legitimate-interest basis has its own conditions for B2B marketing contact. The practical fix is a suppression table in your database — tracking email, domain, reason, source, and date added — checked automatically before any message is allowed to send, not relied on as a manual step someone might forget. This is general information, not legal advice — confirm current requirements for your specific jurisdiction and use case before sending real outreach.

VPS Sizing for This Stack

Choosing between an API-based LLM and a self-hosted local model changes the VPS spec, GPU requirement, and data-residency posture for the whole pipeline:

VPS Sizing: API-Based vs. Local-Model PathsChoosing between an API-based LLM and a self-hosted local model changes the VPS spec, GPU requirement, and data-residency posture.
PathMinimum SpecContabo PlanNotes
API-based LLM (Claude, GPT, Gemini)4 vCPU / 8 GB RAM / 100 GB SSDCloud VPS 4 (€5.24/mo)Model calls go to the provider’s API; your VPS runs n8n, PostgreSQL, and orchestration only
Local model via Ollama (7-13B, CPU)8 vCPU / 24 GB RAM / 300 GB SSDCloud VPS 8 (€13.33/mo)CPU-only inference is workable for lead research/drafting at moderate volume, not for real-time chat-speed responses
Local model via Ollama (GPU-accelerated)GPU + 8 GB+ VRAM depending on model sizeContabo GPU Cloud (verify current pricing)Needed if response latency or model size makes CPU inference too slow for your volume

Start with the API-based path unless data residency specifically requires local inference — it’s simpler to operate and the VPS cost difference is small relative to API token costs at most lead volumes.

When to Use a Pre-Built Framework Instead

Everything above assumes you’re assembling the pipeline yourself from n8n, Ollama, and PostgreSQL — the right call if you want full control over each stage and are comfortable maintaining a custom workflow. If you’d rather start from a more complete reference architecture with an agent framework, memory, and CRM wiring already built in, see our guide to building a self-hosted Hermes AI SDR — it covers the same underlying compliance and VPS-sizing considerations, packaged around a ready-made agent stack rather than one you assemble node by node.

FAQ: Self-Hosted AI Sales Agents

How can I build a self-hosted AI sales agent that automates lead research and outreach on my own server?

Build it as a workflow system, not a single autonomous agent: n8n for orchestration, Ollama for model serving, and PostgreSQL for the lead database, with a deterministic policy layer checking opt-outs and confidence thresholds before anything sends. n8n’s own Self-Hosted AI Starter Kit bundles the core components together as a starting point.

Is n8n or a dedicated AI agent framework better for a self-hosted sales agent?

n8n is the better starting point if you want visibility into and control over every step — lead normalization, research, drafting, and the compliance checks are all separate, inspectable nodes. A dedicated agent framework can be faster to get running but gives you less granular control over exactly when and how a message gets approved to send, which matters more for outreach than for most other automation tasks.

What compliance rules apply to AI-assisted cold outreach?

In the US, CAN-SPAM applies to commercial email including B2B outreach, requiring accurate headers, a real postal address, and a working opt-out mechanism. UK and EU contacts fall under PECR and GDPR respectively, which are more restrictive about marketing contact without consent or a qualifying interest. Build a suppression list checked automatically before sending, and treat this as a genuine legal question for your specific situation — this is general information, not legal advice.

What VPS specs do I need to run this stack?

For an API-based LLM setup, 4 vCPU / 8 GB RAM covers n8n, PostgreSQL, and orchestration comfortably. If you’re running a local model via Ollama, plan for 8 vCPU / 24 GB RAM for CPU-only inference at moderate volume, or a GPU instance if response speed or model size makes CPU inference too slow.

Disclaimer: Product specifications, features, and prices mentioned in this article are subject to change and may vary by region, billing term, and active promotions. This article provides general information, not legal advice — consult a qualified professional for guidance specific to your compliance obligations. Please check each provider’s or brand’s official website for current figures and pricing.