Skip to content

Commit

Permalink
chore(pregel): add test for getGraph().toJSON() (#382)
Browse files Browse the repository at this point in the history
Co-authored-by: jacoblee93 <[email protected]>
  • Loading branch information
dqbd and jacoblee93 authored Aug 26, 2024
1 parent 2721e3f commit 002e68d
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 8 deletions.
3 changes: 2 additions & 1 deletion libs/langgraph/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@langchain/langgraph",
"version": "0.1.2",
"version": "0.1.1",
"description": "LangGraph",
"type": "module",
"engines": {
Expand Down Expand Up @@ -50,6 +50,7 @@
"@jest/globals": "^29.5.0",
"@langchain/anthropic": "^0.2.12",
"@langchain/community": "^0.2.25",
"@langchain/core": "^0.2.29",
"@langchain/openai": "^0.2.4",
"@langchain/scripts": ">=0.1.2 <0.2.0",
"@swc/core": "^1.3.90",
Expand Down
141 changes: 141 additions & 0 deletions libs/langgraph/src/tests/pregel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3399,6 +3399,59 @@ describe("MessageGraph", () => {
.addEdge("action", "agent")
.compile();

expect(app.getGraph().toJSON()).toMatchObject({
nodes: expect.arrayContaining([
{
id: "__start__",
type: "schema",
data: {
$schema: "http://json-schema.org/draft-07/schema#",
title: undefined,
},
},
{
id: "agent",
type: "runnable",
data: {
id: ["langchain", "chat_models", "fake", "FakeChatModel"],
name: "FakeChatModel",
},
},
{
id: "action",
type: "runnable",
data: {
id: ["langchain_core", "runnables", "RunnableLambda"],
name: "RunnableLambda",
},
},
{
id: "__end__",
type: "schema",
data: {
$schema: "http://json-schema.org/draft-07/schema#",
title: undefined,
},
},
]),
edges: expect.arrayContaining([
{ source: "__start__", target: "agent" },
{ source: "action", target: "agent" },
{
source: "agent",
target: "action",
data: "continue",
conditional: true,
},
{
source: "agent",
target: "__end__",
data: "end",
conditional: true,
},
]),
});

const result = await app.invoke(
new HumanMessage("what is the weather in sf?")
);
Expand Down Expand Up @@ -3509,6 +3562,45 @@ describe("MessageGraph", () => {
.addEdge("action", "agent")
.compile();

expect(app.getGraph().toJSON()).toMatchObject({
nodes: expect.arrayContaining([
expect.objectContaining({ id: "__start__", type: "schema" }),
expect.objectContaining({ id: "__end__", type: "schema" }),
{
id: "agent",
type: "runnable",
data: {
id: ["langchain", "chat_models", "fake", "FakeChatModel"],
name: "FakeChatModel",
},
},
{
id: "action",
type: "runnable",
data: {
id: ["langchain_core", "runnables", "RunnableLambda"],
name: "RunnableLambda",
},
},
]),
edges: expect.arrayContaining([
{ source: "__start__", target: "agent" },
{ source: "action", target: "agent" },
{
source: "agent",
target: "action",
data: "continue",
conditional: true,
},
{
source: "agent",
target: "__end__",
data: "end",
conditional: true,
},
]),
});

const stream = await app.stream([
new HumanMessage("what is the weather in sf?"),
]);
Expand Down Expand Up @@ -4087,6 +4179,55 @@ it("StateGraph branch then node", async () => {

const tool = toolBuilder.compile();

expect(tool.getGraph().toJSON()).toMatchObject({
nodes: expect.arrayContaining([
expect.objectContaining({ id: "__start__", type: "schema" }),
expect.objectContaining({ id: "__end__", type: "schema" }),
{
id: "prepare",
type: "runnable",
data: {
id: ["langchain_core", "runnables", "RunnableLambda"],
name: "RunnableLambda",
},
},
{
id: "tool_two_slow",
type: "runnable",
data: {
id: ["langchain_core", "runnables", "RunnableLambda"],
name: "RunnableLambda",
},
},
{
id: "tool_two_fast",
type: "runnable",
data: {
id: ["langchain_core", "runnables", "RunnableLambda"],
name: "RunnableLambda",
},
},
{
id: "finish",
type: "runnable",
data: {
id: ["langchain_core", "runnables", "RunnableLambda"],
name: "RunnableLambda",
},
},
]),
edges: expect.arrayContaining([
{ source: "__start__", target: "prepare" },
{ source: "tool_two_fast", target: "finish" },
{ source: "tool_two_slow", target: "finish" },
{ source: "finish", target: "__end__" },
{ source: "prepare", target: "tool_two_slow", conditional: true },
{ source: "prepare", target: "tool_two_fast", conditional: true },
{ source: "prepare", target: "finish", conditional: true },
{ source: "prepare", target: "__end__", conditional: true },
]),
});

expect(await tool.invoke({ my_key: "value", market: "DE" })).toEqual({
my_key: "value prepared slow finished",
market: "DE",
Expand Down
39 changes: 32 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1841,21 +1841,21 @@ __metadata:
linkType: hard

"@langchain/core@npm:latest":
version: 0.2.27
resolution: "@langchain/core@npm:0.2.27"
version: 0.2.29
resolution: "@langchain/core@npm:0.2.29"
dependencies:
ansi-styles: ^5.0.0
camelcase: 6
decamelize: 1.2.0
js-tiktoken: ^1.0.12
langsmith: ~0.1.39
langsmith: ^0.1.43
mustache: ^4.2.0
p-queue: ^6.6.2
p-retry: 4
uuid: ^10.0.0
zod: ^3.22.4
zod-to-json-schema: ^3.22.3
checksum: 188ab834a0a9f4462b81d38b92be61df91d87392b2bd86fb21d5cfe253c080700d09ffd954c90726704fc5fe6c0f06cb2f5bd7705f17632819473c9d8ed57b39
checksum: 8c42017d567595866ddc57421f2d7b6dca0e42becf992ae92f1b2715667f0455ade90ebeb11dff9e739080ca5b49776013b2b2e55a16502bf42041d5f91388ce
languageName: node
linkType: hard

Expand Down Expand Up @@ -1993,7 +1993,7 @@ __metadata:
"@jest/globals": ^29.5.0
"@langchain/anthropic": ^0.2.12
"@langchain/community": ^0.2.25
"@langchain/core": ">=0.2.20 <0.3.0"
"@langchain/core": ^0.2.29
"@langchain/langgraph-checkpoint": ~0.0.2
"@langchain/langgraph-checkpoint-sqlite": ~0.0.1
"@langchain/openai": ^0.2.4
Expand Down Expand Up @@ -3329,7 +3329,7 @@ __metadata:
languageName: node
linkType: hard

"@types/uuid@npm:^10":
"@types/uuid@npm:^10, @types/uuid@npm:^10.0.0":
version: 10.0.0
resolution: "@types/uuid@npm:10.0.0"
checksum: e3958f8b0fe551c86c14431f5940c3470127293280830684154b91dc7eb3514aeb79fe3216968833cf79d4d1c67f580f054b5be2cd562bebf4f728913e73e944
Expand Down Expand Up @@ -8954,7 +8954,32 @@ __metadata:
languageName: unknown
linkType: soft

"langsmith@npm:~0.1.30, langsmith@npm:~0.1.39":
"langsmith@npm:^0.1.43":
version: 0.1.47
resolution: "langsmith@npm:0.1.47"
dependencies:
"@types/uuid": ^10.0.0
commander: ^10.0.1
p-queue: ^6.6.2
p-retry: 4
semver: ^7.6.3
uuid: ^10.0.0
peerDependencies:
"@langchain/core": "*"
langchain: "*"
openai: "*"
peerDependenciesMeta:
"@langchain/core":
optional: true
langchain:
optional: true
openai:
optional: true
checksum: 52b663619f4bec5c935555ce3fc25b413c2670b696ec715f0d3fdcfcf5a444332acdd6729c7f34579e57201802d1d6d23811a5202fa03a1d4da7fe2ba8782335
languageName: node
linkType: hard

"langsmith@npm:~0.1.30":
version: 0.1.39
resolution: "langsmith@npm:0.1.39"
dependencies:
Expand Down

0 comments on commit 002e68d

Please sign in to comment.