@langchain/core 0.2.13-rc.0 → 0.2.13-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/runnables/graph.cjs +1 -2
- package/dist/runnables/graph.d.ts +1 -1
- package/dist/runnables/graph.js +1 -1
- package/dist/runnables/tests/runnable_graph.test.js +75 -0
- package/package.json +14 -1
- package/runnables/graph.cjs +1 -0
- package/runnables/graph.d.cts +1 -0
- package/runnables/graph.d.ts +1 -0
- package/runnables/graph.js +1 -0
package/dist/runnables/graph.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Graph =
|
|
3
|
+
exports.Graph = void 0;
|
|
4
4
|
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
5
5
|
const uuid_1 = require("uuid");
|
|
6
6
|
const utils_js_1 = require("./utils.cjs");
|
|
@@ -27,7 +27,6 @@ function nodeDataStr(node) {
|
|
|
27
27
|
return node.data.name ?? "UnknownSchema";
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
exports.nodeDataStr = nodeDataStr;
|
|
31
30
|
function nodeDataJson(node) {
|
|
32
31
|
// if node.data is implements Runnable
|
|
33
32
|
if ((0, utils_js_1.isRunnableInterface)(node.data)) {
|
package/dist/runnables/graph.js
CHANGED
|
@@ -3,7 +3,7 @@ import { v4 as uuidv4, validate as isUuid } from "uuid";
|
|
|
3
3
|
import { isRunnableInterface } from "./utils.js";
|
|
4
4
|
import { drawMermaid, drawMermaidPng } from "./graph_mermaid.js";
|
|
5
5
|
const MAX_DATA_DISPLAY_NAME_LENGTH = 42;
|
|
6
|
-
|
|
6
|
+
function nodeDataStr(node) {
|
|
7
7
|
if (!isUuid(node.id)) {
|
|
8
8
|
return node.id;
|
|
9
9
|
}
|
|
@@ -4,6 +4,14 @@ import { StringOutputParser } from "../../output_parsers/string.js";
|
|
|
4
4
|
import { FakeLLM } from "../../utils/testing/index.js";
|
|
5
5
|
import { PromptTemplate } from "../../prompts/prompt.js";
|
|
6
6
|
import { CommaSeparatedListOutputParser } from "../../output_parsers/list.js";
|
|
7
|
+
// import { TavilySearchResults } from "@langchain/community/tools/tavily_search";
|
|
8
|
+
// import { ChatOpenAI } from "@langchain/openai";
|
|
9
|
+
// import { MemorySaver } from "@langchain/langgraph";
|
|
10
|
+
// // Define the tools for the agent to use
|
|
11
|
+
// import { HumanMessage } from "@langchain/core/messages";
|
|
12
|
+
// import { ToolNode } from "@langchain/langgraph/prebuilt";
|
|
13
|
+
// import { END, START, StateGraph, StateGraphArgs } from "@langchain/langgraph";
|
|
14
|
+
// import * as fs from "fs";
|
|
7
15
|
test("Test graph single runnable", async () => {
|
|
8
16
|
const jsonOutputParser = new StringOutputParser();
|
|
9
17
|
const graph = jsonOutputParser.getGraph();
|
|
@@ -98,3 +106,70 @@ graph TD;
|
|
|
98
106
|
\tclassDef otherclass fill:#fad7de;
|
|
99
107
|
`);
|
|
100
108
|
});
|
|
109
|
+
// test.only("langgraph", async () => {
|
|
110
|
+
// // Define the state interface
|
|
111
|
+
// interface AgentState {
|
|
112
|
+
// messages: HumanMessage[];
|
|
113
|
+
// }
|
|
114
|
+
// // Define the graph state
|
|
115
|
+
// const graphState: StateGraphArgs<AgentState>["channels"] = {
|
|
116
|
+
// messages: {
|
|
117
|
+
// value: (x: HumanMessage[], y: HumanMessage[]) => x.concat(y),
|
|
118
|
+
// default: () => [],
|
|
119
|
+
// },
|
|
120
|
+
// };
|
|
121
|
+
// // Define the tools for the agent to use
|
|
122
|
+
// const tools = [new TavilySearchResults({ maxResults: 1 })];
|
|
123
|
+
// const toolNode = new ToolNode<AgentState>(tools);
|
|
124
|
+
// const model = new ChatOpenAI({ temperature: 0 }).bindTools(tools);
|
|
125
|
+
// // Define the function that determines whether to continue or not
|
|
126
|
+
// function shouldContinue(state: AgentState): "tools" | typeof END {
|
|
127
|
+
// const messages = state.messages;
|
|
128
|
+
// const lastMessage = messages[messages.length - 1];
|
|
129
|
+
// // If the LLM makes a tool call, then we route to the "tools" node
|
|
130
|
+
// if (lastMessage.additional_kwargs.tool_calls) {
|
|
131
|
+
// return "tools";
|
|
132
|
+
// }
|
|
133
|
+
// // Otherwise, we stop (reply to the user)
|
|
134
|
+
// return END;
|
|
135
|
+
// }
|
|
136
|
+
// // Define the function that calls the model
|
|
137
|
+
// async function callModel(state: AgentState) {
|
|
138
|
+
// const messages = state.messages;
|
|
139
|
+
// const response = await model.invoke(messages);
|
|
140
|
+
// // We return a list, because this will get added to the existing list
|
|
141
|
+
// return { messages: [response] };
|
|
142
|
+
// }
|
|
143
|
+
// // Define a new graph
|
|
144
|
+
// const workflow = new StateGraph<AgentState>({ channels: graphState })
|
|
145
|
+
// .addNode("agent", callModel)
|
|
146
|
+
// .addNode("tools", toolNode)
|
|
147
|
+
// .addEdge(START, "agent")
|
|
148
|
+
// .addConditionalEdges("agent", shouldContinue)
|
|
149
|
+
// .addEdge("tools", "agent");
|
|
150
|
+
// // Initialize memory to persist state between graph runs
|
|
151
|
+
// const checkpointer = new MemorySaver();
|
|
152
|
+
// // Finally, we compile it!
|
|
153
|
+
// // This compiles it into a LangChain Runnable.
|
|
154
|
+
// // Note that we're (optionally) passing the memory when compiling the graph
|
|
155
|
+
// const app = workflow.compile({ checkpointer });
|
|
156
|
+
// const graph = app.getGraph();
|
|
157
|
+
// const blob = await graph.drawMermaidPng();
|
|
158
|
+
// const arrayBuffer = await blob.arrayBuffer();
|
|
159
|
+
// fs.writeFileSync("/Users/jacoblee/langchain/langchainjs/langchain-core/src/runnables/tests/data/graph-mermaid.png", Buffer.from(arrayBuffer));
|
|
160
|
+
// // // Now it's time to use!
|
|
161
|
+
// // const agentFinalState = await agent.invoke(
|
|
162
|
+
// // { messages: [new HumanMessage("what is the weather in sf")] },
|
|
163
|
+
// // { configurable: { thread_id: "42" } },
|
|
164
|
+
// // );
|
|
165
|
+
// // console.log(
|
|
166
|
+
// // agentFinalState.messages[agentFinalState.messages.length - 1].content,
|
|
167
|
+
// // );
|
|
168
|
+
// // const agentNextState = await agent.invoke(
|
|
169
|
+
// // { messages: [new HumanMessage("what about ny")] },
|
|
170
|
+
// // { configurable: { thread_id: "42" } },
|
|
171
|
+
// // );
|
|
172
|
+
// // console.log(
|
|
173
|
+
// // agentNextState.messages[agentNextState.messages.length - 1].content,
|
|
174
|
+
// // );
|
|
175
|
+
// })
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/core",
|
|
3
|
-
"version": "0.2.13-rc.
|
|
3
|
+
"version": "0.2.13-rc.2",
|
|
4
4
|
"description": "Core LangChain.js abstractions and schemas",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -329,6 +329,15 @@
|
|
|
329
329
|
"import": "./runnables.js",
|
|
330
330
|
"require": "./runnables.cjs"
|
|
331
331
|
},
|
|
332
|
+
"./runnables/graph": {
|
|
333
|
+
"types": {
|
|
334
|
+
"import": "./runnables/graph.d.ts",
|
|
335
|
+
"require": "./runnables/graph.d.cts",
|
|
336
|
+
"default": "./runnables/graph.d.ts"
|
|
337
|
+
},
|
|
338
|
+
"import": "./runnables/graph.js",
|
|
339
|
+
"require": "./runnables/graph.cjs"
|
|
340
|
+
},
|
|
332
341
|
"./runnables/remote": {
|
|
333
342
|
"types": {
|
|
334
343
|
"import": "./runnables/remote.d.ts",
|
|
@@ -698,6 +707,10 @@
|
|
|
698
707
|
"runnables.js",
|
|
699
708
|
"runnables.d.ts",
|
|
700
709
|
"runnables.d.cts",
|
|
710
|
+
"runnables/graph.cjs",
|
|
711
|
+
"runnables/graph.js",
|
|
712
|
+
"runnables/graph.d.ts",
|
|
713
|
+
"runnables/graph.d.cts",
|
|
701
714
|
"runnables/remote.cjs",
|
|
702
715
|
"runnables/remote.js",
|
|
703
716
|
"runnables/remote.d.ts",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/runnables/graph.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/runnables/graph.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/runnables/graph.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/runnables/graph.js'
|