Reasoning & Architectures
Hands-on lab with starter code you can copy + run, and guided steps to produce the artifact for this module.
Setup
- Open a fresh terminal in a new folder, e.g.
mkdir lab-2 && cd lab-2. - Create a Python 3.11 venv:
python -m venv .venv && source .venv/bin/activate. - Install the dependencies noted on each starter snippet (the small pip install … line above the code).
- Copy each starter into a file with the suggested name, then run it and capture the output.
Starter code
import re, json
from openai import OpenAI
client = OpenAI()
TOOLS = {"calc": lambda x: str(eval(x, {"__builtins__":{}}))}
SYS = """Use the format:
Thought: ...
Action: tool_name[input]
Observation: ...
... (repeat)
Final Answer: ..."""
def react(question, max_iter=6):
history = f"Question: {question}\n"
for _ in range(max_iter):
out = client.chat.completions.create(
model="gpt-5-mini",
messages=[{"role":"system","content":SYS},
{"role":"user","content":history}],
stop=["Observation:"],
).choices[0].message.content
history += out
m = re.search(r"Action: (\w+)\[(.+?)\]", out)
if not m: # Final Answer reached
return history
tool, arg = m.group(1), m.group(2)
obs = TOOLS[tool](arg) if tool in TOOLS else f"unknown tool {tool}"
history += f"\nObservation: {obs}\n"
return history
print(react("What is 17 * 23 + 4?"))python 02_01_lab.pyGuided steps
Work through each step in order. Stop when your output matches the expected artifact — then push your work to your lab folder.
- 1ReAct calculator
Do — Implement the ReAct loop with a calc tool. Test on 'What is 17*23+4?' and 'sqrt(144)+2^8'.
Expected artifact — Transcript showing Thought / Action / Observation steps and Final Answer: 395 and 268.
Run free: - 2Plan-and-execute variant
Do — Replace ReAct with a Plan-then-Execute architecture (LLM emits a 3-step plan, executor runs each).
Expected artifact — Same 2 questions answered correctly; transcript shows the explicit plan before any action.
Run free: - 3Architecture comparison
Do — Run both architectures on 20 mixed math/reasoning prompts. Report accuracy and avg steps.
Expected artifact — arch.md with a 2×2 table (acc, steps) and a 3-sentence recommendation.
Run free:
Authoritative sources
Independent primary sources used to check and corroborate the guidance on this page.
- NIST National Initiative for Cybersecurity Education (NICE)
US national framework for cybersecurity work roles and competencies.
- Financial Action Task Force (FATF)
Global AML/CFT standards referenced by financial-crime curricula.
- FBI Internet Crime Complaint Center — Annual Reports
Primary loss and typology data used in fraud-investigation training.
- US Federal Trade Commission — Consumer Sentinel Data Book
Official complaint statistics for teaching fraud trend analysis.
