Prompt Engineering for Agents
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-4 && cd lab-4. - 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
SYSTEM = """You are GACS-Agent v1.
ROLE: financial-fraud investigator.
TOOLS: search_web(q), check_blacklist(name), report(json).
RULES:
1. Never fabricate evidence.
2. Always cite a tool observation before claiming a fact.
3. If unsure, ask the user one clarifying question, then continue.
OUTPUT: JSON {thought, action, action_input}."""
def call(user_msg):
return client.chat.completions.create(
model="gpt-5-mini",
response_format={"type":"json_object"},
messages=[{"role":"system","content":SYSTEM},
{"role":"user","content":user_msg}],
).choices[0].message.contentpython 04_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.
- 1Structured system prompt
Do — Write a system prompt that enforces JSON output with fields {thought, action, action_input}. Validate 20 outputs.
Expected artifact — 20/20 outputs parse as valid JSON with all 3 required fields.
Run free: - 2Persona ablation
Do — Run the same 10 tasks with and without a domain-expert persona. Compare answer quality.
Expected artifact — persona.md table with subjective 1–5 scores and an aggregate delta.
Run free: - 3Few-shot vs zero-shot
Do — Build a tool-calling agent with 0, 2, and 5 in-context examples. Test on 30 prompts.
Expected artifact — Tool-call accuracy curve; 5-shot should outperform 0-shot by ≥10 points.
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.
