← All posts
GuideAugust 15, 2026 · 7 min

ai agents vs automations: When to build an autonomous agent and when a simple workflow suffices

What's the difference? An AI agent is a loop-driven system that can decide which tool to call next, keep state across interactions, and adapt its behaviour. An automation is a fixed sequence of steps that runs the same way every time. In this guide you'll build both a plain n8n workflow that sends a prompt to OpenAI and stores the answer, and a full RAG-enabled AI agent that decides when to fetch documents, when to query the LLM, and when to respond. By the end you'll see why most teams over-engineer, and you'll have a production-ready example you can ship tomorrow.

Key insight: If your use-case requires conditional tool use, memory, or dynamic goal-setting, you need an AI agent; otherwise a straight automation is cheaper, faster, and easier to maintain.


What you need

ToolPlan / PriceRole
n8n (open-source workflow engine)Community edition (self-hosted, free) - see <https://n8n.io/pricing> for hosted optionsOrchestrates both automation and agent pipelines
OpenAI API (ChatGPT/GPT-4)Pay-as-you-go - see <https://openai.com/api/pricing>Generates natural-language responses
Pinecone (vector store)Free tier or paid plan - see <https://www.pinecone.io/pricing>Holds document embeddings for RAG
Docker (container runtime)FreeRuns n8n locally or in CI
Git (version control)FreeStores workflow definitions

Estimated build time: ~4 hours for a complete agent (including embedding documents) and ~1 hour for the plain automation.


Step-by-step build

1. Set up n8n locally

bash
# Pull the official n8n Docker image and start it on port 5678
docker run -d --name n8n \
 -p 5678:5678 \
 -e N8N_BASIC_AUTH_ACTIVE=true \
 -e N8N_BASIC_AUTH_USER=admin \
 -e N8N_BASIC_AUTH_PASSWORD=secret \
 n8nio/n8n

What this does: launches a self-hosted n8n instance with basic auth. After a few seconds open <http://localhost:5678> and log in with the credentials above.

2. Create the plain automation workflow

1. In the n8n UI, click New Workflow. 2. Add a Webhook node (trigger URL: /automation). This receives a JSON payload { "prompt": "Your question?" }. 3. Connect the Webhook to an OpenAI node (provided by n8n). - Model: gpt-4o-mini (or whichever you have access to). - Prompt: {{$json["prompt"]}}. 4. Add a Set node to format the LLM output: response = {{$node["OpenAI"].json["choices"][0]["message"]["content"]}}. 5. End with a Respond node that returns { "answer": {{$json["response"]}} }.

Export the workflow JSON so you can version-control it:

json
{
 "nodes": [
 {
 "name": "Webhook",
 "type": "n8n-nodes-base.webhook",
 "parameters": {
 "path": "automation",
 "httpMethod": "POST"
 }
 },
 {
 "name": "OpenAI",
 "type": "n8n-nodes-base.openAi",
 "parameters": {
 "operation": "chatCompletion",
 "model": "gpt-4o-mini",
 "messages": [
 {
 "role": "user",
 "content": "{{$json[\"prompt\"]}}"
 }
 ]
 }
 },
 {
 "name": "Set",
 "type": "n8n-nodes-base.set",
 "parameters": {
 "values": {
 "response": "={{$node[\"OpenAI\"].json[\"choices\"][0][\"message\"][\"content\"]}}"
 }
 }
 },
 {
 "name": "Respond",
 "type": "n8n-nodes-base.respond",
 "parameters": {
 "responseData": "={{$json}}"
 }
 }
 ],
 "connections": {
 "Webhook": {
 "main": [
 [
 {
 "node": "OpenAI",
 "type": "main",
 "index": 0
 }
 ]
 ]
 },
 "OpenAI": {
 "main": [
 [
 {
 "node": "Set",
 "type": "main",
 "index": 0
 }
 ]
 ]
 },
 "Set": {
 "main": [
 [
 {
 "node": "Respond",
 "type": "main",
 "index": 0
 }
 ]
 ]
 }
 }
}

What this does: the JSON defines a linear pipeline - receive a prompt, send it to the LLM, wrap the response, and return it. There is no conditional logic or memory; each request is isolated.

3. Prepare document embeddings for RAG

bash
# Install the official OpenAI Python client
pip install openai tqdm

# Encode a folder of .txt files into vectors and upsert them into Pinecone
python - <<'PY'
import os, openai, pinecone, tqdm

openai.api_key = os.getenv("OPENAI_API_KEY")
pinecone.init(api_key=os.getenv("PINECONE_API_KEY"), environment="us-west1-gcp")

index = pinecone.Index("rag-demo")
folder = "docs"
for filename in tqdm.tqdm(os.listdir(folder)):
 if not filename.endswith(".txt"):
 continue
 with open(os.path.join(folder, filename), "r") as f:
 text = f.read()
 # Create a single embedding for the whole doc (replace with chunking for large files)
 resp = openai.Embedding.create(model="text-embedding-3-large", input=text)
 vector = resp["data"][0]["embedding"]
 index.upsert(vectors=[(filename, vector, {"text": text})])
print("All docs indexed")
PY

What this does: reads each .txt file, generates an embedding with OpenAI's text-embedding-3-large model, and stores the vector in Pinecone. The script uses environment variables for API keys - store them securely (e.g., in a .env file).

4. Build the AI agent workflow

  1. Create a new workflow called RAG Agent.
  2. Add a Webhook node (trigger URL: /agent). Input payload: { "question": "How does X work?" }.
  3. Add a Function node named DecideAction. Its JavaScript decides whether a document lookup is needed:
javascript
// Very simple heuristic: if the prompt contains the word "explain", fetch docs
const prompt = $json["question"];
if (prompt.toLowerCase().includes("explain")) {
 return [{ action: "retrieval", query: prompt }];
}
return [{ action: "direct", query: prompt }];
  1. Connect DecideAction to a Switch node that branches on action.

- Branch "retrieval": a. Pinecone Search node (n8n has a community Pinecone node; if not, use an HTTP Request node). - Namespace: rag-demo. - Query vector: compute on-the-fly using OpenAI's embedding endpoint (text-embedding-3-large). - Top K: 3. b. Merge node to concatenate retrieved text fields. c. Feed the concatenated context and original question to an OpenAI node (prompt: Context: {{ $json["context"] }}\nQuestion: {{ $json["question"] }}) and return the answer.

- Branch "direct": a. Send the original question straight to an OpenAI node (same model, no context).

  1. Close each branch with a Respond node that returns { "answer": ... }.

Export the workflow; the JSON will be larger because of the conditional logic, but the core principle is the same: the agent retains state (action) and decides which tool to call next.

5. Test both endpoints

bash
# Test automation (fixed pipeline)
curl -X POST http://localhost:5678/webhook/automation \
 -H "Content-Type: application/json" \
 -d '{"prompt":"What is the capital of France?"}'

# Test agent (dynamic pipeline)
curl -X POST http://localhost:5678/webhook/agent \
 -H "Content-Type: application/json" \
 -d '{"question":"Explain the difference between supervised and unsupervised learning."}'

What you should see: the automation returns a single sentence answer; the agent may include relevant excerpts from your indexed docs before the LLM's answer, demonstrating true tool use.

6. Deploy (optional)

If you prefer a managed n8n instance, sign up at <https://n8n.io> and import the JSON files via the UI. For production you'll also want to:

  • Enable HTTPS with a reverse proxy (e.g., Nginx).
  • Store API keys in environment variables (OPENAI_API_KEY, PINECONE_API_KEY).
  • Set rate limits on the webhook nodes to protect against abuse.

You can now sell these automations as part of a service offering - see the catalog at https://getaab.com/ai-automations-to-sell for ready-made ideas.


Where this breaks

Failure modeSymptomFix
OpenAI rate-limit429 Too Many Requests from the OpenAI nodeBack-off with exponential delay; consider batching requests or upgrading your OpenAI quota (see the pricing page).
Pinecone vector limitUpsert error or missing resultsVerify your current plan's vector quota; prune old vectors or migrate to a higher tier (check Pinecone's pricing).
n8n authentication lapseWebhook returns 401 UnauthorizedRefresh the basic auth password in the Docker environment or switch to OAuth if you move to the hosted service.
Embedding latencyLong delay before the agent can query PineconeCache embeddings locally or pre-compute them offline; avoid generating an embedding on each request.
Branching logic errorAgent always takes the "direct" path even for retrieval queriesEnsure the DecideAction function correctly parses the incoming JSON; check $json["question"] naming.
Cost surpriseMonthly bill spikes due to high LLM usageAdd a usage monitor (n8n's built-in analytics or external logging) and set hard caps on token count per request.

For a deeper technical reference, see n8n's documentation.

FAQ

What is an AI agent? An AI agent is a system that loops: it receives input, decides which tool (LLM, database, API) to invoke, possibly updates an internal state, and repeats until a goal is satisfied.

When should I choose a plain automation over an agent? Pick a plain automation when the process is deterministic - no branching, no need to fetch external knowledge, and no requirement to remember prior steps. It's cheaper, faster to develop, and easier to debug.

How does the RAG component fit into an AI agent? RAG (Retrieval-Augmented Generation) supplies external context to the LLM. In the agent example, the decision node routes the question to a Pinecone search, merges retrieved texts, and feeds them into the LLM, enabling factual answers that go beyond the model's internal knowledge.

Can I run this stack entirely self-hosted? Yes. All components - n8n, OpenAI client, and Pinecone (via its managed service) - can be run from Docker with environment variables for keys. The only cloud-hosted piece is the OpenAI API, which you must access via the internet.

How do I monitor usage to avoid surprise bills? Use n8n's Execution Statistics panel, or export logs to a monitoring service (e.g., Datadog). Track two metrics: LLM token count per request and Pinecone query volume. Set alerts when thresholds approach your plan limits.

Where can I find more ready-made automations? Explore the curated list at https://getaab.com/ai-automations-to-sell and the detailed RAG example in the vault at https://getaab.com/vault/support-agent-rag.


If you're ready to ship a robust AI-powered solution, start with the simple automation, then evolve it into an agent when you hit the "needs tool use" wall. The distinction between ai agents vs automations isn't academic - it's the difference between a one-off script and a scalable, maintainable product.

Get started for free: https://getaab.com/free

Get the full toolkit

Grab the free guide with the node-by-node build for all 10 automations.

No spam. Unsubscribe anytime. Just the good stuff.