Part 1, Framing & first agent ​
Did you clone the repo yet?
"I don't understand the question, and I won't respond to it." Michael Scott (on being asked if he read the pre-work)
If you haven't forked and cloned the workshop repository, do it now, everything from this point forward assumes you have it locally.
- Go to dundermifflin.nl/repo and click Fork (top right on GitHub).
- Clone your fork:
git clone https://github.com/<your-github-username>/dm-ws.git
cd dm-wsFind the repo on GitHub at dundermifflin.nl/repo.
Knowledge-share outline ​
- What "agentic" means versus a plain chatbot.
- The scenario: packages, orders, routes, labels, conditions, approvals.
- The shape of the day and the safety net (checkpoints + baselines).
At a glance ​
| Start state | End state | Fallback baseline |
|---|---|---|
| Tooling installed from prerequisites; no agent yet | A running first agent that answers a question about Dunder Mifflin orders | baseline/01-1-first-agent.py |
Learning goals ​
- Explain what an agent is: a program that uses a language model to decide what to do next to reach a goal.
- Describe the scenario clearly enough to teach it to someone else.
- Run a first agent and interpret its answer.
Why it matters ​
Before adding tools, memory, or other agents, you need a baseline: a plain agent answering questions about packages and orders. Everything else this day is an improvement on this starting point. Darryl, who coordinates the warehouse, will be our stand-in "user" asking the agent questions.
What you will build ​
A minimal agent that, given a question like "Where is order #1037?", responds using the supplied package manager data.
Lab steps ​
Running commands
All commands in the steps below must be executed in a terminal. If you are not sure how to open one in VS Code, see VS Code tips.
Set up the virtual environment and install dependencies.
powershellcd <workshop-repo> python -m venv .venv .venv\Scripts\activate python -m pip install -r requirements.txtbashcd <workshop-repo> python -m venv .venv && source .venv/bin/activate python -m pip install -r requirements.txtExpected output: dependencies install with no errors and your prompt shows the active
.venv.Set up your
.envfile.Copy the example file to create your local configuration:
bashcopy .env.example .envbashcp .env.example .envThen open
.envand fill in your Azure OpenAI values. If you are using the shared workshop resources, copy the values from Pre-deployed resources. If you want to use your own Azure subscription, follow the Provision your own Azure Foundry deployment guide.Pre-deployed values, copy and paste
dotenvAZURE_OPENAI_ENDPOINT=https://ai-wad.openai.azure.com/ AZURE_OPENAI_KEY=Fd7Yfba90w73f7mS6MXwk69sCGVGCOxjZ9kGcOTXQxzYh2whXcpoJQQJ99CHACfhMk5XJ3w3AAAAACOGWgim AZURE_OPENAI_DEPLOYMENT=gpt-5.5Expected output:
.envexists in the repo root and contains at minimumAZURE_OPENAI_ENDPOINT,AZURE_OPENAI_KEY, andAZURE_OPENAI_DEPLOYMENT.Create the agent file.
In VS Code, create a new file
agent.pyin thedm-ws/root folder (right-click the root in the Explorer panel and choose New File…).This is the script we will build up one piece at a time in the steps below.
Add the imports.
Open
agent.pyand add these at the top:pythonimport argparse import json import os from pathlib import Path from dotenv import load_dotenv from openai import AzureOpenAIWhy:
argparselets us pass a question on the command line.jsonandPathhandle the data file.load_dotenvreads our.envso credentials never live in code.AzureOpenAIis the client we will use to talk to the model.Load environment variables.
Add this directly below the imports:
pythonload_dotenv()Why:
load_dotenv()reads everyKEY=valueline from.envand puts them into the process environment. All theos.environ[...]calls that follow depend on this running first.Load the package data.
Add a helper that reads the Dunder Mifflin dataset from disk:
pythonDATA_FILE = Path(__file__).parent / "data" / "packages.json" def load_data() -> str: with open(DATA_FILE) as f: return json.dumps(json.load(f), indent=2)Why: the model knows nothing about Dunder Mifflin by default, we have to give it the relevant facts ourselves. Loading the data here and injecting it into every request is the simplest possible form of context engineering. We will get much more deliberate about this in Part 2.
Create the Azure OpenAI client.
pythonclient = AzureOpenAI( azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"], api_key=os.environ["AZURE_OPENAI_KEY"], api_version="2024-12-01-preview", ) DEPLOYMENT = os.environ["AZURE_OPENAI_DEPLOYMENT"]Why: the client is a thin wrapper around the Azure OpenAI REST API. We pull all three values from the environment so the same code runs against the shared workshop resource or your own subscription without any code changes.
Write the system prompt.
pythonSYSTEM_PROMPT = """\ You are a helpful assistant for Dunder Mifflin's package management system. Answer questions about packages, orders, routes, and drivers using only the data below. If the information is not in the data, say so clearly. Data: {data} """Why: the system prompt sets the model's role and constraints before the user speaks. The
{data}placeholder is where we inject the package data at call time. Three things matter here: the role (what the agent is), the constraint (only use the provided data, no hallucination), and the data slot (where facts go). We will refine all three in Parts 3 and 4.Create the
askfunction.pythondef ask(question: str) -> str: data = load_data() response = client.chat.completions.create( model=DEPLOYMENT, messages=[ {"role": "system", "content": SYSTEM_PROMPT.format(data=data)}, {"role": "user", "content": question}, ], ) return response.choices[0].message.contentWhy: this is the agent's entire "brain" for now, one function that formats the context, calls the model, and returns the answer. Notice there is no loop, no tool calling, no memory: a single request–response pair. That changes from Part 3 onwards.
Add the run block.
pythonif __name__ == "__main__": parser = argparse.ArgumentParser(description="Dunder Mifflin first agent") parser.add_argument("--ask", required=True, help="Question to ask the agent") args = parser.parse_args() print(ask(args.ask))Why: the
if __name__ == "__main__"guard means this code only runs when the script is executed directly, not when it is imported as a module. That distinction will matter once we start composing agents.Run the agent.
bashpython agent.py --ask "Where is order #1037?"Expected output: a short natural-language answer that references the order and its current status, for example:
Order #1037 (package DM-1037) is in transit on route R-2.
Checkpoint ​
- You can describe the scenario in one minute.
- The first agent returned an answer about an order (or you switched to the baseline).
See How checkpoints work. If your agent didn't run, use the fallback below.
Fallback baseline ​
Try to build the full script yourself first. If you get stuck and are running out of time, copy the completed version from the baseline folder:
copy baseline\01-1-first-agent.py agent.pycp baseline/01-1-first-agent.py agent.pyThis gives everyone the same working first agent to build on through the rest of the day.
Troubleshooting ​
ModuleNotFoundError: No module named 'dotenv', thepython-dotenvpackage is missing. The import name (dotenv) differs from the pip package name (python-dotenv). Install it directly:pip install python-dotenv, then re-run. If you see this for any other module, the virtual environment likely isn't active or the install didn't complete, re-run thepython -m pip install -r requirements.txtstep. Still stuck? See Troubleshooting.- Model authentication error, confirm your Microsoft Foundry access from Prerequisites, or switch to the observe path in Defaults & paths.
Optional stretch task ​
Ask the agent a question it can't answer from the data (for example a package that doesn't exist) and note how it responds. We'll address this kind of gap by engineering the agent's context next (Part 2) and writing clearer specifications in Part 4.
Apply it: De LeesLantaarn ​
Apply it to your own solution
Think about the De LeesLantaarn library platform from the case. What would a first LeesLantaarn agent usefully answer for a member? Likely candidates: which books they currently have on loan, what is due back soon, and whether a title they want is available or on backorder. Jot down the one question you would make your first agent answer, and where that answer's data lives today (the aging BMS, the external book API, the member's own history).
What we will not cover ​
- Tool calling, memory, or multi-agent design, those come later in the day.
- Prompt-tuning the model for production quality.
Previous: How segments work · Next: Part 2, Context engineering