Registry / llm-agents / langchainhub

langchainhub

JSON →
library0.1.21pypypi✓ verified 22d ago

LangChain Hub (pypi-slug: `langchainhub`) is an API client for the LangChain Hub, a centralized platform for sharing and discovering high-quality artifacts like prompts, chains, and agents for building LLM applications. It allows users to upload, browse, retrieve, and manage these components. The current version is 0.1.21. It's actively developed as part of the broader LangChain ecosystem, with releases typically tied to LangChain updates.

pip install langchainhub langchain
INSTALL
IMPORT
SIG · LANGCHAINHUB
L
langchainhub
llm-agentspythonv0.1.21
Install
8.8s avg
Import
805ms
Disk
84MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.21 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.164s · 75.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 8.8s · import 0.158s · 83MB
84MB installed
● package 84MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

hub
from langchain import hub
from langchainhub import hub
The primary interface for LangChain Hub is exposed through the `langchain` package, not directly from `langchainhub`. This changed in LangChain v0.3 where the 'hub' module (for managing prompts programmatically) was moved to `langchain-classic` or accessed via the `langchain` package itself.
load_prompt
from langchain.prompts import load_prompt
from langchain.hub import load_prompt
While `hub.pull` is used to retrieve content, `load_prompt` for local file loading is part of `langchain.prompts`.

This quickstart demonstrates how to pull a prompt from the LangChain Hub and use it with a LangChain LLM (ChatOpenAI) to form a simple question-answering chain. It assumes an OpenAI API key is available, preferably as an environment variable.

import os from langchain import hub from langchain_openai import ChatOpenAI # Set your API key as an environment variable (or replace with your actual key for testing) # os.environ["OPENAI_API_KEY"] = os.environ.get("OPENAI_API_KEY", "YOUR_API_KEY") # Pull a prompt from the LangChain Hub prompt = hub.pull("hwchase17/q-and-a-prompt") # Initialize a chat model (requires langchain-openai to be installed) llm = ChatOpenAI(openai_api_key=os.environ.get("OPENAI_API_KEY", "")) # Create a simple chain chain = prompt | llm # Invoke the chain response = chain.invoke({"question": "What is the capital of France?", "context": "Paris is the capital of France."}) print(response.content)
Debug
Known issues
breakingWith LangChain v0.3+, the 'hub' module for programmatic prompt management has been refactored. Direct imports like `from langchain import hub` or `from langchain.prompts import load_prompt` should be used, or `langchain-classic` may be required for older patterns.
fix
Ensure you are importing `hub` from `langchain` (e.g., `from langchain import hub`). If migrating from very old code, you might need to install `langchain-classic` and adjust imports, though current best practice is to use the `langchain` package directly for hub interactions.
affects: LangChain >= 0.3.0
breakingThe `initialize_agent()` function has been removed in LangChain v0.3. When loading agents from LangChain Hub, you should now use factory helpers like `create_react_agent` or other specific agent constructors.
fix
Replace calls to `initialize_agent()` with specific agent factory functions, for example, `create_react_agent` for React-style agents. Refer to the LangChain documentation for the appropriate factory function for your agent type.
affects: LangChain >= 0.3.0
gotchaLangChain Hub artifacts (prompts, chains, agents) are referenced using 'lc://' URIs. Misspellings or incorrect paths in these URIs will result in loading errors.
fix
Always verify the 'lc://' URI for the specific artifact on the LangChain Hub. The format is typically `lc://<user_or_org>/<artifact_type>/<artifact_name>`.
affects: All
Upgrade
Version history
0.1.21latest on PyPI · released Aug 11, 2024
Audit
Dependencies
langchainrequiredProvides core LangChain primitives and the `hub` module for interaction.
Agent activity
28 hits · last 30 days
node
24
OpenAI (training)
1
Resources
langchainhub — pip install langchainhub · libregistry