|
15 | 15 | ```xml
|
16 | 16 | <dependency>
|
17 | 17 | <groupId>org.bsc.langgraph4j</groupId>
|
18 |
| - <artifactId>langgraph4j</artifactId> |
| 18 | + <artifactId>langgraph4j-jdk8</artifactId> |
19 | 19 | <version>1.0-SNAPSHOT</version>
|
20 |
| - <classifier>jdk8<classifier> |
21 | 20 | <dependency>
|
22 | 21 | ```
|
23 | 22 |
|
24 | 23 | **JDK17 compliant**
|
25 |
| -```xml |
26 |
| -<dependency> |
27 |
| - <groupId>org.bsc.langgraph4j</groupId> |
28 |
| - <artifactId>langgraph4j</artifactId> |
29 |
| - <version>1.0-SNAPSHOT</version> |
30 |
| - <classifier>jdk17<classifier> |
31 |
| -<dependency> |
32 |
| -``` |
| 24 | +> _work in progress_ |
| 25 | +
|
33 | 26 |
|
34 | 27 | ### Define the agent state
|
35 | 28 |
|
36 |
| -The main type of graph in `langgraph` is the `StatefulGraph`. This graph is parameterized by a state object that it passes around to each node. Each node then returns operations to update that state. These operations can either SET specific attributes on the state (e.g. overwrite the existing values) or ADD to the existing attribute. Whether to set or add is denoted by initialize the property with a `AppendableValue`. The State must be compliant with `AgentState` interface that essentially is a `Map` wrapper. |
| 29 | +The main type of graph in `langgraph` is the `StatefulGraph`. This graph is parameterized by a state object that it passes around to each node. |
| 30 | +Each node then returns operations to update that state. These operations can either SET specific attributes on the state (e.g. overwrite the existing values) or ADD to the existing attribute. |
| 31 | +Whether to set or add is denoted by initialize the property with a `AppendableValue`. The State must inherit from `AgentState` base class (that essentially is a `Map` wrapper). |
37 | 32 |
|
38 | 33 | ```java
|
39 |
| -public interface AgentState { |
| 34 | +public class AgentState { |
40 | 35 |
|
41 |
| - java.util.Map<String,Object> data(); |
| 36 | + public AgentState( Map<String,Object> initData ); |
| 37 | + |
| 38 | + public final java.util.Map<String,Object> data(); |
| 39 | + |
| 40 | + public final <T> Optional<T> value(String key); |
| 41 | + |
| 42 | + public final <T> AppendableValue<T> appendableValue(String key ); |
42 | 43 |
|
43 | 44 | }
|
44 | 45 | ```
|
@@ -73,22 +74,22 @@ Below you can find a piece of code of the `AgentExecutor` to give you an idea of
|
73 | 74 |
|
74 | 75 | public static class State implements AgentState {
|
75 | 76 |
|
76 |
| - private final Map<String,Object> data; |
77 |
| - |
78 |
| - public State( Map<String,Object> initData ) { |
79 |
| - this.data = new HashMap<>(initData); |
80 |
| - this.data.putIfAbsent("intermediate_steps", |
81 |
| - new AppendableValue<IntermediateStep>()); |
82 |
| - } |
83 |
| - |
84 |
| - public Map<String,Object> data() { return Map.copyOf(data); } |
85 |
| - |
86 |
| - Optional<String> input() { return value("input"); } |
87 |
| - Optional<AgentOutcome> agentOutcome() { return value("agent_outcome"); } |
88 |
| - Optional<List<IntermediateStep>> intermediateSteps() { return appendableValue("intermediate_steps"); } |
| 77 | + public State(Map<String, Object> initData) { |
| 78 | + super(initData); |
| 79 | + } |
| 80 | + |
| 81 | + Optional<String> input() { |
| 82 | + return value("input"); |
| 83 | + } |
| 84 | + Optional<AgentOutcome> agentOutcome() { |
| 85 | + return value("agent_outcome"); |
| 86 | + } |
| 87 | + AppendableValue<IntermediateStep> intermediateSteps() { |
| 88 | + return appendableValue("intermediate_steps"); |
| 89 | + } |
| 90 | + |
89 | 91 | }
|
90 | 92 |
|
91 |
| - |
92 | 93 | var toolInfoList = ToolInfo.fromList( objectsWithTools );
|
93 | 94 |
|
94 | 95 | final List<ToolSpecification> toolSpecifications = toolInfoList.stream()
|
@@ -130,6 +131,10 @@ var app = workflow.compile();
|
130 | 131 | return app.stream( inputs );
|
131 | 132 |
|
132 | 133 | ```
|
| 134 | +## Samples |
| 135 | + |
| 136 | +* [Agent Executor](agents-jdk8/src/main/java/dev/langchain4j/agentexecutor) |
| 137 | +* [Image To PlantUML Diagram](agents-jdk8/src/main/java/dev/langchain4j/image_to_diagram) |
133 | 138 |
|
134 | 139 | # References
|
135 | 140 |
|
|
0 commit comments