Connect with me via the floating button
Define the agent loop, boundaries, and the minimum contract for reliable behavior.
If you cannot define what your agent is, you cannot make it reliable. An agent is not a chatbot. It is a system that observes a context, decides on a next action, executes that action through tools, and updates state until a goal is met or a budget is exhausted.
A workflow is a fixed path. An agent is a controlled loop. The distinction matters because agents must survive ambiguity, retries, and partial progress. This lesson is about naming that loop and setting the boundaries that keep it safe.
At minimum, an agent needs five things:
When these are explicit, you can debug and test them. When they are implicit, you get chaos.
// Minimal agent loop, intentionally small
export type AgentState = {
goal: string;
context: string;
history: Array<{ role: "system" | "user" | "assistant"; content: string }>;
stepsTaken: number;
maxSteps: number;
};
export async function runAgent(state: AgentState) {
while (state.stepsTaken < state.maxSteps) {
const plan = await decideNextAction(state); // model policy
const result = await executeTool(plan.tool, plan.input); // tool call
state = updateState(state, plan, result); // state transition
if (isGoalMet(state, result)) break;
}
return state;
}
This loop is small on purpose. Every production agent is a variation of this.
Your agent must know what success looks like. Define it as a check that can be evaluated without calling the model again. For example: "Return a JSON object with a validated email and a completed onboarding checklist." The goal is not "help the user" or "be useful." Vague goals are untestable.
Agents are powerful because they can act, but that is also where they break. Every tool must have:
If a tool is fuzzy, the model will misuse it. If a tool is broad, a single mistake can cause damage.
An agent without a budget will loop forever. Budgets are not just costs. They are also step limits, API rate limits, and timeouts. You should define all three and enforce them at runtime.
Full access
Unlock all 10 lessons, templates, and resources for AI Agent Masterclass. $99 AUD.
const budget = {
maxSteps: 8,
maxTokens: 8000,
maxWallTimeMs: 30_000,
};
if (state.stepsTaken >= budget.maxSteps) {
throw new Error("BudgetExceeded: maxSteps");
}
A tool-using assistant might call a tool once and stop. An agent persists, checks its own progress, and recovers from failure. The difference is the feedback loop. That loop is where you should focus your design.
Here is a simple checklist you can apply to any system and decide if it is an agent:
If the answer is yes to all four, you have an agent. If not, you have a workflow or a tool-using assistant.
Pick a real use case and write the agent contract in one page:
This contract becomes the single source of truth for the rest of the course.
In Lesson 2, we will explore agent architectures and when to use each one, from reactive loops to deliberative planning systems.