{ question, api_key } to /ask. The web framework is only HTTP. It does not “think.”Module 3: Flask or FastAPI, Groq, open-source models — and how they become one working agent
The agent is three Lego bricks. This course uses the left column. The right column is the same job with a different brand.
You → Flask or FastAPI → LangGraph → Groq (or alt) → model. Tools hang off the agent, not off Flask.
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.
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.
templates/index.html, POST /ask, optional /to-pdfWithout a web app you still have a model — no door for a human to use it. Other doors: Django, Streamlit, Gradio.
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.
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.”
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.
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.
| Platform | Typical LangChain client | When you’d pick it |
|---|---|---|
| Groq (this course) | ChatGroq | Fast hosted open models, simple gsk_ key |
| OpenAI | ChatOpenAI | GPT-4.1 / GPT-5 family, official OpenAI API |
| Google AI Studio / Gemini | ChatGoogleGenerativeAI | Gemini models, Google Cloud key |
| Anthropic | ChatAnthropic | Claude models |
| Together AI | ChatTogether or OpenAI-compatible | Many open models, OpenAI-style base URL |
| Fireworks AI | OpenAI-compatible ChatOpenAI | Hosted Llama / Mixtral / Qwen |
| OpenRouter | ChatOpenAI + custom base URL | One key, many vendors behind one gateway |
| Ollama (local) | ChatOllama | No cloud key — model runs on your machine |
| Hugging Face Inference | HuggingFaceEndpoint / OpenAI-compat | Hub 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
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 family | Example ids | Notes |
|---|---|---|
| GPT-OSS 20B | openai/gpt-oss-20b | This course. Open weights, hosted on Groq. |
| Llama 3.1 / 3.3 | llama-3.1-8b-instant, llama-3.3-70b-versatile | Meta open models; very common on Groq / Together / Ollama |
| Mistral / Mixtral | mistral-small, Mixtral 8x7B | Strong instruction following, European lab |
| Qwen | qwen2.5-32b | Alibaba open models, good multilingual |
| Gemma | gemma2-9b-it | Google open weights |
| DeepSeek | DeepSeek-V3 / R1 (host-specific ids) | Strong reasoning; check the host’s exact string |
{ question, api_key } to /ask. The web framework is only HTTP. It does not “think.”create_research_agent(api_key) builds ChatGroq + tools + create_react_agent. That is LangGraph, not Flask/FastAPI.GROQ_API_KEY / the key from the UI.openai/gpt-oss-20b (or whichever id you set) and returns tokens. Swap the id, keep Groq, and you changed only the brain.tool_calls, LangGraph runs Python (search, time, …) and sends the result back to Groq for a final answer.{ 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
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)
ChatGroq) and one string chooses the open model. That is the swap point for Together / OpenRouter / Ollama later.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).
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: