Skip to content

Commit 27fa004

Browse files
jeremymanningclaude
andcommitted
Fix langchain import: text_splitter moved to langchain-text-splitters
The langchain package restructured — RecursiveCharacterTextSplitter now lives in the standalone langchain-text-splitters package. Updated both the pip install and the import statement. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6402a0e commit 27fa004

1 file changed

Lines changed: 2 additions & 59 deletions

File tree

slides/week9/agents_demo.ipynb

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"execution_count": null,
1616
"metadata": {},
1717
"outputs": [],
18-
"source": "# Install required packages\n!pip install -q smolagents[litellm] ddgs datasets sentence-transformers faiss-cpu langchain langchain-community"
18+
"source": "# Install required packages\n!pip install -q smolagents[litellm] ddgs datasets sentence-transformers faiss-cpu langchain-text-splitters langchain-community"
1919
},
2020
{
2121
"cell_type": "code",
@@ -205,64 +205,7 @@
205205
"execution_count": null,
206206
"metadata": {},
207207
"outputs": [],
208-
"source": [
209-
"from langchain.text_splitter import RecursiveCharacterTextSplitter\n",
210-
"from langchain_community.vectorstores import FAISS\n",
211-
"from langchain_community.embeddings import HuggingFaceEmbeddings\n",
212-
"\n",
213-
"# Our \"knowledge base\" — key concepts from the lecture\n",
214-
"documents = [\n",
215-
" \"The ReAct framework (Yao et al., 2023) interleaves reasoning and acting. \"\n",
216-
" \"The agent generates a Thought, takes an Action by calling a tool, receives an \"\n",
217-
" \"Observation, and repeats until it has enough information for a Final Answer.\",\n",
218-
"\n",
219-
" \"Model Context Protocol (MCP) is an open standard created by Anthropic in November 2024. \"\n",
220-
" \"It standardizes how LLMs connect to external tools and data sources, similar to how \"\n",
221-
" \"USB-C standardized physical connectors. MCP moved to the Linux Foundation in 2025.\",\n",
222-
"\n",
223-
" \"SWE-bench measures how well AI agents can resolve real GitHub issues. The state of the \"\n",
224-
" \"art improved from 14% (2024) to 81% (2026). Claude Code reached $1B in annualized \"\n",
225-
" \"revenue within 6 months, showing massive commercial demand for coding agents.\",\n",
226-
"\n",
227-
" \"Computer use agents can see screens, click buttons, and type text. Anthropic's Claude \"\n",
228-
" \"computer use scored 22% on OSWorld in October 2024 and 72.0% by February 2026 — a \"\n",
229-
" \"3.3x improvement in 16 months.\",\n",
230-
"\n",
231-
" \"Multi-agent systems use multiple LLMs collaborating on complex tasks. Common architectures \"\n",
232-
" \"include orchestrator-worker (one agent delegates to specialists), debate (agents argue \"\n",
233-
" \"toward consensus), and pipeline (sequential handoffs between agents).\",\n",
234-
"\n",
235-
" \"Agent safety concerns include prompt injection (malicious content hijacks the agent), \"\n",
236-
" \"tool misuse (agent with write permissions takes harmful actions), cascading errors \"\n",
237-
" \"(one bad tool call triggers a chain of failures), and the principal-agent problem \"\n",
238-
" \"(how do you verify an opaque agent did what you wanted?).\",\n",
239-
"\n",
240-
" \"The 2026 International AI Safety Report found that AI agents can identify 77% of \"\n",
241-
" \"vulnerabilities in real software. Criminal groups are actively using general-purpose AI. \"\n",
242-
" \"Multiple companies could not rule out bioweapons uplift before deploying.\",\n",
243-
"\n",
244-
" \"In February 2026, the Pentagon demanded unrestricted use of Claude for military purposes. \"\n",
245-
" \"When Anthropic CEO Dario Amodei refused, the government ordered all agencies to cease \"\n",
246-
" \"using Anthropic's technology and threatened to invoke the Defense Production Act.\",\n",
247-
"\n",
248-
" \"Professor Kenneth Payne at King's College London ran 21 simulated nuclear crises with \"\n",
249-
" \"GPT-5.2, Claude Sonnet 4, and Gemini 3 Flash. Nuclear signaling occurred in 95% of games. \"\n",
250-
" \"Claude recommended nuclear strikes in 64% of games — the highest rate of all models.\",\n",
251-
"\n",
252-
" \"Deep research agents from OpenAI, Google, and Perplexity were all launched within an \"\n",
253-
" \"11-day window in February 2025. They can autonomously browse the web for hours, \"\n",
254-
" \"synthesizing 100+ page reports from dozens of sources.\"\n",
255-
"]\n",
256-
"\n",
257-
"# Split into chunks and build a vector index\n",
258-
"splitter = RecursiveCharacterTextSplitter(chunk_size=300, chunk_overlap=50)\n",
259-
"chunks = splitter.create_documents(documents)\n",
260-
"\n",
261-
"embeddings = HuggingFaceEmbeddings(model_name=\"sentence-transformers/all-MiniLM-L6-v2\")\n",
262-
"vectordb = FAISS.from_documents(chunks, embeddings)\n",
263-
"\n",
264-
"print(f\"Knowledge base ready: {len(chunks)} chunks indexed\")"
265-
]
208+
"source": "from langchain_text_splitters import RecursiveCharacterTextSplitter\nfrom langchain_community.vectorstores import FAISS\nfrom langchain_community.embeddings import HuggingFaceEmbeddings\n\n# Our \"knowledge base\" — key concepts from the lecture\ndocuments = [\n \"The ReAct framework (Yao et al., 2023) interleaves reasoning and acting. \"\n \"The agent generates a Thought, takes an Action by calling a tool, receives an \"\n \"Observation, and repeats until it has enough information for a Final Answer.\",\n\n \"Model Context Protocol (MCP) is an open standard created by Anthropic in November 2024. \"\n \"It standardizes how LLMs connect to external tools and data sources, similar to how \"\n \"USB-C standardized physical connectors. MCP moved to the Linux Foundation in 2025.\",\n\n \"SWE-bench measures how well AI agents can resolve real GitHub issues. The state of the \"\n \"art improved from 14% (2024) to 81% (2026). Claude Code reached $1B in annualized \"\n \"revenue within 6 months, showing massive commercial demand for coding agents.\",\n\n \"Computer use agents can see screens, click buttons, and type text. Anthropic's Claude \"\n \"computer use scored 22% on OSWorld in October 2024 and 72.0% by February 2026 — a \"\n \"3.3x improvement in 16 months.\",\n\n \"Multi-agent systems use multiple LLMs collaborating on complex tasks. Common architectures \"\n \"include orchestrator-worker (one agent delegates to specialists), debate (agents argue \"\n \"toward consensus), and pipeline (sequential handoffs between agents).\",\n\n \"Agent safety concerns include prompt injection (malicious content hijacks the agent), \"\n \"tool misuse (agent with write permissions takes harmful actions), cascading errors \"\n \"(one bad tool call triggers a chain of failures), and the principal-agent problem \"\n \"(how do you verify an opaque agent did what you wanted?).\",\n\n \"The 2026 International AI Safety Report found that AI agents can identify 77% of \"\n \"vulnerabilities in real software. Criminal groups are actively using general-purpose AI. \"\n \"Multiple companies could not rule out bioweapons uplift before deploying.\",\n\n \"In February 2026, the Pentagon demanded unrestricted use of Claude for military purposes. \"\n \"When Anthropic CEO Dario Amodei refused, the government ordered all agencies to cease \"\n \"using Anthropic's technology and threatened to invoke the Defense Production Act.\",\n\n \"Professor Kenneth Payne at King's College London ran 21 simulated nuclear crises with \"\n \"GPT-5.2, Claude Sonnet 4, and Gemini 3 Flash. Nuclear signaling occurred in 95% of games. \"\n \"Claude recommended nuclear strikes in 64% of games — the highest rate of all models.\",\n\n \"Deep research agents from OpenAI, Google, and Perplexity were all launched within an \"\n \"11-day window in February 2025. They can autonomously browse the web for hours, \"\n \"synthesizing 100+ page reports from dozens of sources.\"\n]\n\n# Split into chunks and build a vector index\nsplitter = RecursiveCharacterTextSplitter(chunk_size=300, chunk_overlap=50)\nchunks = splitter.create_documents(documents)\n\nembeddings = HuggingFaceEmbeddings(model_name=\"sentence-transformers/all-MiniLM-L6-v2\")\nvectordb = FAISS.from_documents(chunks, embeddings)\n\nprint(f\"Knowledge base ready: {len(chunks)} chunks indexed\")"
266209
},
267210
{
268211
"cell_type": "code",

0 commit comments

Comments
 (0)