Small teams lose good leads all the time. Someone fills in the contact form, the founder is busy with sales, the product and support, and the reply goes out two days later. By then, the lead has often found someone else.

So I built two connected teams of AI agents with Claude. The Lead Loop sorts every new enquiry and drafts a reply, and the Demand Engine works out how to bring more of the right people in. AI writes the drafts, and a person approves everything before it goes out.

The code is free and open source, so you can install it in your own accounts. I tested it on my own studio first, and every screenshot on this page comes from that test. All the leads in it are made up.

Why leads go cold

Harvard Business Review audited 2,241 US companies. The ones that tried to reach a new lead within an hour were nearly seven times more likely to qualify it than the ones that waited even an hour longer. The average reply took 42 hours, and 23% of the companies never replied at all (Oldroyd et al., 2011).

In a small team, it's nobody's job to sort the inbox. Good leads sit next to spam, and the follow-up waits until there's time. Being found is hard too. When I asked Claude what BYCN.studios is, it guessed a design firm, a game studio or a music label.

How the Lead Loop works

  1. A lead arrives. Someone fills in your contact form, and n8n picks it up.
  2. Claude reads and scores it. The Lead agent checks for spam, scores the lead out of 100 against the rules in your company file and writes a reply draft in the lead's own language.
  3. It's saved in HubSpot. Every real lead is saved with its score, its group, a short summary and the reply draft.
  4. You get an alert. When a lead is hot, an email arrives with the reasons for the score and the draft to check.
  5. You decide. Nothing is sent to the lead automatically. You read the draft, change what you want and send it yourself.
The workflow in n8n after the test run. 20 leads went in, 3 were stopped as spam, 17 were saved to HubSpot and 6 sent an alert.
A hot-lead alert. You see why the lead scored 100 and get a reply draft to check.
The score and group saved on each contact in HubSpot.

The test

I wrote 20 made-up leads with an answer key, from a robotics founder in Oslo to an SEO spammer, and ran them through Claude Haiku 5.5.

Test resultNumber
Leads in the right group20 of 20
Hot leads flagged with an alert6
Spam stopped with no reply3
Cost for all 20 leadsUS$0.016
Time for all 20 leadsAbout 107 seconds

These are test results on made-up leads. They show the system works the way it was planned, not how many customers it will bring you.

The Demand Engine

Sorting leads only helps if people can find you. The Demand Engine is eight agents that run one after the other, each building on what the others found.

AgentWhat it does
MarketFinds who is most likely to buy and what makes them start looking for help
CompetitorCompares how similar studios and agencies describe and price their work
SEOChecks how the site shows up on Google and drafts clearer page titles
AI searchAsks AI assistants the questions buyers ask and checks whether they mention you
StrategistTurns it all into one positioning line and a 30-day plan
SocialDrafts LinkedIn posts that follow the plan
OutboundDrafts one-to-one follow-up messages for a person to send
ReviewChecks the post and message drafts against the facts before you see them

When I ran it on my own studio, it found that my services page offered a free first chat with no way to book one, and that the site didn't come up when you searched Google for its own name. Both went into the first week of the plan, and the booking link is now on the site. The whole run cost about US$1.83 in API credits.

The two engines work together. The Demand Engine brings the right people to your site, and the Lead Loop makes sure each of them gets a fast, personal answer.

Inside the repository

camzymb / ai-marketing-engine PublicMIT licence

Two connected Claude agent teams for small B2B companies, a Demand Engine and a Lead Loop, with a person approving everything.

  • agents/ The Lead, Audit, Report, Content and Review agents
  • context/ Your company file, plus a filled-in example
  • demand-engine/ The Demand Engine agents and the script that runs them
  • demo/ A dashboard to watch a test run on your own computer
  • docs/ The n8n setup, click by click
  • scripts/ Builds the prompts and the n8n workflow from your settings
  • test-data/ 20 made-up leads and their answer key
  • INSTALL.md Setup guides for Windows, Mac and Linux
  • PRIVACY.md A GDPR checklist for using it with real leads
  • README.md What it is and a quick start
  • SECURITY.md How your keys and your leads' data are protected
Open it on GitHub

Install it yourself

Trying it on your own computer takes about 20 minutes, and connecting n8n, HubSpot and Gmail takes about 45 more. You need a Claude API key, Node.js 18 or newer, Python 3.10 or newer and Git. The full guides for Windows, Mac and Linux are in INSTALL.md.

Step 1. Get a Claude API key

Make one in the Claude Console under API keys, and give it a low spend limit first, like $5. A full test run of all 20 leads costs about two cents.

Step 2. Download the project

Open Terminal on a Mac or Linux, or PowerShell on Windows, and run this.

git clone https://github.com/camzymb/ai-marketing-engine.git
cd ai-marketing-engine

Step 3. Add your settings

Paste your API key after ANTHROPIC_API_KEY= and add your name and the email for alerts. The .env file stays on your computer and is never uploaded. On Windows, use copy instead of cp and notepad instead of nano.

cp .env.example .env
nano .env

Step 4. Describe your business

Copy the template and fill it in with who you sell to, your prices and what a good lead looks like for you. Then set CONTEXT_FILE=context/my-company.md in .env. The agents score and write from this file, so the more honest it is, the better they get.

cp context/template.md context/my-company.md

Step 5. Try a dry run

Build the prompts and start the demo, then open http://127.0.0.1:8787/dashboard.html in your browser. The dry run uses no credits, and you can watch the dashboard go through the 20 test leads. On Windows, use py instead of python3.

python3 scripts/build.py
node demo/server.js --mock
What the dry run looks like in your browser.

Step 6. Connect n8n, HubSpot and Gmail

Import n8n/lead-loop.json into n8n, add four AI fields to your HubSpot contacts, and connect your Claude, HubSpot and Gmail accounts. The guide in docs/lead-loop-setup.md shows every click, and it takes about 45 minutes.

Step 7. Run the 20 test leads

In n8n, click Run 20 test leads and compare the results with the answer key in test-data. When every lead lands in the right group, you can connect your real contact form.

Step 8. Run the Demand Engine

Fill in demand-engine/evidence/my-evidence.md with what you already know about your market, check the cost with a dry run, then run it for real. The plan and the drafts land in demand-engine/runs.

python3 demand-engine/run.py --dry
python3 demand-engine/run.py

Safety and privacy

  • No agent can send, post, buy or delete anything. They only write drafts.
  • Your API key stays in your own .env file or in n8n's credential store, never in the code.
  • The Lead agent treats what a lead writes as information only, so nobody can take it over by typing instructions into your form.
  • The repo includes a GDPR checklist for using it with real leads in Europe.

What I'm working on next

Next, I'm connecting my own website's contact form to the Lead Loop, so real enquiries go through it. I'm also filming a walkthrough of the install, and it will go on this page.

If you'd like help setting it up for your business, book a free first chat.

References

Back to Portfolio