From 30820697591c0001e6d7758faf103d9b009bd1f7 Mon Sep 17 00:00:00 2001 From: bsorrentino Date: Sun, 30 Jun 2024 18:23:07 +0200 Subject: [PATCH] docs: update readme --- README.md | 40 ++++++++++++++++++- .../langgraph4j/action/AsyncEdgeAction.java | 4 +- .../langgraph4j/action/AsyncNodeAction.java | 2 +- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e8b9a50..5e6539f 100644 --- a/README.md +++ b/README.md @@ -61,11 +61,31 @@ public class AgentState { ### Define the nodes -We now need to define a few different nodes in our graph. In `langgraph`, a node is a function that accept an `AgentState` as argument. There are two main nodes we need for this: +We now need to define a few different nodes in our graph. In `langgraph`, a node is an async/sync function that accept an `AgentState` as argument and returns a (partial) state update. There are two main nodes we need for this: 1. **The agent**: responsible for deciding what (if any) actions to take. 1. **A function to invoke tools**: if the agent decides to take an action, this node will then execute that action. +```java + +/** + * Represents an asynchronous node action that operates on an agent state and returns state update. + * + * @param the type of the agent state + */ +@FunctionalInterface +public interface AsyncNodeAction extends Function>> { + + CompletableFuture> apply(S t); + + /** + * Creates an asynchronous node action from a synchronous node action. + */ + static AsyncNodeAction node_async(NodeAction syncAction) { ... } +} + +``` + ### Define Edges We will also need to define some edges. Some of these edges may be conditional. The reason they are conditional is that based on the output of a node, one of several paths may be taken. The path that is taken is not known until that node is run (the LLM decides). @@ -75,6 +95,24 @@ We will also need to define some edges. Some of these edges may be conditional. * If the agent said that it was finished, then it should finish 1. **Normal Edge**: after the tools are invoked, it should always go back to the agent to decide what to do next +```java + +/** + * Represents an asynchronous edge action that operates on an agent state and returns a new route. + * + * @param the type of the agent state + */ +public interface AsyncEdgeAction extends Function> { + + CompletableFuture apply(S t); + + /** + * Creates an asynchronous edge action from a synchronous edge action. + */ + static AsyncEdgeAction edge_async(EdgeAction syncAction ) { ... } +} +``` + ### Define the graph We can now put it all together and define the graph! (see example below) diff --git a/core-jdk8/src/main/java/org/bsc/langgraph4j/action/AsyncEdgeAction.java b/core-jdk8/src/main/java/org/bsc/langgraph4j/action/AsyncEdgeAction.java index 8afe652..1cda1aa 100644 --- a/core-jdk8/src/main/java/org/bsc/langgraph4j/action/AsyncEdgeAction.java +++ b/core-jdk8/src/main/java/org/bsc/langgraph4j/action/AsyncEdgeAction.java @@ -5,8 +5,8 @@ import java.util.concurrent.CompletableFuture; import java.util.function.Function; /** - * Represents an asynchronous edge action that operates on an agent state and returns a CompletableFuture. - * + * Represents an asynchronous edge action that operates on an agent state and returns a new route. + * * @param the type of the agent state */ public interface AsyncEdgeAction extends Function> { diff --git a/core-jdk8/src/main/java/org/bsc/langgraph4j/action/AsyncNodeAction.java b/core-jdk8/src/main/java/org/bsc/langgraph4j/action/AsyncNodeAction.java index f9a9b69..9f4e09e 100644 --- a/core-jdk8/src/main/java/org/bsc/langgraph4j/action/AsyncNodeAction.java +++ b/core-jdk8/src/main/java/org/bsc/langgraph4j/action/AsyncNodeAction.java @@ -7,7 +7,7 @@ import java.util.function.Function; /** - * Represents an asynchronous node action that operates on an agent state and returns a CompletableFuture. + * Represents an asynchronous node action that operates on an agent state and returns state update. * * @param the type of the agent state */