AI Agent for Beginners: From Architecture to Automated Sales Lead Enrichment

AI agents form goal-driven loops from model, instructions, memory, and tools—automating sales lead research and email drafting.
Based on a freeCodeCamp course, this article breaks down AI agents from concept to runnable workflow. It distinguishes chatbots from agents, explains the four building blocks—model, instructions, memory, and tools—and why outdated data and simple HTTP requests break agents. It then builds a sales lead enrichment agent in both n8n and Python, ending with production reliability tips and emerging standards MCP and Agent Skills.
AI Agent for Beginners: From Architecture to Automated Sales Lead Enrichment
While chatbots like ChatGPT are still stuck in the single-turn "you ask, I answer" loop, AI agents can already plan their own steps, call tools, observe results, and iterate continuously toward a goal. In a hands-on course on freeCodeCamp, Beau Carnes uses a real-world "sales and lead enrichment agent" scenario to break down agent architecture, tool calling, memory mechanisms, and engineering details in full. This article is based on that course and traces the key path from concept to a runnable workflow.
The Essential Difference Between Chatbots and AI Agents
A standard large model is like a genius locked in a room with no real-time information—it excels at writing, summarizing, and reasoning, but it cannot take action on its own. Ask it to write a cold email to a contact at a certain company, and it can only generate a generic template based on training data; it neither knows what product the company recently launched nor what its pricing page currently says.
The shift with agents is this: give the model a goal, a set of tools, and the authority to autonomously decide which tools to call in a loop until the goal is complete. For the same email-writing task, the agent first reasons "I need to learn about this company," then calls a search tool to read the results, determines that it needs to crawl the official website and news pages, evaluates lead quality based on real-time content, and only then outputs a score and a personalized email.
The course distinguishes two easily confused concepts: an AI Agent is a single autonomous worker with a clear role and toolset; Agentic AI is a broader system paradigm emphasizing planning, tool use, self-checking, and multi-agent collaboration. The course's advice is pragmatic—don't start by building a multi-agent cluster. Begin with a focused, reliable agent, and only consider splitting it when a single agent's instructions or toolset become too complex.

Five Types of Agents Already in Production
The course surveys five agent forms that enterprises actually deploy, helping clarify where the sales lead agent fits:
- Research and enrichment agents: Take a company name or domain, crawl live web pages, news, and competitor pricing, and output structured reports or CRM updates. This is exactly the type built in this course.
- Customer service and triage agents: Connect to help desks and knowledge bases, check order status, answer policy questions, tag tickets, and hand complex issues to humans along with a summary.
- Coding and DevOps agents: Read code repositories, run tests, modify files, and submit PRs, such as tools like Claude Code and Cursor.
- Operations and workflow agents: Integrate with Slack, Google Workspace, and Notion to automate internal tasks such as invoice routing, meeting notes, and onboarding processes.
- Data analysis agents: Translate natural-language business questions into SQL queries, execute them, and generate charts.
What these forms share is that the large model alone is not enough—value comes from combining the model with the right architecture and real-world tools.
ICP (Ideal Customer Profile) is a foundational concept in sales and marketing, referring to the type of customer that best matches a company's product value and that the company most wants to acquire. An actionable ICP is usually made up of quantifiable dimensions, such as industry, company size, tech stack, funding stage, geography, and recent trigger events (e.g., new product launches or hiring expansion). In an agent scenario, the ICP must be written as machine-decidable scoring rules—each dimension given a weight and threshold—so the model can output a stable match score and qualification level. If the ICP description is vague, the agent degenerates into a chatty bot that scores by feel, which is why the course includes detailed ICP criteria as a core part of the system prompt.
The Four Core Building Blocks: Model, Instructions, Memory, Tools
Whether you use LangGraph, CrewAI, or a few hundred lines of Python, the skeleton of an agent is basically the same:
The model is the brain. The course uses GPT-4.1, valuing its stability in tool calling and adherence to structured JSON schemas, with cost and speed suitable for a teaching project.
Instructions are the job description. The course repeatedly emphasizes a rule of thumb—good agent engineering is about 70% clear instructions and clean tool definitions, and only 30% fancy code. The system prompt needs to spell out: who you are, what the company sells, the specific scoring criteria for the ideal customer profile (ICP), which tools to use in what order, and what the final output format is.
Memory has two layers. Short-term memory is the scratchpad within a single run, recording what has been searched, which URLs have been crawled, and what the pages said; underneath, it is simply the message history passed back to the model at each step. Long-term memory persists across runs and can be a Google Sheet, a CRM, or a vector database. In the n8n workflow, the AI Agent node automatically manages short-term memory, while Google Sheets serves as the persistent record.
Tools are the hands, feet, and eyes. Each tool consists of three parts: a name, a description of its purpose written in natural language, and input parameters. The course specifically warns that descriptions must clearly state "when and why" to use the tool, as this directly affects the model's accuracy in choosing tools.
The Agent Loop: Think, Call, Observe, Repeat
The heartbeat of an agent in actual operation can be illustrated with a concrete example:
- A trigger receives a new lead, such as a company submitting a form;
- The model reads the instructions and input, determines it has no information about the company yet, and decides to call the search tool;
- The runtime executes the API call and writes the results to memory;
- The model wakes up, reads the search results, finds the official website link and a launch announcement, and decides to call the crawling tool;
- The runtime crawls the pages and appends clean Markdown to memory;
- Now sufficiently informed, the model calls no more tools and directly generates the final structured JSON, ending the loop.
This "think—call tool—observe—repeat—finish" loop is the entire core mechanism of an AI agent.
Why Static Data and Simple HTTP Requests Break Agents
The course attributes the primary reasons beginner agents fail in production to two things: relying on outdated training data, and crawling web pages with simple HTTP GET requests.
Company positioning, pricing, funding, and product launches change almost weekly. If a sales agent cites product features from two years ago in an email, or even hallucinates a funding round that never happened, prospects will be lost immediately and brand credibility will suffer.
Giving the agent a simple curl or requests tool doesn't work either: modern SaaS sites built with React or Next.js often return only an empty root div to ordinary HTTP requests; data-center IPs get blocked by anti-bot mechanisms, receiving CAPTCHAs or 403s; and even when a request succeeds, the response is raw HTML full of scripts, styles, and nested divs—often hundreds of KB—which both consumes a large number of tokens and easily confuses the model's judgment.
The course's solution is to integrate a dedicated web data API (the example uses Oxylabs Web API). It provides two endpoints: a search endpoint that returns real-time ranked results with titles, URLs, and snippets, with geo-targeting support; and a crawl endpoint that renders JavaScript on demand, handles proxies and anti-bot measures, and directly returns clean Markdown suitable for model reading, or extracts structured JSON based on a natural-language prompt. The agent therefore needs only a small number of tokens to obtain accurate, real-time facts.
JavaScript rendering and anti-bot mechanisms are key to understanding the difficulty of web data acquisition. Sites built with modern frontend frameworks (React, Next.js, Vue) often have an HTML skeleton containing only an empty root element, with the real content dynamically injected after the browser executes JavaScript. Ordinary HTTP requests do not execute scripts, so they receive an empty shell. In addition, protective services such as Cloudflare identify automated traffic through TLS fingerprints, IP reputation, and behavioral characteristics; data-center IPs are easily blocked and receive CAPTCHAs. Dedicated web data APIs bypass these restrictions by rendering pages in a headless browser, rotating residential proxy pools, and simulating real browser fingerprints, then cleaning the DOM into pure Markdown—giving the model readable facts at minimal token cost.
Building a Runnable Sales Lead Agent in n8n
The course chooses n8n as the visual building platform and also provides an equivalent Python implementation so learners can compare the two. The complete workflow's node sequence is as follows:
Trigger: A new company record is added to a Google Sheet (an n8n form trigger can also be used).
AI Agent node: Connected to the OpenAI chat model and configured with an SDR system prompt—defining your product, ICP scoring criteria, a research checklist, and email style rules (e.g., no more than 120 words, and no clichés like "hope this email finds you well").

Tool 1: Web search. The query parameter is set to "defined by the agent," letting the model generate search terms at runtime; results are limited to 5, and a country is specified. No need to hand-write HTTP headers or stitch together JSON.
Tool 2: Web crawl. The URL is likewise dynamically determined by the agent, the output format is set to Markdown, and JavaScript rendering is enabled to ensure modern frontend sites render fully.
Structured output parser: Attached to a JSON Schema, forcing the agent to return fixed fields including ICP match score, qualification level, qualification rationale, company summary, recent news, talking points, email subject, and email body.
Write back to Google Sheet: First map the parsed results into fields via an Edit Fields node, then use the Google Sheets Update Row node to match by company name and write the research results and email draft back into the same row.
The course also suggests branching to a Gmail draft-creation node, so sales reps can open their inbox in the morning and find drafts waiting for review.
The "defined by the agent" parameter in n8n is key to understanding how tool nodes cooperate with the model. When this option is checked, n8n does not hard-code the query or URL in the node configuration; instead, it declares the parameter as part of the tool schema and lets the model generate the concrete value at runtime based on context. This enables truly dynamic tool calling: the agent first reasons about "what to search for," then decides "which link to crawl." Paired with it, the structured output parser constrains the set and types of fields the model ultimately returns via JSON Schema, so downstream nodes (such as Edit Fields and Google Sheets) can map against fixed field names without parsing free text. Together, the two control input flexibility and output determinism respectively.
Testing: Different Leads, Different Strategies
In actual runs, the same workflow, without changing any prompt, behaves noticeably differently across companies. When testing a tech company, the agent automatically generates targeted search terms, crawls the official website and news pages, assigns a qualification level of "hot," and references recent news in the email. Switch to another tech company, and the talking points, email subject, and body perspective change accordingly. Input a local bakery, and the agent gives a very low match score and a "cold/disqualified" rating, politely explaining in the email that the business is not relevant.
This "knows when to say no" test is specifically emphasized in the course—many people skip it when building agents, yet it is precisely the key signal for judging whether an agent is production-ready.
Python Implementation: Code Mapping of the Same Architecture
The course uses a piece of Python code to show the real logic behind the visual workflow: loading environment variables, defining two web API functions (crawl results truncated to 8,000 characters to control the token budget), declaring JSON tool schemas equivalent to the n8n tool nodes, reusing the same system prompt and ICP scoring criteria, and finally the core agent loop—initializing a message list as short-term memory, repeatedly calling the model within a maximum number of steps, executing the tools the model requests, and appending results back to the message list.

Visual orchestration and hand-written code are not two different worlds; they implement the same loop of "model + instructions + memory + tools."
Five Reliability Recommendations for Production
The course offers several highly practical recommendations for the deployment phase:
- Always set a maximum number of iterations. The course author once forgot to set a limit during development, causing the agent to loop endlessly and consume a large number of tokens. For the search-crawl-synthesize process, six to eight iterations are sufficient.
- Enforce structured output. Whenever downstream systems depend on specific fields (spreadsheets, Salesforce, Slack), constrain the return format with JSON Schema.
- Control token volume. Crawling large pages can return tens of thousands of characters; requesting clean Markdown or targeted JSON extraction significantly reduces token consumption and latency.
- Keep human confirmation for external actions. The agent in the course only "drafts" emails rather than sending them automatically; before validating dozens of runs, keep humans in the loop via Gmail drafts or Slack approvals.
- Handle errors gracefully. Enable retry mechanisms for scenarios such as temporary timeouts on target websites.
MCP and Agent Skills: Two Emerging Standards for Tool Integration
The course concludes by introducing two standards that are taking shape. MCP (Model Context Protocol) is like giving agents a universal "USB-C port"—enter the remote MCP server address and API key into any compatible client (Claude Desktop, Cursor, VS Code, or n8n's MCP tool node), and the agent can automatically discover and call capabilities such as search and crawling, without hand-writing HTTP endpoints and JSON request bodies. Agent Skills, by contrast, lean toward "judgment"—lightweight instruction files like skill.md teach the agent to decide like a senior engineer when to search, how to construct queries, how to cite sources, and how to avoid fabricating API parameters. Combined, the two make it faster to build research, monitoring, or data enrichment agents.
The gap between a chatbot and an agent that produces business results is not a smarter model, but clear instructions, reliable real-time tools, controlled memory, and a loop with boundaries. This architecture works in n8n and in Python; understanding it has more long-term value than memorizing the location of buttons on any particular platform.
MCP (Model Context Protocol) is an open-source protocol proposed by Anthropic, using a client-server architecture: MCP servers expose tools, resources, and prompt templates, while clients (Claude Desktop, Cursor, n8n, etc.) communicate with them via standardized JSON-RPC messages. Its value lies in transforming "tool integration" from hand-writing HTTP requests and authentication logic in each application to implementing once and discovering everywhere. Agent Skills are lighter, usually existing as markdown instruction files; they do not provide new capabilities but inject domain judgment rules into the model—such as when a search is worthwhile, how to construct high-quality queries, and how to indicate source credibility. The two are complementary: MCP addresses "what can be called," while Agent Skills address "how it should be used."
One-line Summary
An AI agent forms a goal-driven loop from four elements—model, instructions, memory, and tools—and can automatically complete sales lead research and email drafting.
Paragraph Summary
Based on a hands-on freeCodeCamp course, this article systematically breaks down the complete path of an AI agent from concept to a runnable workflow. It first distinguishes chatbots from agents: the former is single-turn Q&A, while the latter can autonomously plan, call tools, and iterate in a loop until the goal is complete. An agent's skeleton consists of four building blocks—model, instructions, memory, and tools—with about 70% of the effect coming from clear system prompts and clean tool definitions. The article identifies the two main causes of beginner agent failures—reliance on outdated training data and simple HTTP requests—and offers a dedicated web data API as the solution. It then builds a complete sales lead enrichment agent in two ways, an n8n visual workflow and equivalent Python code: triggered from Google Sheets, going through search, crawling, and structured output to writing back to the sheet. Finally, it provides five reliability recommendations for production deployment and introduces two emerging standards, MCP and Agent Skills.
Related articles

Say Goodbye to Hand-Written Code: Cursor AI Doubles Your Programming Efficiency
e-Bliss Technologies' short video reveals how Cursor AI compresses 5 hours of coding into 5 minutes—describe your logic in natural language to auto-generate frontend, backend, and bug fixes. Delivery speed tripled. Discover the real potential and limits of AI coding workflows.

AI Giants Say 'Slow Down' While Flooring the Accelerator — Who's Lying?
The Vergecast breaks down five AI hot topics: Anthropic's crypto flub, AI hacking, Altman and Amodei's slowdown calls, Google search AI-ification, Jensen Huang's testimony, and how AI products can replicate Google Maps-style data deals.

AI Proves the Riemann Hypothesis: Should We Believe It?
Can AI prove the Riemann Hypothesis? Computerphile explores formal mathematics, the Lean proof assistant, and AI collaboration: AI generates proofs, mechanical checkers independently verify them, and multiple checkers plus formal verification ensure reliability—shifting trust from AI to verifiable mathematics and software.