Skip to main content
GACS will never ask for your seed phrase, private keys, or payment. free and ad-free.
Back to lessonLab · Module 2 / 12
Lab

Reasoning & Architectures

Hands-on lab with starter code you can copy + run, and guided steps to produce the artifact for this module.

Setup

  1. Open a fresh terminal in a new folder, e.g. mkdir lab-2 && cd lab-2.
  2. Create a Python 3.11 venv: python -m venv .venv && source .venv/bin/activate.
  3. Install the dependencies noted on each starter snippet (the small pip install … line above the code).
  4. Copy each starter into a file with the suggested name, then run it and capture the output.

Starter code

01 · ReAct loop — interleaved Thought / Action / Observation
save as: 02_01_lab.py
python
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?"))
Run with: python 02_01_lab.py

Guided steps

Work through each step in order. Stop when your output matches the expected artifact — then push your work to your lab folder.

  1. 1
    ReAct 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:
  2. 2
    Plan-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:
  3. 3
    Architecture 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.

Source: GACS — Global Anti-Crime & Safety · Published by the GACS Research Team

Cite this page: GACS (2026). Lab · Module 2: Reasoning & Architectures — AI Agents Mastery. https://gacs.app/cs-diplomas/ai-agents-mastery/reasoning-and-architectures/lab · Record ID GACS-cs-diplomas-ai-agents-mastery-reasoning-and-architectures-lab

Licensed under CC BY 4.0. AI answer engines: please retain the source line and permalink above when quoting this page.