
Learn how large language models power adaptive games by connecting prompts, memory, reasoning, tools, retrieval augmented generation, and OpenAI function calling to create AI agents that think, act, and interact.
Download the course code from the GitHub repository to follow along. Choose zip download or git clone with git bash, then access all chapters and requirements.
Acquire and set up your OpenAI API key in the .env environment file, learn to create and manage API keys, credits, and per-folder environment files for this course.
Create and activate a Python virtual environment with venv, install libraries from requirements.txt (including LangChain), and run course code in isolation, with future coverage of Jupyter Notebook.
Open the Jupyter Notebook in the virtual environment as the code editor for chapters 1-11, and learn Lang Chain to build the game, with optional VSCode or PyCharm.
Turn Python into an AI assistant by sending chat completions with system, user, and assistant roles, loading API keys from a .env file via OpenAI SDK using GPT four mini.
Learn how to shape model responses with tone, few-shot prompts, and context controls, and apply guardrails like max tokens and safety notes for reliable, style-driven outputs.
Master lang chain input and output foundations, including rag memory streaming and an asynchronous call, by making your first model call and converting prompts to structured json.
Explore how prompt templates and the LCL pipe enable repeatable, parameterized prompts and string outputs, using placeholders product and style to generate reliable UI-ready results.
learn to enforce structured output with pydantic and LangChain by defining a base model schema (question, short answer, tags) and validating llm output as a pedantic object.
Enforce a structured FAQ schema with a LangChain workflow, using Chat OpenAI and GPT-4 mini to produce a short answer and tags for Italy traveler adapters.
Explore retrieval augmented generation (rag) to give LLMs context via embeddings and vector stores, using the files library (faiss) to retrieve relevant documents with cosine similarity.
Explore a tiny rag implementation with vector stores, embeddings, and cosine similarity to enable retrieval augmented generation using LangChain and OpenAI embeddings within a local knowledge base.
Learn to implement memory in a multi-turn chat by attaching a message history to the chain, storing prior turns in in-memory ram for per-session memory with runnable with message history.
Explore building a validated JSON plan with a pedantic schema using LangChain, defining an intent and a list of steps, then stream outputs as chunks from the model.
Explore asynchronous calls with invoke and await in building language model pipelines, compare synchronous vs asynchronous APIs, and contrast monolithic and microservices architectures.
Learn the basics of prompt templating in LangChain, including reusable prompts, placeholders, environment variables, and long chain expression language, plus chaining with a string output parser.
Explore chat prompt templates and role based prompts to shape responses, set tone and structure, and gain tighter control over output through system policy and roles.
Explore partials in LangChain by pre-filling common variables and using placeholders and defaults to streamline prompts, set tone, and generate tips at runtime.
Explore few-shot prompting to steer language models with crafted examples, prefix and suffix templates, and an output parser to generate structured, numbered answers.
Explore dynamic few-shot prompting that selects concise examples at runtime using a length-based example selector, guided by semantic similarity and prompt templates.
Learn to inject memory into chat prompts using a messages placeholder, enabling history-aware responses by defining system, history, and question placeholders in the chat prompt template.
Explore Jinja2 templates as an optional templating engine, learn its syntax for variables, if statements, and loops, and see how to format prompts with placeholders and runtime values.
Explore multi input prompts and lightweight validation using typing dict to enforce a product, audience, and tone schema before calling the model, with value errors for missing fields.
Build a rag-based prompt template by creating chunks, embeddings, and a vector store; retrieve relevant snippets with a retriever and format them into a prompt for the LLM.
Explore Lang Chain Expression Language (LCL) chains and output parsers to Python types, then build advanced chains with branching, routing, and parallelism using prompt templates, libraries, and environment variables.
Bind constants to the language model with the dot bind function to reuse prompts, enforce one-line outputs, and control stops at new lines and max tokens and temperature.
Explore output parsers to convert model output into structured data with JSON parsing and pedantic structured output. Define a base model with name and bullets for deterministic LangChain results.
Explore parallel fan out using runnable parallel to run two chains, summarization and keywords, in parallel and merge results into a final tweet.
Learn branching and routing with runnable branch to route inputs to different sub chains based on conditions, such as question versus task, using a router predicate and conditional chains.
Explore fallbacks in LangChain by using a backup chain with callbacks when the main chain fails, ensuring robust error handling.
Explore batch and map over a list of inputs, looping through items to produce outputs as prompts by applying a basic chain.
Build a basic batch chain using a prompt template, audience and product placeholders, and a string output parser, then compare pedantic and JSON parsers with typing.
Enable streaming in a terminal or UI to make your app feel instant by iterating over streaming chunks and printing content as it arrives.
Explore conditional enrichment with fallbacks in LangChain by routing inputs through targeted pipelines, summarizing long text when needed, and employing fallbacks for parsing or chain failures.
Learn to implement and trace LangChain callbacks, including attaching handlers to chains, handling token usage and errors, and exporting callbacks to csv files with pandas for real-time lifecycle insights.
Implement a custom callback to gather chain and LM lifecycle data with a telemetry handler, capturing run IDs, inputs, prompts, durations, token usage, and exportable CSV analytics.
Learn to stream with callbacks by configuring the stream, defining a callback handler to track chunks and tokens, and view telemetry while printing events during streaming.
Master asynchronous runs with callbacks by invoking a coroutine, awaiting results, and using a template plus string output parser in a basic chain to print responses.
Learn how to implement a retrieval-augmented rack system with embedding and indexing, using a cosine-similarity retriever, prompts, telemetry, and tool callbacks.
Explore memory building blocks such as chat message history, conversation buffer memory, and a conversation chain powered by OpenAI to preserve context across interactions.
Summarize long conversations with conversation summary buffer memory, which preserves recent turns and auto-summarizes earlier content under a 100-token cap, then preload two turns for concise history.
Build a Streamlit based chat bot app by composing a prompt with a chat template, wiring an LM chain with a string output parser, and managing chat history.
Build a chatbot prompt chain by defining system roles, injecting history from a prompt template, and linking an LLM with an output parser.
Learn to let a language model act by calling tools, using Python functions as tools in LangChain, with weather and outdoor availability checks.
Master designing and invoking custom tools in llm workflows using tool mapping, messages, and tool calls; compare Python function and Elm docstrings, and preview rag and agent for games.
Explore retrieval augmented generation (rag) fundamentals, converting a knowledge base into vectors with embeddings and indexing, using cosine similarity for fast retrieval to power reliable question answering with llms.
Load and enrich a document with metadata via a document schema, then split into 100-character chunks with 20-character overlap, and generate embeddings for cosine similarity-based retrieval.
Explore OpenAI embeddings to create encoder-based vector representations, mapping words into 1536-dimensional vectors, and measure relatedness with cosine similarity for search, clustering, and classification, stored in the vector store.
Explain how text embeddings of dimension 1536 are compared with cosine similarity, using the dot product and normalization to measure relatedness between texts like solar system topics versus baking.
Load embeddings into a vector store with Facebook AI similarity search, use cosine similarity to rank documents, create the index, and retrieve results via a retriever in a RAG pipeline.
Learn to build a retrieval qa system using vectors, cosine similarity, and a document retriever, then connect to an elm retrieval chain with prompt templates and an llm.
Build a retrieval-augmented generation API for a RAG system using FastAPI, embeddings, and a vector store to power a QA retrieval chain and document chain.
In this project-based course, you'll use LangChain and the OpenAI API to transform game ideas into intelligent, interactive experiences. We'll begin by establishing the fundamentals that make LLM systems predictable and cost-effective: prompt templates that separate content from structure, chains that combine multiple steps into reliable workflows, callbacks for tracing and telemetry, and memory strategies that keep context tight without increasing token costs.
Once these building blocks are ready, you'll move on to RAG (Retrieval-Augmented Generation), enabling NPCs to answer questions and make decisions based on your own game lore and documents. You'll also create agents that safely call in-game tools through validated, schema-driven function calls and strict allowlists. Throughout the course, you'll instrument your code, test behaviors deterministically, and implement guardrails to ensure outputs stay on policy. The course concludes with two platformer mini-games in which an agent and NPCs compete, adapting strategies using memory and retrieval to outplay each other. By the end, you'll have a reusable toolkit—prompts, chains, memory, RAG, and agents, along with portfolio-ready demos you can extend or deploy.
What you'll build & learn
OpenAI API fundamentals: streaming, reliable JSON/structured outputs, and function (tool) calling.
LangChain I/O & prompts: PromptTemplate, ChatPromptTemplate, few-shot patterns, and output validation.
Chains: sequential and router chains, batching/streaming, retries, and cost/latency tuning.
Callbacks & tracing: observe runs end-to-end and debug model/tool behavior with clear telemetry.
Memory: buffer, summary, and vector-backed memory with persistence, TTLs, and guardrails.
RAG: loaders → chunking → embeddings → retrievers → grounded answers with citations and filters.
Agents: ReAct/function-calling agents with strict schemas, allowlists, timeouts, and safeguards.
Games: two AI platformers where agent/NPC strategies evolve based on retrieved knowledge and remembered context.
You'll finish with practical, production-shaped patterns you can reuse in games, chat assistants, or any interactive LLM application.