Problem
langchain-openai and langchain-anthropic are currently listed as required dependencies in pyproject.toml, but neither is directly imported in any executable source code. They are only resolved at runtime by langchain.chat_models.init_chat_model() when a user explicitly requests a specific LLM provider via a string identifier (e.g. "openai:gpt-4o" or "anthropic:claude-3-5-sonnet-latest").
This means installing langmem pulls in both provider SDKs (and their transitive dependencies like openai, anthropic, tiktoken, etc.) even when:
- A user only needs one provider
- A user passes a pre-instantiated model object and doesn't need either provider SDK — the
init_chat_model() factory is never invoked in this case, making both packages completely unused
Evidence
| Dependency |
Required? |
Actual usage in source |
langchain-openai>=0.3.1 |
Hard required |
Only referenced in docstring examples (short_term/summarization.py). Never imported in executable code. |
langchain-anthropic>=0.3.3 |
Hard required |
Never directly imported. Only loaded dynamically by init_chat_model() at runtime when a user passes an Anthropic model string. |
langchain-core |
Hard required |
Legitimately required — 56+ top-level imports across the codebase |
langchain |
Hard required |
Legitimately required — init_chat_model imported in 3 modules |
langgraph |
Hard required |
Legitimately required — 20+ top-level imports |
langsmith |
Hard required |
Legitimately required — top-level imports in 5 modules |
trustcall |
Hard required |
Legitimately required — top-level imports in 4 modules |
Proposal
Move langchain-openai and langchain-anthropic to optional dependency groups:
[project.optional-dependencies]
openai = ["langchain-openai>=0.3.1"]
anthropic = ["langchain-anthropic>=0.3.3"]
all = [
"langchain-openai>=0.3.1",
"langchain-anthropic>=0.3.3",
]
Users would install only what they need:
pip install langmem # Core only — works with pre-instantiated models
pip install langmem[openai] # OpenAI provider
pip install langmem[anthropic] # Anthropic provider
pip install langmem[all] # Both providers
Impact
- No breaking changes to code —
init_chat_model() already handles missing providers with a clear error message at runtime
- Lighter default install — removes
openai, anthropic, tiktoken, httpx, and other transitive deps for users who don't need them
- Better developer experience — users who pass custom model instances don't have to install unused SDKs
P.S.
Want to validate the general vision of the team on this. Happy to submit the PR
Problem
langchain-openaiandlangchain-anthropicare currently listed as required dependencies inpyproject.toml, but neither is directly imported in any executable source code. They are only resolved at runtime bylangchain.chat_models.init_chat_model()when a user explicitly requests a specific LLM provider via a string identifier (e.g."openai:gpt-4o"or"anthropic:claude-3-5-sonnet-latest").This means installing
langmempulls in both provider SDKs (and their transitive dependencies likeopenai,anthropic,tiktoken, etc.) even when:init_chat_model()factory is never invoked in this case, making both packages completely unusedEvidence
langchain-openai>=0.3.1short_term/summarization.py). Never imported in executable code.langchain-anthropic>=0.3.3init_chat_model()at runtime when a user passes an Anthropic model string.langchain-corelangchaininit_chat_modelimported in 3 moduleslanggraphlangsmithtrustcallProposal
Move
langchain-openaiandlangchain-anthropicto optional dependency groups:Users would install only what they need:
Impact
init_chat_model()already handles missing providers with a clear error message at runtimeopenai,anthropic,tiktoken,httpx, and other transitive deps for users who don't need themP.S.
Want to validate the general vision of the team on this. Happy to submit the PR