The Agent Stack

Module 3: Flask or FastAPI, Groq, open-source models — and how they become one working agent

Picture this: swap any layer

The agent is three Lego bricks. This course uses the left column. The right column is the same job with a different brand.

Web app

Flaskthis course
or
FastAPIsame /ask JSON

API platform

Groqgsk_ key
or
Together / OpenRouter / Ollamaother hosts

Open model

GPT-OSS 20Bthis course
or
Llama / Mistral / Qwenother weights

You → Flask or FastAPI → LangGraph → Groq (or alt) → model. Tools hang off the agent, not off Flask.

Three pieces, one agent

A chatbot is a model in a box. A working agent is a stack: a web app students can click, an API that runs a model, and the model itself. In Kodin the capstone stack is Flask + Groq + GPT-OSS 20B. FastAPI can replace Flask as the web layer (same job: routes + JSON). Each layer can be swapped without changing the idea.

YouType a question in the browser
↓ HTTP POST /ask
Flask or FastAPIWeb app + routes. Serves the page, receives the question, returns JSON. This course uses Flask; FastAPI is the common alternative (async, OpenAPI docs).
↓ create_react_agent(llm, tools)
LangGraph agentThinks, may call a tool, then writes the answer
ToolsSearch, time, calculator — Python functions the model can request
↓ ChatGroq.invoke / tool loop
Groq (API platform)Your gsk_… key. Hosts open models on fast GPUs. Not the model itself.
↓ model = openai/gpt-oss-20b
Open-source modelGPT-OSS 20B in this course. Weights are open; Groq only runs them.

What each piece is responsible for

App layer

Flask or FastAPI

Both are Python web frameworks that expose the agent over HTTP. This course’s Research Agent uses Flask. FastAPI does the same job with @app.post("/ask"), automatic JSON, and interactive /docs.

  • Flask (this course): templates/index.html, POST /ask, optional /to-pdf
  • FastAPI: same routes; good when you want async and OpenAPI docs out of the box
  • Creates the LangGraph agent with your Groq key inside the route

Without a web app you still have a model — no door for a human to use it. Other doors: Django, Streamlit, Gradio.

API platform

Groq

Groq is an inference host. You paste a key, pick a model id, and send chat messages. It does not train the model. LangChain talks to it with ChatGroq.

This course uses Groq because it is fast and hosts GPT-OSS 20B. You can point the same agent at another host by changing one client class and the model string.

Brain

Open-source model

The model is the weights that predict the next token. openai/gpt-oss-20b is open (OpenAI GPT-OSS). Groq’s id still starts with openai/ because that is Groq’s catalog name, not “you must use OpenAI’s paid API.”

Hands

Tools

Practice in this module’s notebook: @tool + bind_tools. The model requests a function. Module 5’s ReAct agent actually runs it. Module 8’s capstone tool is research_web.

Alternate API platforms (same job as Groq)

All of these give you an HTTP API and a key. The agent code stays the same idea: create an LLM client → bind tools → loop.

PlatformTypical LangChain clientWhen you’d pick it
Groq (this course)ChatGroqFast hosted open models, simple gsk_ key
OpenAIChatOpenAIGPT-4.1 / GPT-5 family, official OpenAI API
Google AI Studio / GeminiChatGoogleGenerativeAIGemini models, Google Cloud key
AnthropicChatAnthropicClaude models
Together AIChatTogether or OpenAI-compatibleMany open models, OpenAI-style base URL
Fireworks AIOpenAI-compatible ChatOpenAIHosted Llama / Mixtral / Qwen
OpenRouterChatOpenAI + custom base URLOne key, many vendors behind one gateway
Ollama (local)ChatOllamaNo cloud key — model runs on your machine
Hugging Face InferenceHuggingFaceEndpoint / OpenAI-compatHub models, serverless endpoints
# Same agent, different host — only the client + model id change
llm = ChatGroq(model="openai/gpt-oss-20b")           # this course
# llm = ChatOpenAI(model="gpt-4.1-mini")              # OpenAI
# llm = ChatOpenAI(base_url="https://openrouter.ai/api/v1", model="meta-llama/llama-3.1-8b-instruct")
# llm = ChatOllama(model="llama3.1")                   # local, no Groq

Alternate open models (same job as GPT-OSS 20B)

Pick a model the platform actually hosts. Groq’s catalog is not identical to Together’s or Ollama’s. The name in code is the catalog id, not the research paper title.

Model familyExample idsNotes
GPT-OSS 20Bopenai/gpt-oss-20bThis course. Open weights, hosted on Groq.
Llama 3.1 / 3.3llama-3.1-8b-instant, llama-3.3-70b-versatileMeta open models; very common on Groq / Together / Ollama
Mistral / Mixtralmistral-small, Mixtral 8x7BStrong instruction following, European lab
Qwenqwen2.5-32bAlibaba open models, good multilingual
Gemmagemma2-9b-itGoogle open weights
DeepSeekDeepSeek-V3 / R1 (host-specific ids)Strong reasoning; check the host’s exact string

How the pieces connect (request path)

1
Browser → Flask or FastAPI. The page POSTs JSON { question, api_key } to /ask. The web framework is only HTTP. It does not “think.”
2
Web app → agent. create_research_agent(api_key) builds ChatGroq + tools + create_react_agent. That is LangGraph, not Flask/FastAPI.
3
Agent → Groq. Each thought or tool-choice is an API call. Groq authenticates with GROQ_API_KEY / the key from the UI.
4
Groq → model. Groq loads openai/gpt-oss-20b (or whichever id you set) and returns tokens. Swap the id, keep Groq, and you changed only the brain.
5
Tool hop (optional). If the model emits tool_calls, LangGraph runs Python (search, time, …) and sends the result back to Groq for a final answer.
6
Web app → browser. JSON { answer } is shown in the page. Convert to PDF (STEP 4) turns that text into a file and Kodin’s PDF viewer opens it.
You  →  Flask or FastAPI (/ask)  →  LangGraph agent  →  Groq API  →  GPT-OSS 20B
                ↑                │
                │                └→ tool (search / time) → back to model
                └──────── JSON answer + optional PDF

Before you click Practice

The notebook still trains tools (the hands). The visualization above is the rest of the machine. In Module 8 you will put Flask around the same Groq + model + tools pattern (you could use FastAPI the same way).

Practice task 1–2

Install + Groq key + GPT-OSS 20B

Same as Modules 1–2. You are talking to Groq’s API, not to a web app yet. Flask (or FastAPI) appears when you Build agent in Module 8.

MODEL = "openai/gpt-oss-20b"
llm = ChatGroq(model=MODEL, temperature=0)
Why: One line chooses the platform client (ChatGroq) and one string chooses the open model. That is the swap point for Together / OpenRouter / Ollama later.
Practice task 3–4

@tool and bind_tools

Create multiply and get_weather, then llm.bind_tools(tools). Print tool_calls — the model asks, it does not run the function yet (Module 5 does).

Expected: tool_calls for multiply(15, 4) and get_weather(Paris).

Check yourself

1. Groq is best described as:

2. You want the same agent without a cloud key. Which swap is right?

3. Flask or FastAPI’s job in the capstone is to: