Before you click Practice — Module 1 notebook
The lab is three cells: install → key + helper → one ChatGroq call. You are proving you can talk to an LLM through LangChain. That is the brain of an agent — not yet tools, memory, or a loop.
Install langgraph + groq→Paste API key→ChatGroq.invoke one sentence
In Kodin: finish this page → Practice → run cells top to bottom. Stay in the app; paste the Groq key in the notebook prompt.
Practice task 1
Install packages into this notebook’s Python
Run the first code cell. It uses sys.executable -m pip so packages go into Kodin’s Jupyter kernel, not a random Windows pip.
# Install into THIS notebook kernel (not Windows pip).
import sys
import subprocess
print("Installing into:", sys.executable)
subprocess.check_call([
sys.executable, "-m", "pip", "install", "-qU",
"langgraph", "langchain-groq", "langchain-core",
])
print("Done. Run the next cells.")
Expected: Prints the kernel path, then “Done.”
Why this cell: A plain !pip install on Windows often installs into a different Python, then the next cell fails with ModuleNotFoundError: langgraph. If import still fails: Kernel → Restart Kernel, then Run All.
Practice task 2
Set the Groq key and the helper that reads GPT-OSS replies
Paste your Groq API key when the cell asks. The model is always openai/gpt-oss-20b. groq_text() turns whatever the model returns into a printable string.
import os
MODEL = "openai/gpt-oss-20b"
def groq_text(msg) -> str:
"""GPT-OSS may return content as a string or a list of parts."""
c = getattr(msg, "content", msg)
if isinstance(c, list):
parts = []
for p in c:
if isinstance(p, str):
parts.append(p)
elif isinstance(p, dict):
parts.append(str(p.get("text") or p.get("content") or ""))
c = "\n".join(x for x in parts if x)
if not c:
extra = getattr(msg, "additional_kwargs", {}) or {}
c = extra.get("reasoning_content") or extra.get("reasoning") or ""
return str(c or "").strip()
if not os.getenv("GROQ_API_KEY"):
os.environ["GROQ_API_KEY"] = input("Enter GROQ_API_KEY: ").strip()
if not os.getenv("GROQ_API_KEY"):
raise SystemExit("Set GROQ_API_KEY before running the next cells.")
print("API key ready. Model:", MODEL)
Expected: “API key ready. Model: openai/gpt-oss-20b”
Why this cell: GPT-OSS 20B does not always put a plain string in message.content. It may send a list of parts, or put thinking in reasoning_content. Printing the raw object looks messy; this helper is what later cells use.
Practice task 3
First LLM call with ChatGroq
This is a chatbot-style call: one prompt in, one answer out. There is no tool, no memory, no loop. Compare that with the Agent vs Chatbot section above.
from langchain_groq import ChatGroq
llm = ChatGroq(model=MODEL, temperature=0)
response = llm.invoke("Explain what an AI Agent is in exactly one sentence.")
print(groq_text(response) or response)
llm = ChatGroq(...) — create the client (does not call the API yet).
llm.invoke("...") — send one message and wait.
groq_text(response) — unwrap GPT-OSS content so you see the sentence.
Expected: One sentence defining an AI agent, printed in the notebook.
Why this cell: ChatGroq is the LangChain wrapper around Groq. model=MODEL uses GPT-OSS 20B. temperature=0 keeps the answer steady for class demos. invoke is a single shot — the model cannot search or remember the next cell unless you send history yourself.
Checklist in the notebook: packages installed, key set, invoke ran with no error. Then you are ready for Module 2, where the same LLM is asked to think in ReAct format.