AI Agent Building Blocks: Role, Context, Tools and Guardrails

An agent is not one mysterious thing. It is a set of simple parts working together. If you understand those parts, you can design an agent, debug it and explain it in an interview. This lesson walks through the AI agent building blocks using a QA example.

📖 What You’ll Learn

  • The main parts of an AI agent
  • The difference between skills and tools
  • The difference between constraints and guardrails
  • How to write an agent definition

💡 The AI Agent Building Blocks

Explain Like I’m 5: A New Team Member

Imagine: On a new tester’s first day, you explain their job, the project, today’s task, what tools they may use and what they must never do.

What it really means: An agent needs the same kind of clear briefing.

In testing: Each block answers one question about the agent’s job.

BlockQuestion it answersQA example
RoleWho is the agent?Senior QA automation engineer
ContextWhat facts does it need?Shop website, login flow, test URL
TaskWhat must it do now?Create login test scenarios
GoalWhat does success look like?Valid scenarios with clear evidence
SkillsWhat does it know how to do?Test design and Playwright
ToolsWhat actions can it take?Open page, read file, run tests
ConstraintsWhat are the limits?No production writes, no fixed sleeps
GuardrailsWhat checks enforce safety?Human approval before running code
MemoryWhat should it remember?Approved locator conventions
WorkflowIn what order does it work?Explore, plan, generate, review, run
Output schemaWhat shape must the result have?JSON scenarios and a file path

🔍 Skills vs Tools

Explain Like I’m 5: Knowing vs Holding

Imagine: You know how to cut paper. That is a skill. The scissors in your hand are a tool.

What it really means: A skill is what an agent knows, and a tool is what it can call.

In testing: Test design is a skill, and a test runner is a tool.

This difference is important. Knowing how to write Playwright tests does not allow an agent to run them. It can do that only if you give it a test-runner tool.


🧩 Constraints vs Guardrails

Explain Like I’m 5: Rules and Gates

Imagine: “Do not go near the road” is a rule. A locked gate stops you even if you forget the rule.

What it really means: A constraint is an instruction, and a guardrail enforces it.

In testing: Prompts can be ignored, so real limits must be in code.

Constraint in the promptGuardrail in code
“Only test the approved site”Reject any URL outside an allowlist
“Do not delete files”Provide no delete tool
“Stop after a few steps”Exit the loop at a step limit
“Ask before running code”Wait for a human approval signal

Do not rely on the prompt alone

A model can misunderstand or be manipulated. Anything that protects data, money or systems must be enforced by code and permissions.


🛠️ Memory: Less Is More

Memory is useful, but not everything belongs there. Keep stable project facts, such as your locator rules. Avoid storing secrets, personal data or outdated assumptions. You saw why context limits matter in How LLMs Work.


📌 Write the Definition

A plain object is a useful way to describe an agent. This example defines the Explorer agent that you will build in Level 8.

type AgentDefinition = {
  role: string;
  goal: string;
  tools: string[];
  constraints: string[];
  maxSteps: number;
};

const explorer: AgentDefinition = {
  role: 'Explorer',
  goal: 'Report the visible elements on an approved page',
  tools: ['openPage', 'readAccessibilitySnapshot'],
  constraints: ['Do not invent selectors', 'Do not submit forms'],
  maxSteps: 10,
};

console.log(`${explorer.role}: ${explorer.tools.join(', ')}`);
console.log(`Max steps: ${explorer.maxSteps}`);
Explorer: openPage, readAccessibilitySnapshot
Max steps: 10

Notice that this agent has only two tools. Fewer tools mean fewer ways to go wrong.


🌍 Real-Life Example: A Missing Block

A team’s agent keeps writing tests with brittle CSS selectors. Its role and task are fine, but nobody supplied the team’s locator conventions as context. Adding that one block fixes most of the problem. Thinking in blocks helps you find what is missing.


🧪 Try It Yourself

  1. Pick one small QA job, such as summarising failures.
  2. Fill in all eleven blocks for it.
  3. Mark which limits are prompts and which are in code.
  4. Run the prompt below.
  5. Remove any tool that the agent does not truly need.

📋 Ready-to-Copy Prompt

You are a senior AI test architect. Help me design a small QA agent.

Job: [describe one narrow job]
Environment: [approved test environment]
Actions it must never take: [list]

Fill in: Role, Context, Task, Goal, Skills, Tools, Constraints, Guardrails,
Memory, Workflow and Output Schema.

Rules:
- Suggest the smallest possible set of tools.
- For each constraint, say how code should enforce it.
- Mark anything that needs human approval.
- List information you need instead of guessing.

⚠️ Common Mistakes

  • Treating a role as the whole agent design
  • Confusing what an agent knows with what it can do
  • Relying on prompts for safety
  • Giving an agent more tools than it needs
  • Storing secrets or old facts in memory

🎯 Key Takeaways

  • An agent is made of clear, understandable parts.
  • Skills are knowledge, and tools are actions.
  • Guardrails enforce limits in code.
  • Small tool sets are safer and easier to test.

🎤 Interview Questions

1. What are the main components of an AI agent?

Model answer: They include a role, context, task, goal, skills, tools, constraints, guardrails, memory, a workflow and an output schema. Together they define what the agent knows, does and may not do.

2. What is the difference between a skill and a tool?

Model answer: A skill is knowledge or expertise, such as test design. A tool is an external capability it can call, such as a test runner. An agent can only act through the tools provided.

3. What is the difference between a constraint and a guardrail?

Model answer: A constraint is a rule given to the agent, often in the prompt. A guardrail is an enforced control, such as a URL allowlist or an approval step, that still works if the model ignores the rule.

4. Why should agents have few tools?

Model answer: Fewer tools reduce wrong choices, narrow the security risk and make behaviour easier to test. I give each agent only what its current job requires.

5. What should and should not go into agent memory?

Model answer: Stable, approved facts such as conventions can go in. Secrets, personal data and unverified guesses should stay out, and stored information should be reviewed so it does not become outdated.


📝 Assignment

Write a complete building-block design for a Failure Analyst agent. Include at least three guardrails enforced in code. Save it for the project in Level 8.


❓ FAQ

Does every agent need memory?

No. Many small agents work well using only the context from the current run.

Can one agent have several roles?

It can, but separate focused agents are often easier to test. Start with one clear role.


🚀 Next Steps

Well done on finishing this lesson. Complete the assignment, then continue with The AI Agent Loop Explained: Think, Act, Observe and Stop.