What an agent is in production
In this lesson you will
- Describe the six steps of an agent loop and why it needs bounds
- Name the eight building blocks and what you own in each
- Sketch a bounded loop with an allow list of tools and two handover exits
An agent is a system around a prompt
A chatbot answers one question and stops. An agent keeps going until a task is done. It plans, calls a tool, reads the result, checks it, and decides what to do next. That loop is what makes an agent useful, and it is also what makes it risky: every pass can touch a real system.
At NexOps, we start every agent project with one sentence: which task, for whom, and how do we measure that it went well? If you cannot answer that, you are not ready to pick a model. The model is one part of the system, and it is the part you can replace with the least work.
This course follows one agent from design to operation. In this first lesson we define the loop and the eight building blocks. We do not cover framework choices in depth, because the blocks stay the same whichever framework you pick.
The loop
Every production agent runs the same six steps.
- Goal. A task with a success measure, for example "classify the incoming request and draft a reply that a person can approve".
- Plan. The model breaks the task into steps. Keep plans short. A long plan is a long list of places to go wrong.
- Call a tool. The model asks the harness to run a tool. The harness, not the model, executes it, with the permissions of a scoped service account.
- Observe. The harness returns the result, together with its source.
- Check. Rules, guardrails and an evaluation set decide whether the step is acceptable.
- Answer or hand over. The agent finishes, or a person decides.
The important design rule is that the loop is bounded. Set a maximum number of steps, a maximum duration and a token budget. An agent without a bound will, sooner or later, loop on a tool error and spend your budget on it.
The eight building blocks
The same parts appear in every agent we build. Treat each one as something you configure, test and own.
| Block | What it does | What you own |
|---|---|---|
| Model | Reads context, chooses the next action | A choice per task, on your evaluation set |
| Instructions | System prompts and rules | Files in version control, reviewed like code |
| Tools | Actions the agent can take | A short list, each with its own identity |
| Memory and state | Session context and long-term facts | Retention and deletion rules |
| Retrieval | Passages from your documents | Sources returned with every passage |
| Guardrails | Checks on requests, calls and answers | Policies applied on every call |
| Evaluation and tracing | Measures quality, records every step | A test set from real cases |
| Human approval | A person confirms consequential actions | A rule for which actions need it |
Lessons 2 to 8 take these blocks one by one.
A minimal loop in code
The sketch below shows the shape of a bounded loop. It is schematic: it shows the control flow, not the API of any framework.
Illustration
# Schematic agent loop. The names are placeholders, not a real framework API.
MAX_STEPS = 8 # hard bound on passes through the loop
TOKEN_BUDGET = 40_000 # hard bound on tokens for one task
def run_agent(task, model, tools, checks):
state = {"task": task, "history": [], "tokens": 0}
for step in range(MAX_STEPS):
decision = model.decide(state) # plan or answer
if decision.kind == "answer":
return checks.final(decision.text, state) # last gate before the user
if decision.tool not in tools: # deny by default
state["history"].append(("error", "unknown tool"))
continue
result = tools[decision.tool].run(decision.args) # runs with a scoped identity
state["history"].append((decision.tool, result)) # result and its source
state["tokens"] += model.last_usage
if state["tokens"] > TOKEN_BUDGET:
return handover(state, reason="budget") # a person takes over
return handover(state, reason="step limit")Three details matter. The tool list is an allow list, so an unknown tool is an error and never an improvisation. Every result goes into the history together with its source. And both exits, budget and step limit, hand the task to a person instead of failing silently.
Where the agent loop connects to the platform
On Databricks, the pieces line up like this. Tools are reached through MCP servers, which can be Databricks-managed, custom or external, and Unity Catalog permissions govern the managed ones. Conversation state and long-term memory are stored in managed stores backed by Lakebase. MLflow Tracing records each step with its inputs, outputs, latency and token usage. Unity Gateway sits in front of the models and adds access control, budgets, limits and logging. The current documentation calls it Unity Gateway; many teams, and our site, still say Unity AI Gateway.
Do not treat this list as a shopping list. Start with the task and the measure, then add only the blocks the task needs. A reply drafter for an internal service desk needs fewer tools than an agent that updates your ERP.
Common mistakes
- Starting with the framework. Pick the task and its evaluation set first. Frameworks come and go; the loop stays.
- One big agent. Several small agents with one job each are easier to test than one agent with twenty tools.
- No bound. Always set step, time and token limits.
- No handover. Define who takes over, and how they see what the agent did.
Summary
An agent is a bounded loop around a model with scoped tools, memory, guardrails, evaluation and a person who can approve. The model is replaceable. The loop, the bounds and the evidence are what you keep.
In the next lesson we look at the block with the most risk: tools.
The idea in one picture
The loop an agent runs
- GoalA task with a success measure
- Plan
- Call a toolScoped identity
- ObserveResult and source
- CheckRules and evaluation
- Answer or hand over
Knowledge check
Answer each question. You see the reason behind every answer at once.
0 of 3 answered
Hands-on lab
Goal. Run and extend a bounded agent loop with a stub model.
Where to run it
Local Python Run this lab on your own machine with Python 3.10 or newer in a virtual environment.
Steps
- Copy the loop from the lesson into agent.py. Write a StubModel class whose decide() returns a tool call twice and then an answer.
- Add one tool, get_order_status, that returns a fixed dictionary for order SO-100234 and raises an error for any other id.
- Make the stub ask for an unknown tool once and check that the loop records an error and continues.
- Set MAX_STEPS to 2 and run again. Confirm that handover() is called with reason 'step limit'.
Expected result
The normal run ends with an answer. The unknown tool run records an error and still ends. The MAX_STEPS=2 run ends in a handover.
Go deeper
Official documentation and recommended courses from the providers.
- Databricks
- Free with an account
- Databricks Academy account
- Beginner
AI Agent Fundamentals
A free primer on agent concepts, useful before the MCP and agent courses.
Open course : AI Agent Fundamentals. Opens the provider site in a new tab
- DeepLearning.AI
- Cost not stated
- Intermediate
- 9 h 55 min
Agentic AI
A longer course on designing and building agent systems end to end.
Open course : Agentic AI. Opens the provider site in a new tab
- docs.databricks.com
Build agents on Databricks
Open documentation : Build agents on Databricks. Opens at the provider
Read at NexOps
Articles from our own projects on the same topic.
Sources
Last verified 2026-11-11
- Build agents on Databricks (Agent Bricks)
- MCP on Databricks
- Stateful agents on Databricks
- MLflow Tracing for GenAI
- Unity Gateway
We check every source against the official documentation. Products change, so confirm details there before you build.