Back to all articles
8 min read

Build an AI Agent Workshop: Safety-First Design

By Dorian Laurenceau

Updated

📅 Last reviewed: April 24, 2026. Updated with April 2026 findings and community feedback.

Build an AI Agent: Safety-First Workshop

An AI agent without safety guardrails is a liability. In this workshop, you will build a complete agent system, not just the reasoning loop, but the safety infrastructure that makes it production-worthy: tool whitelisting, human confirmation, cost controls, and output validation.

Workshop Goal

By the end, you will have built an agent that:

  1. →Takes a user question and plans a series of actions
  2. →Uses 3 tools: web search, calculator, and document lookup
  3. →Requires human confirmation for any action that modifies data
  4. →Stops after 7 iterations or $0.50 in API costs
  5. →Validates its final answer against observed evidence

Step 1: Define the Agent Architecture

Building the Agent Step by Step

From system prompt to safety layer

The System Prompt

The system prompt defines the agent's behavior, available tools, and safety rules. This is the most important engineering decision.
code
You are a research assistant. You help users find accurate information.

Available tools:
1. search_web(query) - Search the internet. Use for current events or facts.
2. calculator(expression) - Evaluate math expressions. Use for any calculation.
3. lookup_docs(query) - Search internal documents. Use for company-specific info.

Rules:
- Always explain your reasoning before acting
- Use the minimum number of steps
- Never guess when you can look up
- If uncertain after 5 steps, say so honestly

💡 Rules in the system prompt act as behavioral guardrails.

1/4

Step 2: Implement Safety Layers

Safety Layer Implementation

LayerWhat It PreventsHow to Implement
Tool WhitelistHallucinated tool callsValidate tool name against allowed list before execution
Parameter ValidationInjection attacks, malformed inputsSchema validation on all tool parameters
Iteration LimitInfinite loops, runaway costsCounter in the execution loop, max 5-10
Cost BudgetUnexpected API expensesTrack token usage per run, stop at threshold
Human ConfirmationUnauthorized destructive actionsFlag tools as requires_confirmation, pause for approval

← Scroll horizontally →

Quick Check

Why is human-in-the-loop important for AI agents?

Step 3: Testing Your Agent

Agent Testing Strategy

Verify behavior before deployment

Happy Path Testing

Test with straightforward questions that require 2-3 tool calls. Verify the agent uses the right tools in a reasonable order.
code
Test: 'What is the current population of Tokyo?'
Expected: search_web -> extract number -> answer
Actual: Verify tool selection and answer accuracy

💡 Start with simple cases to verify the basic loop works.

1/4

Common Agent Anti-Patterns

Click to expand
Click to expand

Test Your Understanding

Question 1 of 5.

AI Agent Workshop Check

0 / 5 answered

Q1.What is the most common source of agent failures in production?

5 questions remaining

What's Next

You have built an AI agent with proper safety guardrails. In the next module, you will explore AI image generation, understanding diffusion models and learning to prompt for visual content.


Continue to AI Image Generation and Diffusion Models to enter the world of visual AI.

Go deeper — free guide

Module 6 — AI Agents & ReAct

Create autonomous agents that reason and take actions.

D

Dorian Laurenceau

Full-Stack Developer & Learning Designer

Full-stack web developer and learning designer. I spent 4 years as a freelance full-stack developer and 4 years teaching React, JavaScript, HTML/CSS and WordPress to adult learners. Today I design learning paths in web development and AI, grounded in learning science. I founded learn-prompting.fr to make AI practical and accessible, and built the Bluff app to gamify political transparency.

Prompt EngineeringLLMsFull-Stack DevelopmentLearning DesignReact
Published: March 9, 2026Updated: April 24, 2026

One practical AI workflow in your inbox

Methods, resources and new exercises. Free, unsubscribe at any time.

FAQ

What will I learn in this AI Agents guide?+

Hands-on workshop to build an AI agent with the ReAct pattern. Includes tool integration, safety guardrails, human-in-the-loop confirmation, and practical deployment tips.