1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
18 small wins to finish your pathNext lesson →
Real models: model strings and keys
Anywhere LangMem takes a model, a string like anthropic:claude-sonnet-4-5 works too. LangChain turns it into a chat model that reads its key from the environment.
manager = create_memory_manager("anthropic:claude-sonnet-4-5")A string is passed to LangChain's init_chat_model. The provider's integration package must be installed, and its key set:
| Model string | Package | Key |
|---|---|---|
anthropic:claude-sonnet-4-5 | langchain-anthropic | ANTHROPIC_API_KEY |
openai:gpt-4.1-mini | langchain-openai | OPENAI_API_KEY |
ollama:llama3.2 | langchain-ollama | none; runs on your machine |
from langmem import create_memory_manager
manager = create_memory_manager("anthropic:claude-sonnet-4-5")
manager.invoke({"messages": [{"role": "user", "content": "Please email me."}]})With no key, the call fails before anything is sent, and the message names the variable to set. The rest of the course passes MemoryModel() where this passes a string.
Memory needs a capable model
Extraction works through parallel tool calls with nested JSON Patch arguments. Small local models often get those wrong; a model that is good at tool calling matters more here than a model that writes well.
Try it yourself
- Pass
"openai:gpt-4.1-mini"and read the error. - Create the model yourself with
init_chat_model("anthropic:claude-sonnet-4-5", temperature=0)and pass the object. - List what a model needs to do for LangMem, from lesson 3's request.
Every expert started right here.