Homework
Complete these tasks before Lesson 19. Work in a notebook or script. The goal is to deepen your understanding of when and how to use orchestration frameworks effectively.
Task 1: Add Conversation Memory to LangChain
Goal: Extend your LangChain chain from the lab to support multi-turn conversations with memory.
Instructions
Build a conversational chain that remembers previous exchanges:
- Create a
ChatPromptTemplatethat includes a placeholder for conversation history:from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder prompt = ChatPromptTemplate.from_messages([ ("system", "You are a helpful technical assistant. Be concise."), MessagesPlaceholder(variable_name="history"), ("human", "{input}") ]) - Implement a conversation loop that maintains a list of messages and passes them as the
historyvariable on each turn. - Have at least a 5-turn conversation where later questions depend on context from earlier turns. For example:
- Turn 1: "What is a vector database?"
- Turn 2: "Give me three examples of popular ones."
- Turn 3: "Which of those would you recommend for a small project?"
- Turn 4: "How would I set it up with Python?"
- Turn 5: "Can you summarise what we discussed?"
- Verify that the model correctly references information from earlier turns in its later responses.
Self-check
- ✓ Your conversation loop runs for at least 5 turns.
- ✓ The model's answer to turn 3 correctly references the examples from turn 2.
- ✓ The turn 5 summary covers topics from the entire conversation.
- ✓ You can explain how the history is passed to the model on each turn.
Task 2: Swap LLM Providers
Goal: Experience the provider-agnostic benefit of frameworks by switching from Claude to another provider.
Instructions
Take your working LangChain chain (from the lab or Task 1) and your LlamaIndex RAG pipeline:
- Swap the LLM from Claude to OpenAI (or vice versa, or to a local model via Ollama if you have one running):
# LangChain: change one import and one line from langchain_openai import ChatOpenAI model = ChatOpenAI(model="gpt-4o", temperature=0) # LlamaIndex: change one import and one line from llama_index.llms.openai import OpenAI Settings.llm = OpenAI(model="gpt-4o") - Run the exact same queries on both providers.
- Compare the outputs:
- Are the answers substantively different?
- Is one more verbose or more concise?
- For the RAG pipeline: does one cite sources more accurately?
- Record your observations in a short comparison (~150 words).
Self-check
- ✓ You ran the same queries on at least two different LLM providers.
- ✓ The provider swap required changing no more than 2–3 lines of code.
- ✓ Your comparison notes specific differences, not just "they were similar".
- ✓ You can articulate one scenario where you would prefer each provider.
Task 3: Framework Decision Memo
Goal: Practice the real-world skill of choosing the right tool for a project.
Instructions
Choose one of the following project scenarios (or invent your own):
- Scenario A: A customer support chatbot that answers questions about your product documentation (50 pages of docs, ~100 queries/day).
- Scenario B: A code review assistant that takes a git diff and produces a structured review with suggestions (single LLM call per review, ~20 reviews/day).
- Scenario C: An internal research tool that lets employees query 10,000 internal documents, with follow-up questions and the ability to search the web when internal docs are insufficient.
Write a decision memo (300–500 words) that recommends one of these approaches:
- Direct API calls only
- LangChain
- LlamaIndex
- A combination
Your memo should address:
- Why the chosen approach is the best fit for the scenario's requirements
- What trade-offs you are accepting
- What would need to change about the project for you to choose a different approach
- Estimated dependency footprint and maintenance burden
Self-check
- ✓ Your memo is 300–500 words.
- ✓ You make a clear recommendation with specific reasoning (not "it depends").
- ✓ You address at least two trade-offs of your chosen approach.
- ✓ You describe a concrete condition that would change your recommendation.
- ✓ A technical manager could use your memo to make a decision.
Submission
There is no formal submission for this course. These tasks are for your own development. However:
- Keep your Task 3 memo — you will revisit framework decisions in Module 7 (Production & Scale).
- If working with a group, share your decision memos and discuss where your recommendations differ.
- Save your provider comparison notes from Task 2 — they will be useful in Lesson 19 (Comparing LLM Providers).
Next lesson: Lesson 19 — Comparing LLM Providers