Duck
Tutorials5 min read

Agentic AI Examples: Build Your Own Autonomous Workflow

Samet Turan— Editor··5 min read

Learn how to create agentic AI workflows with real prompts, tools, and debugging tips — then grab a ready-made blueprint to ship faster.

Agentic AI Examples: Build Your Own Autonomous Workflow

You keep copying prompts into chat boxes and hoping the AI does the next step, but the process stalls when you need chained actions, memory, or external tool calls. After reading this, you’ll know how to string together LLM calls, API hooks, and simple state to create a working agentic loop, and you’ll have a concrete blueprint to skip the build if you prefer.

Why does my agent stop after the first step?

Most people treat an LLM like a fancy search bar. They send a prompt, get a reply, and call it done. An agentic workflow needs a loop: the output of one step becomes the input for the next, and the system must decide when to stop. If you don’t persist state between calls, the model has no memory of what it already did, so it repeats or halts.

To fix that, you need a tiny store — could be a JSON file, a database row, or a key‑value cache — that holds the current step, gathered data, and any flags. Each loop iteration reads that store, asks the model what to do next, executes the chosen action, writes the result back, and repeats.

Here’s a minimal pseudo‑loop in JavaScript‑style pseudocode:

  1. Load state from storage.
  2. If state.done is true, break.
  3. Build a prompt that includes the state and the goal.
  4. Call the LLM and parse its JSON response for the next action.
  5. Execute the action (API call, DB write, email send).
  6. Update state with the result and set done if the goal is met.
  7. Save state back to storage.
  8. Go to step 1.

That’s the skeleton. The real work is in shaping the prompt and handling errors.

What most guides get wrong about agentic AI

Many tutorials show a single prompt that asks the model to “plan and execute” everything at once. They rely on the model’s internal reasoning to produce a multi‑step plan, then trust it to call APIs correctly. In practice, the model often hallucinates parameters, forgets required headers, or returns malformed JSON. The guide then blames “prompt engineering” instead of admitting the approach is fragile.

⚡
Recommended Reading

Prompt Engineering for Profit

50 Tested Templates

50 tested prompt templates for content, copywriting, and automation. Copy, paste, earn.


Get the Templates → $17

★★★★☆ (54)

What works better is to split the loop into two distinct phases: planning and execution. The planner prompt only asks for the next atomic action in a strict schema. The execution phase is pure code — no model involvement — so you can validate inputs, handle auth, and retry failures. This separation cuts hallucinations dramatically and makes debugging straightforward.

Real example: a lead‑enrichment agent that scrapes, scores, and emails

Let’s walk through a concrete agent I run for a freelance outreach business. The goal: given a list of domain names, find the company’s LinkedIn page, extract the head of marketing, compute a simple fit score based on company size and tech stack, then send a personalized intro email via SendGrid.

First mention of tools: OpenAI GPT-4o for reasoning, Apify for scraping LinkedIn, Supabase for state storage, and SendGrid for email.

Here’s the numbered step‑list that forms the core loop:

  1. Load the next domain from a queue table in Supabase.
  2. Ask GPT-4o to produce a JSON plan: {“action”: “scrape_linkedin”, “domain”: “example.com”}. The prompt includes the schema and a reminder to return only valid JSON.
  3. If the action is scrape_linkedin, call the Apify LinkedIn scraper API with the domain, receive a JSON payload containing the profile URL and marketing lead name.
  4. Update the Supabase row with the scraped data and set the next action to “score_lead”.
  5. When the action is score_lead, call a small Python function that reads company size from Clearbit (via their free tier) and checks BuiltWith for tech stack, then computes a score 0‑100.
  6. Store the score, decide if it exceeds a threshold (I use 70), and if so set the next action to “send_email”.
  7. For send_email, render a Handlebars template with the lead’s name and score, call SendGrid’s v3 Mail Send endpoint, then mark the domain as done.
  8. Loop back to step 1 until the queue is empty.

Each step is isolated, so if the Apify call fails with a 429, the loop simply writes an error flag and moves on to the next domain after a short back‑off. No need to re‑prompt the model.

I love how the Supabase row acts as a living scratchpad — you can inspect it mid‑run to see exactly where an agent got stuck. That visibility saved me hours when the LinkedIn scraper returned a malformed URL because of a missing protocol.

My gripe? The free tier of Apify only gives you 1000 scraper minutes per month, which runs out fast if you’re testing loops. I ended up paying $49/mo for the hobby plan just to keep the agent running during development. It feels steep for a tool that’s essentially a wrapper around HTTP requests.

On the price front, SendGrid’s free tier allows 100 emails per day — enough for solo work — and I think $0 is a fair price for that volume. If you need more, their Essentials plan at $19.95/mo is reasonable.

— and good luck finding docs for this — the Apify API reference is scattered across multiple pages, and the authentication method changed quietly last quarter, causing a few failed runs before I noticed the 401 responses.

We cover this in more depth elsewhere — deeper coverage of AI agent platforms.

If you’d rather skip the build and deploy a working version in an afternoon, we’ve packaged this workflow as a blueprint at deepusecase.com/vault.

— The Colophon

One AI tool. Tested. Reviewed.
In your inbox every Sunday.

~3 minute read. Real outcomes from operators, not marketers.

Free. One email per Sunday. Unsubscribe in one click.