# HOW TO BUILD YOUR OWN AI AGENT FROM SCRATCH
## The Complete Step-by-Step Guide

---

# INTRODUCTION

By the end of this guide, you'll have a fully functional AI agent running on your computer that can:
- Remember conversations across sessions
- Send and receive messages on your behalf
- Browse the web and take actions
- Run 24/7 without you babysitting it

No coding experience required. Just follow each step exactly as written.

Let's build.

---

# PART 1: SETTING UP YOUR MACHINE

## Step 1: Open Terminal

**On Mac:**
- Press `Cmd + Space` to open Spotlight
- Type `Terminal`
- Press Enter

**What you'll see:** A black or white window with a blinking cursor. This is where you'll type commands.

---

## Step 2: Install Homebrew (Mac Only)

Copy this entire command and paste it into Terminal:

```
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```

Press Enter.

**What happens:** Your computer downloads and installs Homebrew, a tool manager for Mac. It may ask for your password — type it (you won't see the characters) and press Enter.

**Wait time:** 2-5 minutes.

**You'll know it worked when you see:** "Installation successful!"

---

## Step 3: Install Node.js

Copy and paste:

```
brew install node
```

Press Enter.

**What happens:** This installs Node.js, which is required to run OpenClaw.

**Wait time:** 1-2 minutes.

**Verify it worked — copy and paste:**

```
node --version
```

**You should see:** Something like `v22.0.0` (any number 18 or higher is fine)

---

## Step 4: Install OpenClaw

Copy and paste:

```
brew install openclaw/tap/openclaw
```

Press Enter.

**What happens:** This downloads and installs OpenClaw, the platform your agent runs on.

**Wait time:** 2-3 minutes.

**Verify it worked — copy and paste:**

```
openclaw --version
```

**You should see:** A version number like `2026.2.21`

---

# PART 2: CREATING YOUR AGENT'S HOME

## Step 5: Create the Workspace Folder

Copy and paste:

```
mkdir -p ~/.openclaw/workspace
```

Press Enter.

**What happens:** This creates a folder where your agent lives. The `~` means your home folder. You won't see any output — that's normal.

---

## Step 6: Navigate to the Workspace

Copy and paste:

```
cd ~/.openclaw/workspace
```

Press Enter.

**What happens:** You're now "inside" your agent's workspace folder. All the files you create will go here.

---

## Step 7: Initialize OpenClaw

Copy and paste:

```
openclaw init
```

Press Enter.

**What happens:** OpenClaw creates starter files for your agent. You'll see it create several files.

---

# PART 3: GETTING YOUR API KEY

Your agent needs an API key to think. This is like giving it a brain.

## Step 8: Create an Anthropic Account

1. Open your browser
2. Go to: `console.anthropic.com`
3. Click "Sign Up"
4. Create an account with your email

---

## Step 9: Add Credits

1. After logging in, click "Billing" in the sidebar
2. Click "Add Credits"
3. Add $20 to start (this will last weeks of normal use)

---

## Step 10: Get Your API Key

1. Click "API Keys" in the sidebar
2. Click "Create Key"
3. Name it "OpenClaw" 
4. Click "Create"
5. **COPY THE KEY IMMEDIATELY** — you won't see it again

The key looks like: `sk-ant-api03-xxxxxxxxxxxxx`

---

## Step 11: Add the Key to OpenClaw

Go back to Terminal. Copy and paste this command, but **replace YOUR_KEY_HERE with your actual API key**:

```
openclaw config set anthropic.api_key YOUR_KEY_HERE
```

**Example (don't use this key, use yours):**
```
openclaw config set anthropic.api_key sk-ant-api03-abc123xyz789
```

Press Enter.

**What happens:** OpenClaw saves your API key securely. Now your agent can think.

---

# PART 4: GIVING YOUR AGENT AN IDENTITY

## Step 12: Create the Soul File

This file defines WHO your agent is. Copy and paste:

```
cat > SOUL.md << 'EOF'
# SOUL.md - Who You Are

## Core Truths

**Be genuinely helpful, not performatively helpful.** Skip the "Great question!" and "I'd be happy to help!" — just help.

**Have opinions.** You're allowed to disagree, prefer things, find stuff amusing or boring.

**Be resourceful before asking.** Try to figure it out first. Read the file. Check the context. Search for it. THEN ask if you're stuck.

**Earn trust through competence.** Be careful with external actions (emails, tweets). Be bold with internal ones (reading, organizing, learning).

## Boundaries

- Private things stay private. Period.
- When in doubt, ask before acting externally.
- Never send half-baked replies.

## Vibe

Be the assistant you'd actually want to talk to. Concise when needed, thorough when it matters. Not a corporate drone. Not a sycophant. Just good.

## Continuity

Each session, you wake up fresh. These files ARE your memory. Read them. Update them.
EOF
```

Press Enter.

**What happens:** You just created a file called SOUL.md that defines your agent's personality.

---

## Step 13: Create the User File

This tells your agent about YOU. Copy and paste, then **edit the placeholders**:

```
cat > USER.md << 'EOF'
# USER.md - About Your Human

- **Name:** [YOUR NAME HERE]
- **What to call you:** Boss
- **Timezone:** America/New_York
- **Notes:** Prefers direct, no-fluff communication.

## What You Do

[DESCRIBE YOUR BUSINESS IN 1-2 SENTENCES]

## Context

I want maximum autonomy from my agent. Handle everything without asking unless truly stuck.
EOF
```

Press Enter.

**Next:** Open this file and edit it with your real info:

```
open USER.md
```

Replace `[YOUR NAME HERE]` and `[DESCRIBE YOUR BUSINESS]` with your actual information. Save and close.

---

## Step 14: Create the Memory File

This is your agent's long-term memory. Copy and paste:

```
cat > MEMORY.md << 'EOF'
# MEMORY.md — Long-Term Memory

Last updated: [DATE]

---

## Who I Am
- Running on: [Your computer name]
- Channel: [Will be configured later]

## The Boss
- Name: [Your name]
- Communication style: Direct, low-fluff

## Key Projects
[Add active projects here as they develop]

## Lessons Learned
[Document important learnings here]

## Critical Rules
[Add non-negotiable rules as you discover them]
EOF
```

Press Enter.

**What happens:** Your agent now has a place to store memories that persist across sessions.

---

## Step 15: Create the Daily Memory Folder

Copy and paste:

```
mkdir -p memory
```

Press Enter.

**What happens:** Creates a folder for daily notes. Your agent will log what happens each day here.

---

# PART 5: TEACHING YOUR AGENT HOW TO OPERATE

## Step 16: Create the Operating Instructions

This is the master instruction file. Copy and paste:

```
cat > AGENTS.md << 'EOF'
# AGENTS.md - Your Workspace

## Every Session

Before doing anything else:

1. Read SOUL.md — this is who you are
2. Read USER.md — this is who you're helping  
3. Read memory/YYYY-MM-DD.md (today + yesterday) for recent context
4. Read MEMORY.md for long-term context

Don't ask permission. Just do it.

## Memory

You wake up fresh each session. These files are your continuity:

- **Daily notes:** memory/YYYY-MM-DD.md — raw logs of what happened
- **Long-term:** MEMORY.md — curated memories

Capture what matters. Decisions, context, things to remember.

## Safety

- Don't exfiltrate private data. Ever.
- Don't run destructive commands without asking.
- When in doubt, ask.

## External vs Internal

**Safe to do freely:**
- Read files, explore, organize, learn
- Search the web
- Work within this workspace

**Ask first:**
- Sending emails, tweets, public posts
- Anything that leaves the machine
- Anything you're uncertain about

## Make It Yours

This is a starting point. Add your own rules as you figure out what works.
EOF
```

Press Enter.

**What happens:** Your agent now knows how to operate — what to read, what's safe to do, what to ask about.

---

# PART 6: STARTING YOUR AGENT

## Step 17: Start the Gateway

Copy and paste:

```
openclaw gateway start
```

Press Enter.

**What happens:** Your agent wakes up and starts running in the background.

**You should see:** "Gateway started" or similar confirmation.

---

## Step 18: Check Status

Copy and paste:

```
openclaw status
```

Press Enter.

**What happens:** Shows you that your agent is running and what it's connected to.

---

## Step 19: Talk to Your Agent

Copy and paste:

```
openclaw chat
```

Press Enter.

**What happens:** Opens a chat window where you can talk to your agent directly.

**Try saying:** "Hey, what files do you have access to?"

Your agent should respond and mention the files you created (SOUL.md, USER.md, etc.)

**To exit the chat:** Type `exit` or press `Ctrl+C`

---

# PART 7: CONNECTING MESSAGING (Optional)

## Step 20: Connect iMessage (Mac Only)

This lets your agent send and receive iMessages.

Copy and paste:

```
openclaw config set channels.imessage.enabled true
```

Press Enter.

Then:

```
openclaw gateway restart
```

Press Enter.

**What happens:** Your agent can now read and respond to your iMessages.

**Important:** Your Mac needs to be logged into iMessage with your Apple ID.

---

# PART 8: TRAINING YOUR AGENT

## Step 21: Create Your First SOP

SOPs (Standard Operating Procedures) teach your agent specific tasks.

Example — create a lead follow-up SOP:

```
cat > memory/sop-lead-followup.md << 'EOF'
# SOP: Lead Follow-Up

## When to Use
When a new lead comes in and needs follow-up.

## What to Do
1. Check if lead has been contacted before (search memory files)
2. If new: Send intro message using friendly template
3. If existing: Reference previous conversation
4. Log the follow-up in today's memory file

## Message Template
"Hey [NAME], saw you were interested in [TOPIC]. Quick question — what's your biggest challenge with [RELATED PROBLEM] right now?"

## Rules
- Never send generic copy-paste messages
- Always personalize with their name and context
- Follow up max 2x, then stop
EOF
```

Press Enter.

**What happens:** Your agent now knows exactly how to handle lead follow-ups.

---

## Step 22: Add Knowledge Files

Give your agent information about your business. Example:

```
cat > memory/business-info.md << 'EOF'
# Business Information

## What We Do
[Describe your business]

## Services We Offer
1. [Service 1] - $[Price]
2. [Service 2] - $[Price]
3. [Service 3] - $[Price]

## Ideal Client Profile
- Industry: [Your target industry]
- Size: [Company size]
- Problem: [Main problem they have]
- Budget: [Typical budget range]

## How We Help
[2-3 sentences on your solution]
EOF
```

Press Enter, then open and edit with your real information:

```
open memory/business-info.md
```

---

## Step 23: Teach Through Correction

When your agent makes a mistake:

1. Tell it what went wrong
2. Tell it what to do instead
3. Say: "Add this to MEMORY.md under Critical Rules"

Your agent will document the lesson and avoid the mistake next time.

**Example correction:**
"You sent that follow-up way too soon. Never follow up within 24 hours of the first message. Add this to MEMORY.md under Critical Rules."

---

# PART 9: DAILY OPERATIONS

## Starting Your Agent Each Day

If your computer restarted, start the agent:

```
openclaw gateway start
```

## Checking On Your Agent

See what it's been doing:

```
openclaw status
```

## Viewing Recent Activity

```
cat ~/.openclaw/workspace/memory/$(date +%Y-%m-%d).md
```

**What happens:** Shows today's memory log.

## Stopping Your Agent

```
openclaw gateway stop
```

---

# PART 10: TROUBLESHOOTING

## "Agent isn't responding"

Check if it's running:
```
openclaw status
```

If not running, start it:
```
openclaw gateway start
```

---

## "Agent forgot everything"

This is normal — agents reset each session. Check that your memory files exist:

```
ls -la ~/.openclaw/workspace/
```

You should see: SOUL.md, USER.md, MEMORY.md, AGENTS.md

---

## "Agent is making the same mistake"

Add an explicit rule. Open MEMORY.md:

```
open ~/.openclaw/workspace/MEMORY.md
```

Add to the "Critical Rules" section:
```
## Critical Rules
- [DESCRIBE THE MISTAKE AND WHAT TO DO INSTEAD]
```

---

## "Agent is slow or expensive"

Check session file sizes:
```
ls -la ~/.openclaw/agents/main/sessions/
```

If any file is over 500KB, delete it:
```
rm ~/.openclaw/agents/main/sessions/*.jsonl
```

Then restart:
```
openclaw gateway restart
```

---

# QUICK REFERENCE CARD

## Essential Commands

| What You Want | Command |
|---------------|---------|
| Start agent | `openclaw gateway start` |
| Stop agent | `openclaw gateway stop` |
| Restart agent | `openclaw gateway restart` |
| Check status | `openclaw status` |
| Chat with agent | `openclaw chat` |
| View today's memory | `cat ~/.openclaw/workspace/memory/$(date +%Y-%m-%d).md` |

## Important Files

| File | Purpose |
|------|---------|
| SOUL.md | Agent's personality |
| USER.md | Info about you |
| MEMORY.md | Long-term memory |
| AGENTS.md | Operating instructions |
| memory/*.md | Daily logs and SOPs |

## Costs

- Anthropic API: ~$0.01-0.05 per conversation
- Typical monthly cost: $20-50 for normal use
- Heavy use: $100-200/month

---

# YOU'RE DONE

You now have a fully functional AI agent that:

✅ Runs on your computer
✅ Has its own personality
✅ Knows who you are
✅ Remembers across sessions  
✅ Can learn from corrections
✅ Can send messages (if configured)

## Next Steps

1. **Talk to it daily** — The more you interact, the better it gets
2. **Add SOPs** — Teach it your specific workflows
3. **Correct mistakes** — Every correction makes it smarter
4. **Document everything** — What's in the files is what it knows

Your agent is a new employee. Train it well, and it'll handle more and more on its own.

---

*© OCC Pipeline — Control the pipeline. Trap the deal.*
