Skip to content

Commit

Permalink
Merge branch 'release/1.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Nov 26, 2024
2 parents ae15a93 + 3cff8a5 commit 381e9ec
Show file tree
Hide file tree
Showing 22 changed files with 302 additions and 55 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ LangGraph for Java. A library for building stateful, multi-agents applications w

| Date | Release | info
|--------------|----------------| ---
| Nov 26, 2024 | `1.1.0` | official release
| Nov 26, 2024 | `1.1.1` | official release


## Samples
Expand Down Expand Up @@ -69,7 +69,7 @@ LangGraph for Java. A library for building stateful, multi-agents applications w
<dependency>
<groupId>org.bsc.langgraph4j</groupId>
<artifactId>langgraph4j-core-jdk8</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion core-jdk8/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.bsc.langgraph4j</groupId>
<artifactId>langgraph4j-parent</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
</parent>

<artifactId>langgraph4j-core-jdk8</artifactId>
Expand Down
28 changes: 12 additions & 16 deletions core-jdk8/src/main/java/org/bsc/langgraph4j/CompiledGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public enum StreamMode {
}
final StateGraph<State> stateGraph;
@Getter
final Map<String, AsyncNodeAction<State>> nodes = new LinkedHashMap<>();
final Map<String, AsyncNodeActionWithConfig<State>> nodes = new LinkedHashMap<>();
@Getter
final Map<String, EdgeValue<State>> edges = new LinkedHashMap<>();

Expand Down Expand Up @@ -430,29 +430,25 @@ private Optional<Data<Output>> getEmbedGenerator( Map<String,Object> partialStat
.findFirst()
.map( e ->
Data.composeWith( (AsyncGenerator<Output>)e.getValue(), data -> {
if( !(data instanceof Map) ) {
throw new IllegalArgumentException("Embedded generator must return a Map");

if( data != null ) {

if (!(data instanceof Map)) {
throw new IllegalArgumentException("Embedded generator must return a Map");
}
currentState = AgentState.updateState(currentState, (Map<String, Object>) data, stateGraph.getChannels());
}
currentState = AgentState.updateState(currentState, (Map<String, Object>)data, stateGraph.getChannels());

nextNodeId = nextNodeId(currentNodeId, currentState);
resumedFromEmbed = true;
})
)
;
}

@SuppressWarnings("unchecked")
private CompletableFuture<Data<Output>> evaluateAction(AsyncNodeAction<State> action, State withState ) {

final CompletableFuture<Map<String,Object>> partialStateFuture;
if( action instanceof AsyncNodeActionWithConfig ) {
partialStateFuture = ((AsyncNodeActionWithConfig<State>)action).apply( withState, config );
}
else {
partialStateFuture = action.apply( withState );
}
private CompletableFuture<Data<Output>> evaluateAction(AsyncNodeActionWithConfig<State> action, State withState ) {

return partialStateFuture.thenApply( partialState -> {
return action.apply( withState, config ).thenApply( partialState -> {
try {

Optional<Data<Output>> embed = getEmbedGenerator( partialState );
Expand Down Expand Up @@ -543,7 +539,7 @@ public Data<Output> next() {

currentNodeId = nextNodeId;

AsyncNodeAction<State> action = nodes.get(currentNodeId);
AsyncNodeActionWithConfig<State> action = nodes.get(currentNodeId);

if (action == null)
throw StateGraph.RunnableErrors.missingNode.exception(currentNodeId);
Expand Down
14 changes: 4 additions & 10 deletions core-jdk8/src/main/java/org/bsc/langgraph4j/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,20 @@ class Node<State extends AgentState> {
/**
* The action to be performed asynchronously by the node.
*/
AsyncNodeAction<State> action;

AsyncNodeActionWithConfig<State> actionWithConfig;
AsyncNodeActionWithConfig<State> action;

public Node( String id ) {
this.id = id;
this.action = null;
this.actionWithConfig = null;

}
public Node( String id, AsyncNodeAction<State> action ) {
this.id = id;
this.action = action;
this.actionWithConfig = null;
this.action = AsyncNodeActionWithConfig.of(action);
}
public Node( String id, AsyncNodeActionWithConfig<State> actionWithConfig ) {
public Node( String id, AsyncNodeActionWithConfig<State> action ) {
this.id = id;
this.action = null;
this.actionWithConfig = actionWithConfig;

this.action = action;
}
/**
* Checks if this node is equal to another object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,15 @@ static <S extends AgentState> AsyncNodeActionWithConfig<S> node_async(NodeAction
};
}

/**
* Adapts a simple AsyncNodeAction to an AsyncNodeActionWithConfig.
*
* @param action the simple AsyncNodeAction to be adapted
* @param <S> the type of the agent state
* @return an AsyncNodeActionWithConfig that wraps the given AsyncNodeAction
*/
static <S extends AgentState> AsyncNodeActionWithConfig<S> of(AsyncNodeAction<S> action) {
return (t, config) -> action.apply(t);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,14 @@ public final java.util.Map<String,Object> data() {
* @param <T> the type of the value
* @return an Optional containing the value if present, otherwise an empty Optional
*/
public final <T> Optional<T> value(String key) {
return ofNullable((T) data().get(key));
}
public final <T> T value(String key, T defaultValue ) {
return (T)value(key).orElse(defaultValue);
}
@SuppressWarnings("unchecked")
public final <T> Optional<T> value(String key) { return ofNullable((T) data().get(key));}

public final <T> T value(String key, Supplier<T> defaultProvider ) {
return (T)value(key).orElseGet(defaultProvider);
}
@Deprecated
public final <T> T value(String key, T defaultValue ) { return this.<T>value(key).orElse(defaultValue);}

@Deprecated
public final <T> T value(String key, Supplier<T> defaultProvider ) { return this.<T>value(key).orElseGet(defaultProvider); }

/**
* Retrieves or creates an AppendableValue associated with the given key.
Expand Down Expand Up @@ -108,6 +106,7 @@ public String toString() {
* @param newValue the new value
* @return the merged value
*/
@Deprecated
private static Object mergeFunction(Object currentValue, Object newValue) {
if (currentValue instanceof AppendableValueRW<?>) {
((AppendableValueRW<?>) currentValue).append(newValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public MessagesState(Map<String, Object> initData) {
}

int steps() {
return value("steps", 0);
return this.<Integer>value("steps").orElse(0);
}

List<String> messages() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public MessagesState(Map<String, Object> initData) {
}

int steps() {
return value("steps", 0);
return this.<Integer>value("steps").orElse(0);
}

List<String> messages() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public MessagesState(Map<String, Object> initData) {
}

int steps() {
return value("steps", 0);
return this.<Integer>value("steps").orElse(0);
}

List<String> messages() {
Expand Down
2 changes: 1 addition & 1 deletion how-tos/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.bsc.langgraph4j</groupId>
<artifactId>langgraph4j-parent</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
</parent>

<artifactId>langgraph4j-howtos</artifactId>
Expand Down
Loading

0 comments on commit 381e9ec

Please sign in to comment.