You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: core-jdk8/src/site/markdown/concepts/low_level.md
+19-18
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,11 @@
4
4
5
5
At its core, LangGraph4j models agent workflows as graphs. You define the behavior of your agents using three key components:
6
6
7
-
1.[`State`](#state): A shared data structure that represents the current snapshot of your application. It is represented by an [`AgentState`] object.
7
+
1.[`State`](#State): A shared data structure that represents the current snapshot of your application. It is represented by an [`AgentState`] object.
8
8
9
-
2.[`Nodes`](#nodes): A **Functional Interface** ([`AsyncNodeAction`]) that encode the logic of your agents. They receive the current `State` as input, perform some computation or side-effect, and return an updated `State`.
9
+
2.[`Nodes`](#Nodes): A **Functional Interface** ([`AsyncNodeAction`]) that encode the logic of your agents. They receive the current `State` as input, perform some computation or side-effect, and return an updated `State`.
10
10
11
-
3.[`Edges`](#edges): A **Functional Interface** ([`AsyncEdgeAction`]) that determine which `Node` to execute next based on the current `State`. They can be conditional branches or fixed transitions.
11
+
3.[`Edges`](#Edges): A **Functional Interface** ([`AsyncEdgeAction`]) that determine which `Node` to execute next based on the current `State`. They can be conditional branches or fixed transitions.
12
12
13
13
By composing `Nodes` and `Edges`, you can create complex, looping workflows that evolve the `State` over time. The real power, though, comes from how LangGraph4j manages that `State`.
14
14
To emphasize: `Nodes` and `Edges` are like functions - they can contain an LLM or just Java code.
@@ -30,11 +30,12 @@ The [`StateGraph`] class is the main graph class to uses. This is parameterized
30
30
31
31
The `MessageGraph` class is a special type of graph. The `State` of a `MessageGraph` is ONLY an array of messages. This class is rarely used except for chatbots, as most applications require the `State` to be more complex than an array of messages.
32
32
-->
33
+
<aid="compiling-your-graph"></a>
33
34
### Compiling your graph
34
35
35
-
To build your graph, you first define the [state](#state), you then add [nodes](#nodes) and [edges](#edges), and then you compile it. What exactly is compiling your graph and why is it needed?
36
+
To build your graph, you first define the [state](#State), you then add [nodes](#Nodes) and [edges](#Edges), and then you compile it. What exactly is compiling your graph and why is it needed?
36
37
37
-
Compiling is a pretty simple step. It provides a few basic checks on the structure of your graph (no orphaned nodes, etc). It is also where you can specify runtime args like [checkpointers](#checkpointer) and [breakpoints](#breakpoints). You compile your graph by just calling the `.compile` method:
38
+
Compiling is a pretty simple step. It provides a few basic checks on the structure of your graph (no orphaned nodes, etc). It is also where you can specify runtime args like [checkpointers](#Checkpointer) and [breakpoints](#Breakpoints). You compile your graph by just calling the `.compile` method:
38
39
39
40
```java
40
41
// compile your graph
@@ -45,7 +46,7 @@ You **MUST** compile your graph before you can use it.
45
46
46
47
## State
47
48
48
-
The first thing you do when you define a graph is define the `State` of the graph. The `State` consists of the [schema of the graph](#schema) as well as [`reducer`](#reducers) functions which specify how to apply updates to the state. The schema of the `State` will be the input schema to all `Nodes` and `Edges` in the graph, and should be defined using a map of [`Channel`] object. All `Nodes` will emit updates to the `State` which are then applied using the specified `reducer` function.
49
+
The first thing you do when you define a graph is define the `State` of the graph. The `State` consists of the [schema of the graph](#Schema) as well as [`reducer`](#Reducers) functions which specify how to apply updates to the state. The schema of the `State` will be the input schema to all `Nodes` and `Edges` in the graph, and should be defined using a map of [`Channel`] object. All `Nodes` will emit updates to the `State` which are then applied using the specified `reducer` function.
49
50
50
51
### Schema
51
52
@@ -110,9 +111,9 @@ Currently the main class for state's serialization using built-in java stream is
110
111
## Nodes
111
112
112
113
<!--
113
-
In LangGraph4j, nodes are typically a **Functional Interface** ([`AsyncNodeAction`]) where the argument is the [state](#state), and (optionally), the **second** positional argument is a "config", containing optional [configurable parameters](#configuration) (such as a `thread_id`).
114
+
In LangGraph4j, nodes are typically a **Functional Interface** ([`AsyncNodeAction`]) where the argument is the [state](#tate), and (optionally), the **second** positional argument is a "config", containing optional [configurable parameters](#configuration) (such as a `thread_id`).
114
115
-->
115
-
In LangGraph4j, nodes are typically a **Functional Interface** ([`AsyncNodeAction`]) where the argument is the [state](#state), you add these nodes to a graph using the [`addNode`] method:
116
+
In LangGraph4j, nodes are typically a **Functional Interface** ([`AsyncNodeAction`]) where the argument is the [state](#State), you add these nodes to a graph using the [`addNode`] method:
@@ -145,6 +146,7 @@ var builder = new StateGraph( State::new )
145
146
146
147
Since [`AsyncNodeAction`] is designed to work with [`CompletableFuture`], you can use `node_async` static method that adapt it to a simpler syncronous scenario.
147
148
149
+
<a id="start-node"></a>
148
150
### `START` Node
149
151
150
152
The `START` Node is a special node that represents the node sends user input to the graph. The main purpose for referencing this node is to determine which nodes should be called first.
The `END` Node is a special node that represents a terminal node. This node is referenced when you want to denote which edges have no actions after they are done.
@@ -181,6 +183,7 @@ Edges define how the logic is routed and how the graph decides to stop. This is
181
183
<!-- 👉 PARALLEL
182
184
A node can have MULTIPLE outgoing edges. If a node has multiple out-going edges, **all** of those destination nodes will be executed in parallel as a part of the next superstep. -->
183
185
186
+
<a id="normal-edges"></a>
184
187
### NormalEdges
185
188
186
189
If you **always** want to go from node A to node B, you can use the [addEdge](/langgraphjs/reference/classes/langgraph.StateGraph.html#addEdge) method directly.
@@ -190,6 +193,7 @@ If you **always** want to go from node A to node B, you can use the [addEdge](/l
190
193
graph.addEdge("nodeA", "nodeB");
191
194
```
192
195
196
+
<a id="conditional-edges"></a>
193
197
### ConditionalEdges
194
198
195
199
If you want to **optionally** route to 1 or more edges (or optionally terminate), you can use the [`addConditionalEdges`] method. This method accepts the name of a node and a **FunctionalInterface** ([`AsyncEdgeAction`]) that will be used as " routing function" to call after that node is executed:
@@ -206,6 +210,7 @@ Similar to nodes, the `routingFunction` accept the current `state` of the graph
206
210
207
211
You must provide an object that maps the `routingFunction`'s output to the name of the next node.
208
212
213
+
<a id="entry-point"></a>
209
214
### Entry Point
210
215
211
216
The entry point is the first node(s) that are run when the graph starts. You can use the [`addEdge`] method from the virtual `START` node to the first node to execute to specify where to enter the graph.
A conditional entry point lets you start at different nodes depending on custom logic. You can use [`addConditionalEdges`] from the virtual `START` node to accomplish this.
@@ -275,7 +280,7 @@ See [this guide](../../how-tos/persistence.html) for how to use threads.
275
280
<a id="checkpointer-state"></a>
276
281
## Checkpointer state
277
282
278
-
When interacting with the checkpointer state, you must specify a [thread identifier](#threads). Each checkpoint saved by the checkpointer has two properties:
283
+
When interacting with the checkpointer state, you must specify a [thread identifier](#Threads). Each checkpoint saved by the checkpointer has two properties:
279
284
280
285
- **state**: This is the value of the state at this point in time.
281
286
- **nextNodeId**: This is the Idenfier of the node to execute next in the graph.
@@ -306,7 +311,7 @@ The config should contain `thread_id` specifying which thread to update.
306
311
307
312
**`values`**
308
313
309
-
These are the values that will be used to update the state. Note that this update is treated exactly as any update from a node is treated. This means that these values will be passed to the [reducer](#reducers) functions that are part of the state. So this does NOT automatically overwrite the state.
314
+
These are the values that will be used to update the state. Note that this update is treated exactly as any update from a node is treated. This means that these values will be passed to the [reducer](#Reducers) functions that are part of the state. So this does NOT automatically overwrite the state.
310
315
311
316
**`asNode`**
312
317
@@ -351,7 +356,7 @@ See [this guide](../how-tos/configuration.html) for a full breakdown on configur
351
356
352
357
It can often be useful to set breakpoints before or after certain nodes execute. This can be used to wait for human approval before continuing. These can be set when you ["compile" a graph](#compiling-your-graph). You can set breakpoints either _before_ a node executes (using `interruptBefore`) or after a node executes (using `interruptAfter`.)
353
358
354
-
You **MUST** use a [checkpoiner](#checkpointer) when using breakpoints. This is because your graph needs to be able to resume execution.
359
+
You **MUST** use a [checkpoiner](#Checkpointer) when using breakpoints. This is because your graph needs to be able to resume execution.
355
360
356
361
In order to resume execution, you can just invoke your graph with `null` as the input.
LangGraph4j is built with first class support for streaming. it uses [java-async-generator] library to help with this.
387
-
388
389
<!--
389
390
There are several different streaming modes that LangGraph4j supports:
390
391
@@ -393,7 +394,7 @@ There are several different streaming modes that LangGraph4j supports:
393
394
394
395
In addition, you can use the [`streamEvents`](https://v02.api.js.langchain.com/classes/langchain_core_runnables.Runnable.html#streamEvents) method to stream back events that happen _inside_ nodes. This is useful for [streaming tokens of LLM calls](../how-tos/streaming-tokens-without-langchain.html). -->
0 commit comments