Pull and push prompts from LangChain Hub for sharing and versioning.
function pull<T extends Runnable>(
ownerRepoCommit: string,
options?: {
apiKey?: string;
apiUrl?: string;
includeModel?: boolean;
modelClass?: new (...args: any[]) => BaseLanguageModel;
}
): Promise<T>;Examples:
import { pull } from "langchain/hub";
// Pull latest version
const prompt = await pull("owner/repo-name");
// Pull specific commit
const specificPrompt = await pull("owner/repo-name:commit-hash");
// Use with agent
import { createAgent } from "langchain";
const ragPrompt = await pull("langchain-ai/rag-prompt");
const agent = createAgent({
model: "openai:gpt-4o",
tools: [searchTool],
systemPrompt: ragPrompt,
});
// Format a prompt
import { ChatPromptTemplate } from "@langchain/core/prompts";
const template = await pull<ChatPromptTemplate>("langchain-ai/summarization");
const formatted = await template.format({ text: "Long text..." });function push(
repoFullName: string,
runnable: Runnable,
options?: {
apiKey?: string;
apiUrl?: string;
parentCommitHash?: string;
isPublic?: boolean;
description?: string;
readme?: string;
tags?: string[];
}
): Promise<string>;Examples:
import { push } from "langchain/hub";
import { ChatPromptTemplate } from "@langchain/core/prompts";
// Create and push
const template = ChatPromptTemplate.fromMessages([
["system", "You are a helpful assistant that {task}."],
["human", "{input}"],
]);
const commitUrl = await push("my-username/my-custom-prompt", template);
console.log("Pushed to:", commitUrl);
// With API key
await push("my-username/my-prompt", template, {
apiKey: "lsv2_...",
});// Node.js-specific with enhanced model loading
import { pull, push } from "langchain/hub/node";Difference: langchain/hub/node automatically resolves chat models by class name when includeModel: true, without requiring modelClass parameter. Standard hub requires modelClass for non-OpenAI models.
// Standard hub - requires modelClass
import { pull } from "langchain/hub";
import { ChatAnthropic } from "@langchain/anthropic";
const prompt = await pull("owner/anthropic-prompt", {
includeModel: true,
modelClass: ChatAnthropic,
});
// Node.js hub - automatic resolution
import { pull } from "langchain/hub/node";
const prompt = await pull("owner/anthropic-prompt", {
includeModel: true,
});LANGCHAIN_API_KEY: API key for Hub authenticationLANGCHAIN_HUB_URL: Optional custom Hub URL// Uses LANGCHAIN_API_KEY from environment
const prompt = await pull("owner/repo");
await push("owner/repo", template);
// Explicit API key
await push("owner/repo", template, {
apiKey: process.env.MY_CUSTOM_API_KEY,
});Versioning:
import { push, pull } from "langchain/hub";
// Push v1
await push("my-org/customer-support", promptV1);
// Push v2
await push("my-org/customer-support", promptV2);
// Pull specific version
const oldPrompt = await pull("my-org/customer-support:commit-hash-v1");
const newPrompt = await pull("my-org/customer-support");Team Collaboration:
import { pull, createAgent } from "langchain";
const teamPrompt = await pull("company/product-assistant");
const agent1 = createAgent({
model: "openai:gpt-4o",
systemPrompt: teamPrompt,
tools: [toolsForApp1],
});
const agent2 = createAgent({
model: "anthropic:claude-3-5-sonnet",
systemPrompt: teamPrompt,
tools: [toolsForApp2],
});Error Handling:
import { pull, push } from "langchain/hub";
try {
const prompt = await pull("owner/nonexistent");
} catch (error) {
if (error.message.includes("404")) {
console.error("Not found");
} else if (error.message.includes("401")) {
console.error("Auth failed");
}
}
try {
await push("owner/repo", template);
} catch (error) {
if (error.message.includes("401")) {
console.error("Set LANGCHAIN_API_KEY");
}
}type Runnable = any;
type BaseLanguageModel = any;