Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build required workspace packages
run: pnpm build --filter=@langchain/openai --filter=@langchain/anthropic --filter=@langchain/cohere --filter=@langchain/textsplitters
- name: Test LangChain with latest deps
run: docker compose -f dependency_range_tests/docker-compose.yml run langchain-latest-deps

Expand All @@ -72,6 +76,10 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build required workspace packages
run: pnpm build --filter=@langchain/openai --filter=@langchain/anthropic --filter=@langchain/cohere --filter=@langchain/textsplitters
- name: Test LangChain with lowest deps
run: docker compose -f dependency_range_tests/docker-compose.yml run langchain-lowest-deps

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/standard-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
mistralai,
aws,
google-vertexai-web,
agents,
]
steps:
- uses: actions/checkout@v4
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@ credentials.json
.vercel

bun.lock
coverage/

examples/src/createReactAgent/*.png
10 changes: 9 additions & 1 deletion dependency_range_tests/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

services:
# LangChain
langchain-latest-deps:
Expand All @@ -10,6 +9,10 @@ services:
working_dir: /app
volumes:
- ../libs/langchain:/langchain
- ../libs/langchain-textsplitters:/libs/langchain-textsplitters
- ../libs/providers/langchain-openai:/libs/langchain-openai
- ../libs/providers/langchain-anthropic:/libs/langchain-anthropic
- ../libs/providers/langchain-cohere:/libs/langchain-cohere
- ./scripts:/scripts
command: bash /scripts/langchain/test-with-latest-deps.sh
langchain-lowest-deps:
Expand All @@ -21,6 +24,11 @@ services:
working_dir: /app
volumes:
- ../libs/langchain:/langchain
- ../libs/langchain-core:/libs/langchain-core
- ../libs/langchain-textsplitters:/libs/langchain-textsplitters
- ../libs/providers/langchain-openai:/libs/langchain-openai
- ../libs/providers/langchain-anthropic:/libs/langchain-anthropic
- ../libs/providers/langchain-cohere:/libs/langchain-cohere
- ./scripts:/scripts
command: bash /scripts/langchain/test-with-lowest-deps.sh

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,52 @@ const communityPackageJsonPath = "package.json";
const currentPackageJson = JSON.parse(
fs.readFileSync(communityPackageJsonPath)
);
currentPackageJson.pnpm = { overrides: {} };

// Convert workspace dependencies to peer dependencies since they don't exist in the test environment
if (currentPackageJson.devDependencies) {
for (const [depName, depVersion] of Object.entries(
currentPackageJson.devDependencies
)) {
if (depVersion.includes("workspace:")) {
delete currentPackageJson.devDependencies[depName];
}
}
if (
currentPackageJson.peerDependencies?.["@langchain/core"] &&
!currentPackageJson.peerDependencies["@langchain/core"].includes("rc")
) {
currentPackageJson.peerDependencies = {
...currentPackageJson.peerDependencies,
"@langchain/core": "*",
};
}

if (currentPackageJson.dependencies) {
for (const [depName, depVersion] of Object.entries(
currentPackageJson.dependencies
)) {
if (depVersion.includes("workspace:")) {
// Convert workspace dependencies to peer dependencies
if (!currentPackageJson.peerDependencies) {
currentPackageJson.peerDependencies = {};
}
currentPackageJson.peerDependencies[depName] = "*";
delete currentPackageJson.dependencies[depName];
}
/**
* Link workspace dependencies via file path
*/
const workspaceDependencies = [
...Object.entries(currentPackageJson.devDependencies),
...Object.entries(currentPackageJson.dependencies),
].filter(([, depVersion]) => depVersion.includes("workspace:"));

for (const [depName, depVersion] of workspaceDependencies) {
/**
* for the peer dependency @langchain/core, we want to make sure to install max version
* defined above
*/
if (depName === "@langchain/core") {
delete currentPackageJson.devDependencies[depName];
continue;
}
}

if (currentPackageJson.devDependencies?.["@langchain/core"]) {
delete currentPackageJson.devDependencies["@langchain/core"];
currentPackageJson.peerDependencies["@langchain/core"] = "*";
const libName = depName.split("/")[1];
/**
* reference the workspace dependency as a file path
*/
currentPackageJson.devDependencies[
depName
] = `file:/libs/langchain-${libName}`;
/**
* ensure that peer dependencies are also installed from the file path
* e.g. @langchain/openai depends on @langchain/core which should be resolved from the file path
*/
currentPackageJson.pnpm.overrides[
depName
] = `file:/libs/langchain-${libName}`;
}

// Stupid hack
currentPackageJson.resolutions = {
...currentPackageJson.resolutions,
jackspeak: "2.1.1",
};

fs.writeFileSync(
communityPackageJsonPath,
JSON.stringify(currentPackageJson, null, 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const communityPackageJsonPath = "package.json";
const currentPackageJson = JSON.parse(
fs.readFileSync(communityPackageJsonPath)
);
currentPackageJson.pnpm = { overrides: {} };

if (
currentPackageJson.peerDependencies?.["@langchain/core"] &&
Expand All @@ -20,68 +21,40 @@ if (
};
}

// Convert workspace dependencies to peer dependencies since they don't exist in the test environment
if (currentPackageJson.devDependencies) {
for (const [depName, depVersion] of Object.entries(
currentPackageJson.devDependencies
)) {
if (depVersion.includes("workspace:")) {
delete currentPackageJson.devDependencies[depName];
}
/**
* Convert workspace dev dependencies to install latest as they are only used for testing
*/
const workspaceDependencies = [
...Object.entries(currentPackageJson.devDependencies),
...Object.entries(currentPackageJson.dependencies),
].filter(([, depVersion]) => depVersion.includes("workspace:"));

for (const [depName, depVersion] of workspaceDependencies) {
/**
* for the peer dependency @langchain/core, we want to make sure to install min version
* defined above
*/
if (depName === "@langchain/core") {
delete currentPackageJson.devDependencies[depName];
continue;
}
}

if (currentPackageJson.dependencies) {
for (const [depName, depVersion] of Object.entries(
currentPackageJson.dependencies
)) {
if (depVersion.includes("workspace:")) {
// Convert workspace dependencies to peer dependencies
if (!currentPackageJson.peerDependencies) {
currentPackageJson.peerDependencies = {};
}
currentPackageJson.peerDependencies[depName] = "*";
delete currentPackageJson.dependencies[depName];
}
}
}

if (
currentPackageJson.peerDependencies?.["@langchain/openai"] &&
!currentPackageJson.peerDependencies["@langchain/openai"].includes("rc") &&
currentPackageJson.peerDependencies["@langchain/openai"] !== "*"
) {
const minVersion = semver.minVersion(
currentPackageJson.peerDependencies["@langchain/openai"]
).version;
currentPackageJson.peerDependencies = {
...currentPackageJson.peerDependencies,
"@langchain/openai": minVersion,
};
const libName = depName.split("/")[1];
/**
* reference the workspace dependency as a file path
*/
currentPackageJson.devDependencies[
depName
] = `file:/libs/langchain-${libName}`;
/**
* ensure that peer dependencies are also installed from the file path
* e.g. @langchain/openai depends on @langchain/core which should be resolved from the file path
*/
currentPackageJson.pnpm.overrides[
depName
] = `file:/libs/langchain-${libName}`;
}

if (
currentPackageJson.peerDependencies?.["@langchain/textsplitters"] &&
!currentPackageJson.peerDependencies["@langchain/textsplitters"].includes(
"rc"
) &&
currentPackageJson.peerDependencies["@langchain/textsplitters"] !== "*"
) {
const minVersion = semver.minVersion(
currentPackageJson.peerDependencies["@langchain/textsplitters"]
).version;
currentPackageJson.peerDependencies = {
...currentPackageJson.peerDependencies,
"@langchain/textsplitters": minVersion,
};
}

// Stupid hack
currentPackageJson.resolutions = {
...currentPackageJson.resolutions,
jackspeak: "2.1.1",
};

fs.writeFileSync(
communityPackageJsonPath,
JSON.stringify(currentPackageJson, null, 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set -euxo pipefail
corepack enable

export CI=true
export LC_DEPENDENCY_RANGE_TESTS=true

# enable extended globbing for omitting build artifacts
shopt -s extglob
Expand All @@ -16,16 +17,11 @@ mkdir -p /updater_script
cp -r /scripts/langchain/node/!(node_modules|dist|dist-cjs|dist-esm|build|.next|.turbo) /updater_script/

cd /updater_script

pnpm install --prod
npm install

cd /app

corepack enable
node /updater_script/update_resolutions_latest.js

pnpm install
pnpm add @langchain/core

# Check the test command completes successfully
pnpm run test
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set -euxo pipefail
corepack enable

export CI=true
export LC_DEPENDENCY_RANGE_TESTS=true

# enable extended globbing for omitting build artifacts
shopt -s extglob
Expand All @@ -16,18 +17,11 @@ mkdir -p /updater_script
cp -r /scripts/langchain/node/!(node_modules|dist|dist-cjs|dist-esm|build|.next|.turbo) /updater_script/

cd /updater_script

pnpm install --prod
npm install

cd /app

node /updater_script/update_resolutions_lowest.js

# Read the @langchain/core version from peerDependencies
core_version=$(node -p "require('./package.json').peerDependencies?.['@langchain/core']")

pnpm install
pnpm add @langchain/core@$core_version

# Check the test command completes successfully
pnpm run test
8 changes: 8 additions & 0 deletions environment_tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ services:
- ../environment_tests/scripts:/scripts
- ../libs/langchain:/langchain
- ../libs/langchain-core:/langchain-core
- ../libs/langchain-agents:/langchain-agents
- ../libs/langchain-community:/langchain-community
- ../libs/providers/langchain-anthropic:/langchain-anthropic
- ../libs/providers/langchain-openai:/langchain-openai
Expand All @@ -36,6 +37,7 @@ services:
- ../environment_tests/scripts:/scripts
- ../libs/langchain:/langchain
- ../libs/langchain-core:/langchain-core
- ../libs/langchain-agents:/langchain-agents
- ../libs/langchain-community:/langchain-community
- ../libs/providers/langchain-anthropic:/langchain-anthropic
- ../libs/providers/langchain-openai:/langchain-openai
Expand All @@ -60,6 +62,7 @@ services:
- ../environment_tests/scripts:/scripts
- ../libs/langchain:/langchain
- ../libs/langchain-core:/langchain-core
- ../libs/langchain-agents:/langchain-agents
- ../libs/langchain-community:/langchain-community
- ../libs/providers/langchain-anthropic:/langchain-anthropic
- ../libs/providers/langchain-openai:/langchain-openai
Expand All @@ -84,6 +87,7 @@ services:
- ../environment_tests/scripts:/scripts
- ../libs/langchain:/langchain
- ../libs/langchain-core:/langchain-core
- ../libs/langchain-agents:/langchain-agents
- ../libs/langchain-community:/langchain-community
- ../libs/providers/langchain-anthropic:/langchain-anthropic
- ../libs/providers/langchain-openai:/langchain-openai
Expand All @@ -108,6 +112,7 @@ services:
- ../environment_tests/scripts:/scripts
- ../libs/langchain:/langchain
- ../libs/langchain-core:/langchain-core
- ../libs/langchain-agents:/langchain-agents
- ../libs/langchain-community:/langchain-community
- ../libs/providers/langchain-anthropic:/langchain-anthropic
- ../libs/providers/langchain-openai:/langchain-openai
Expand All @@ -132,6 +137,7 @@ services:
- ../environment_tests/scripts:/scripts
- ../libs/langchain:/langchain
- ../libs/langchain-core:/langchain-core
- ../libs/langchain-agents:/langchain-agents
- ../libs/langchain-community:/langchain-community
- ../libs/providers/langchain-anthropic:/langchain-anthropic
- ../libs/providers/langchain-openai:/langchain-openai
Expand All @@ -156,6 +162,7 @@ services:
- ../environment_tests/scripts:/scripts
- ../libs/langchain:/langchain
- ../libs/langchain-core:/langchain-core
- ../libs/langchain-agents:/langchain-agents
- ../libs/langchain-community:/langchain-community
- ../libs/providers/langchain-anthropic:/langchain-anthropic
- ../libs/providers/langchain-openai:/langchain-openai
Expand All @@ -177,6 +184,7 @@ services:
- ../environment_tests/scripts:/scripts
- ../libs/langchain:/langchain
- ../libs/langchain-core:/langchain-core
- ../libs/langchain-agents:/langchain-agents
- ../libs/langchain-community:/langchain-community
- ../libs/providers/langchain-anthropic:/langchain-anthropic
- ../libs/providers/langchain-openai:/langchain-openai
Expand Down
Binary file removed examples/.yarn/install-state.gz
Binary file not shown.
1 change: 1 addition & 0 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"@langchain/qdrant": "workspace:*",
"@langchain/redis": "workspace:*",
"@langchain/scripts": ">=0.1.0 <0.2.0",
"@langchain/tavily": "workspace:*",
"@langchain/textsplitters": "workspace:*",
"@langchain/weaviate": "workspace:*",
"@langchain/xai": "workspace:*",
Expand Down
5 changes: 2 additions & 3 deletions examples/src/chat/agent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @ts-expect-error - createReactAgent is not yet available
import { createReactAgent } from "langchain";
import { createReactAgent, HumanMessage } from "langchain";
import { pull } from "langchain/hub";
import type { PromptTemplate } from "@langchain/core/prompts";

Expand Down Expand Up @@ -33,7 +32,7 @@ export const run = async () => {
});

const result = await agent.invoke({
input: "what is LangChain?",
messages: [new HumanMessage("what is LangChain?")],
});

console.log(result);
Expand Down
Loading
Loading