Skip to content

Commit

Permalink
Remove deprecated method in examples (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 committed Jun 14, 2024
1 parent 9f0d6ff commit 5fbdcd1
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 41 deletions.
4 changes: 2 additions & 2 deletions examples/agent_executor/base.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
"outputs": [],
"source": [
"import { RunnableLambda } from \"@langchain/core/runnables\";\n",
"import { END, StateGraph } from \"@langchain/langgraph\";\n",
"import { START, END, StateGraph } from \"@langchain/langgraph\";\n",
"\n",
"// Define a new graph\n",
"const workflow = new StateGraph({\n",
Expand All @@ -267,7 +267,7 @@
"\n",
"// Set the entrypoint as `agent`\n",
"// This means that this node is the first one called\n",
"workflow.setEntryPoint(\"agent\");\n",
"workflow.addEdge(START, \"agent\");\n",
"\n",
"// We now add a conditional edge\n",
"workflow.addConditionalEdges(\n",
Expand Down
4 changes: 2 additions & 2 deletions examples/chat_agent_executor_with_function_calling/base.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@
"metadata": {},
"outputs": [],
"source": [
"import { END, StateGraph } from \"@langchain/langgraph\";\n",
"import { START, END, StateGraph } from \"@langchain/langgraph\";\n",
"\n",
"// Define a new graph\n",
"const workflow = new StateGraph({\n",
Expand All @@ -366,7 +366,7 @@
"\n",
"// Set the entrypoint as `agent`\n",
"// This means that this node is the first one called\n",
"workflow.setEntryPoint(\"agent\");\n",
"workflow.addEdge(START, \"agent\");\n",
"\n",
"// We now add a conditional edge\n",
"workflow.addConditionalEdges(\n",
Expand Down
3 changes: 2 additions & 1 deletion examples/chatbots/customer_support_mistral.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
"source": [
"import { MessagesPlaceholder } from \"@langchain/core/prompts\";\n",
"import type { BaseMessage } from \"@langchain/core/messages\";\n",
"import { START } from \"@langchain/langgraph\";\n",
"\n",
"graph.addNode(\"initial_support\", async (state: BaseMessage[]) => {\n",
" const SYSTEM_TEMPLATE =\n",
Expand All @@ -167,7 +168,7 @@
" return prompt.pipe(model).invoke({ messages: state });\n",
"});\n",
"\n",
"graph.setEntryPoint(\"initial_support\");"
"graph.addEdge(START, \"initial_support\");"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions examples/rag/langgraph_crag_mistral.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@
"metadata": {},
"outputs": [],
"source": [
"import { END, StateGraph } from \"@langchain/langgraph\";\n",
"import { START, END, StateGraph } from \"@langchain/langgraph\";\n",
"\n",
"const workflow = new StateGraph<GraphState>({\n",
" channels: graphState,\n",
Expand All @@ -608,7 +608,7 @@
"workflow.addNode(\"webSearch\", webSearch);\n",
"\n",
"// Build graph\n",
"workflow.setEntryPoint(\"retrieve\");\n",
"workflow.addEdge(START, \"retrieve\");\n",
"workflow.addEdge(\"retrieve\", \"gradeDocuments\");\n",
"workflow.addConditionalEdges(\n",
" \"gradeDocuments\",\n",
Expand Down
39 changes: 11 additions & 28 deletions langgraph/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ And now we're ready! The graph below contains a single node called `"oracle"` th
```ts
import { ChatOpenAI } from "@langchain/openai";
import { HumanMessage, BaseMessage, } from "@langchain/core/messages";
import { END, MessageGraph } from "@langchain/langgraph";
import { START, END, MessageGraph } from "@langchain/langgraph";

const model = new ChatOpenAI({ temperature: 0 });

Expand All @@ -58,7 +58,7 @@ graph.addNode("oracle", async (state: BaseMessage[]) => {

graph.addEdge("oracle", END);

graph.setEntryPoint("oracle");
graph.addEdge(START, "oracle");

const runnable = graph.compile();
```
Expand Down Expand Up @@ -90,7 +90,7 @@ So what did we do here? Let's break it down step by step:
1. First, we initialize our model and a `MessageGraph`.
2. Next, we add a single node to the graph, called `"oracle"`, which simply calls the model with the given input.
3. We add an edge from this `"oracle"` node to the special value `END`. This means that execution will end after current node.
4. We set `"oracle"` as the entrypoint to the graph.
4. We set `"oracle"` as the entrypoint to the graph by adding an edge from the special `START` value to it.
5. We compile the graph, ensuring that no more modifications to it can be made.

Then, when we execute the graph:
Expand Down Expand Up @@ -185,7 +185,7 @@ graph.addNode("calculator", async (state: BaseMessage[]) => {

graph.addEdge("calculator", END);

graph.setEntryPoint("oracle");
graph.addEdge(START, "oracle");
```

Now let's think - what do we want to have happen?
Expand Down Expand Up @@ -477,7 +477,7 @@ const callTool = async (
We can now put it all together and define the graph!

```typescript
import { StateGraph, END } from "@langchain/langgraph";
import { StateGraph, START, END } from "@langchain/langgraph";
import { RunnableLambda } from "@langchain/core/runnables";

// Define a new graph
Expand All @@ -491,7 +491,7 @@ workflow.addNode("action", callTool);

// Set the entrypoint as `agent`
// This means that this node is the first one called
workflow.setEntryPoint("agent");
workflow.addEdge(START, "agent");

// We now add a conditional edge
workflow.addConditionalEdges(
Expand Down Expand Up @@ -723,31 +723,14 @@ This takes three arguments:
- `condition`: A function to call to decide what to do next. The input will be the output of the start node. It should return a string that is present in `conditionalEdgeMapping` and represents the edge to take.
- `conditionalEdgeMapping`: A mapping of string to string. The keys should be strings that may be returned by `condition`. The values should be the downstream node to call if that condition is returned.
### `.setEntryPoint`
### `START`
```typescript
setEntryPoint(key: string): void
import { START } from "@langchain/langgraph";
```
The entrypoint to the graph.
This is the node that is first called.
It only takes one argument:
- `key`: The name of the node that should be called first.
### `.setFinishPoint`
```typescript
setFinishPoint(key: string): void
```
This is the exit point of the graph.
When this node is called, the results will be the final result from the graph.
It only has one argument:
- `key`: The name of the node that, when called, will return the results of calling it as the final output
Note: This does not need to be called if at any point you previously created an edge (conditional or normal) to `END`
This is a special node representing the start of the graph.
This means that anything with an edge from this node will be the entrypoint of the graph.
### `END`
Expand Down Expand Up @@ -827,7 +810,7 @@ workflow.addNode("agent", agent);
workflow.addNode("tools", executeTools);

// We now set the entry point to be this first agent
workflow.setEntryPoint("firstAgent");
workflow.addEdge(START, "firstAgent");

// We define the same edges as before
workflow.addConditionalEdges("agent", shouldContinue, {
Expand Down
2 changes: 1 addition & 1 deletion langgraph/src/tests/chatbot.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("Chatbot", () => {
const graph = new MessageGraph()
.addNode("oracle", async (state: BaseMessage[]) => model.invoke(state))
.addEdge("oracle", END)
.setEntryPoint("oracle")
.addEdge(START, "oracle")
.compile();
const res = await graph.invoke(new HumanMessage("What is 1 + 1?"));

Expand Down
10 changes: 5 additions & 5 deletions langgraph/src/tests/tracing.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { z } from "zod";
import { ToolExecutor } from "../prebuilt/tool_executor.js";
import { createAgentExecutor } from "../prebuilt/agent_executor.js";
// Import from main `@langchain/langgraph` endpoint to turn on automatic config passing
import { StateGraph, END } from "../index.js";
import { StateGraph, END, START } from "../index.js";

test.skip("Can invoke with tracing", async () => {
const tools = [new TavilySearchResults({ maxResults: 1 })];
Expand Down Expand Up @@ -103,7 +103,7 @@ test.skip("Can invoke with tracing", async () => {
.addNode("action", new RunnableLambda({ func: executeTools }))
// Set the entrypoint as `agent`
// This means that this node is the first one called
.setEntryPoint("agent")
.addEdge(START, "agent")
// We now add a conditional edge
.addConditionalEdges(
// First, we define the start node. We use `agent`.
Expand Down Expand Up @@ -234,7 +234,7 @@ test.skip("Can nest an agent executor", async () => {
// Or end work if done
FINISH: END,
})
.setEntryPoint("supervisor");
.addEdge(START, "supervisor");

const graph = workflow.compile();

Expand Down Expand Up @@ -352,7 +352,7 @@ test.skip("Can nest a graph within a graph", async () => {
researcher: "researcher",
FINISH: END,
})
.setEntryPoint("supervisor");
.addEdge(START, "supervisor");

const graph = workflow.compile();

Expand Down Expand Up @@ -525,7 +525,7 @@ Only add steps to the plan that still NEED to be done. Do not return previously
.addNode("agent", executeStep)
// Add a replan node
.addNode("replan", replanStep)
.setEntryPoint("planner")
.addEdge(START, "planner")
// From plan we go to agent
.addEdge("planner", "agent")
// From agent, we replan
Expand Down

0 comments on commit 5fbdcd1

Please sign in to comment.