Prompting AI Agents
An AI agent does not just answer once, it works toward a goal over multiple steps. The simple formula is LLM + tools + a loop : it plans, acts, observes the result, and iterates until done.
Learn Prompting AI Agents in our free Prompt Engineering course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a…
Part of the free Prompt Engineering course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
This lesson covers multi-step planning, the ReAct (reason + act) loop, reflection and self-correction, and the guardrails and stopping conditions that keep agents safe and on track.
What You'll Learn in This Lesson
1 The reason + act loop
Give the agent a goal and tools. In each turn it reasons, acts, and observes, then loops back. This is the ReAct pattern:
2 Reflection and self-correction
Strong agents pause to review their own work. Asking the agent to critique itself catches mistakes before they pile up:
This reflection step is often the difference between an agent that drifts and one that reliably reaches the goal.
3 Guardrails and stopping conditions
Loops can run forever. Always set limits so the agent stops cleanly and stays within safe bounds:
Common Mistakes (and the fix)
- No stopping condition. — Set a step or time limit and a clear done state.
- Skipping reflection. — Have the agent review and correct its own work.
- Vague goal. — Give a concrete, checkable goal the agent can aim for.
- Building an agent for a one-shot task. — Use a single prompt when no loop is needed.
Frequently Asked Questions
⏱ Test Yourself — Timed Quiz
10 quick questions, 12 seconds each. Instant feedback — beat the clock!
🎉 Lesson Complete
- ✅ An agent is an LLM + tools + a loop pursuing a goal
- ✅ The ReAct loop interleaves reasoning and acting
- ✅ Reflection lets the agent self-correct as it goes
- ✅ Guardrails and stopping conditions keep it safe and bounded
- ✅ Use an agent for multi-step goals, a single prompt for one-shot tasks
Practice quiz
What is an AI 'agent' in this context?
- An LLM combined with tools and a loop that pursues a goal over multiple steps
- A single one-shot answer
- A type of database
- A human worker
Answer: An LLM combined with tools and a loop that pursues a goal over multiple steps. An agent is an LLM plus tools plus a loop that works toward a goal step by step.
The ReAct pattern stands for…
- Reading and acting on emails
- Reacting to errors only
- Reason plus Act: the agent thinks, then takes an action, and repeats
- A JavaScript library
Answer: Reason plus Act: the agent thinks, then takes an action, and repeats. ReAct interleaves reasoning and acting in a loop.
Why do agents work in a loop?
- To avoid using tools
- So they can plan, act, observe the result, and adjust until the goal is done
- To waste time
- Because loops are required by law
Answer: So they can plan, act, observe the result, and adjust until the goal is done. The loop lets the agent take multiple steps and react to each result.
A simple formula for an agent is…
- A spreadsheet
- Just a prompt
- A printer
- LLM + tools + a loop
Answer: LLM + tools + a loop. An agent is an LLM with tools driven by an iterating loop toward a goal.
What is 'reflection' or self-correction in an agent?
- The agent reviewing its own progress and fixing mistakes before continuing
- Restarting the computer
- Looking in a mirror
- Deleting the goal
Answer: The agent reviewing its own progress and fixing mistakes before continuing. Reflection means the agent critiques its own work and corrects course.
Why are stopping conditions important for agents?
- To hide the goal
- Without them an agent can loop forever or run up cost
- They are not
- To make answers random
Answer: Without them an agent can loop forever or run up cost. Stopping conditions prevent endless loops and runaway cost.
Guardrails for an agent typically…
- Make it faster
- Remove its tools entirely
- Translate its output
- Limit which actions it may take and when to stop or ask for help
Answer: Limit which actions it may take and when to stop or ask for help. Guardrails bound the agent's actions and define safe limits.
Multi-step planning means the agent…
- Picks a random tool
- Answers in one shot only
- Breaks a goal into steps and works through them in order
- Ignores the goal
Answer: Breaks a goal into steps and works through them in order. The agent decomposes the goal into a sequence of steps.
A good task for an agent rather than a single prompt is…
- Saying hello
- A multi-step goal like 'research a topic, gather sources, and write a summary'
- Echoing a word
- Counting to three
Answer: A multi-step goal like 'research a topic, gather sources, and write a summary'. Open-ended, multi-step goals benefit from the plan-act-observe loop.
When an agent observes a tool result, it should…
- Use it to decide the next step or to finish the goal
- Repeat the same step forever
- Ignore it
- Delete it
Answer: Use it to decide the next step or to finish the goal. The observation feeds the next reasoning step toward the goal.
Continue this course
- Previous: Retrieval-Augmented Generation (RAG)
- Next: Multimodal Prompting