Building AI Agents & Automations
You've built an insight report automation and a Contentful translation agent. This module formalizes the mental model - how to think about agents, when to use n8n vs code vs APIs, and how to design reliable multi-step workflows.
- The 4-step agent loop and how your existing automations fit it
- When to use n8n vs direct API vs agent frameworks
- Why prompt reliability matters more in automation than one-off use
- Spec a complete automation from scratch: trigger, AI step, output, destination, error handling
- Audit an existing automation for failure modes
- Treat your prompts like production code
Step 1 of 5 · Read the lesson
Building AI Agents & Automations lesson
The 4-step agent pattern
- Receive a goal
- Use tools (APIs, files, search)
- Reason about what's next
- Repeat until done or stuck
Decision framework
n8n - linear logic, existing integrations, non-engineers can edit.
Direct API - custom logic, performance-critical, tight integration with your code.
Agent framework (LangChain, CrewAI) - multi-step reasoning, dynamic tool selection.
Reliability
Most AI automations work 80% of the time and fail silently. Add: input validation, output schema checks, retry with backoff, human-in-the-loop for high-stakes paths, observability.
Prompts as code
Version them. Test edge cases. Document the expected output contract. A regression suite for prompts is not overkill - it's table stakes once a flow runs in prod.
Prompt templates as code (in practice)
In automations, treat your prompts like code. Version them. Test edge cases. Document the expected input format and output schema. A prompt that works 90% of the time is a function with a 10% bug rate - which is fine in one-off use and unacceptable in automation.
Specific practices:
- Save your automation prompts in a version-controlled doc (Notion, GitHub, anywhere with history)
- Write test cases: what happens when the input is empty? When it's in a language you didn't expect? When it's 10x longer than normal?
- Specify the output format as a schema, not just a description: "Return a JSON array of objects with keys:
theme(string),count(integer),confidence(high|medium|low)" - When a prompt starts producing worse output over time, treat it like a bug: investigate, iterate, document the fix
Prompts for Building AI Agents & Automations
Agent design prompt
Spec an automation for: [recurring task]. Return: - Trigger (schedule / webhook / manual) - Inputs (sources, format) - AI step (model, prompt sketch) - Output format (JSON schema if possible) - Destination (where output lands) - Error handling (what could fail, fallback) - Human-in-the-loop touchpoints
n8n workflow designer
Design an n8n workflow for: [task]. List nodes in order. For each: node type | function | key config | error path. Highlight any node where I should add a "If error → notify Slack" branch.
Automation audit
Here is an automation I built: [paste flow description]. Audit it. Find: 1. Single points of failure 2. Missing error handling 3. Prompt reliability issues (vague outputs, no schema) 4. Scalability concerns (rate limits, cost at 10x volume) Return prioritized fixes.
Exercise for Building AI Agents & Automations
Spec a real recurring task as an automation using the agent design prompt.
Then audit your existing insight report automation for edge cases and ship a fix for the highest-risk one.
Resources for Building AI Agents & Automations
Questions about this module
What is an AI agent?
An agent is an AI system that can take actions through tools, not just produce text. It plans, calls a tool, reads the result and continues until the task is done.
When should I not build an agent?
When the task is rare, high risk or fully deterministic. A script or a checklist beats an agent whenever the steps never change.
Related modules
Terms used here
All prompts from this module are also on the prompt library.