-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(LangGraphStreamingServer): implementation refinement
work on #9
- Loading branch information
1 parent
3cf8b64
commit 3b8c6cf
Showing
3 changed files
with
116 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 61 additions & 1 deletion
62
jetty/src/test/java/org/bsc/langgraph4j/LangGraphStreamingServerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,62 @@ | ||
package org.bsc.langgraph4j;public class LangGraphStreamingServerTest { | ||
package org.bsc.langgraph4j; | ||
|
||
import org.bsc.langgraph4j.action.AsyncNodeAction; | ||
import org.bsc.langgraph4j.action.EdgeAction; | ||
import org.bsc.langgraph4j.state.AgentState; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import static org.bsc.langgraph4j.StateGraph.END; | ||
import static org.bsc.langgraph4j.action.AsyncEdgeAction.edge_async; | ||
import static org.bsc.langgraph4j.action.AsyncNodeAction.node_async; | ||
import static org.bsc.langgraph4j.utils.CollectionsUtils.mapOf; | ||
|
||
public class LangGraphStreamingServerTest { | ||
|
||
|
||
public static void main(String[] args) throws Exception { | ||
StateGraph<AgentState> workflow = new StateGraph<>(AgentState::new); | ||
|
||
workflow.setEntryPoint("agent_1"); | ||
|
||
workflow.addNode("agent_1", node_async((state ) -> { | ||
System.out.println("agent_1 "); | ||
System.out.println(state); | ||
return mapOf("prop1", "test"); | ||
}) ) ; | ||
|
||
workflow.addNode("agent_2", node_async( state -> { | ||
|
||
System.out.print( "agent_2: "); | ||
System.out.println( state ); | ||
|
||
return mapOf("prop2", "test"); | ||
})); | ||
|
||
workflow.addEdge("agent_2", "agent_1" ); | ||
|
||
|
||
EdgeAction<AgentState> conditionalAge = new EdgeAction<>() { | ||
int steps= 0; | ||
@Override | ||
public String apply(AgentState state) { | ||
if( ++steps == 10 ) { | ||
return END; | ||
} | ||
return "a2"; | ||
} | ||
}; | ||
|
||
workflow.addConditionalEdges("agent_1", | ||
edge_async(conditionalAge), mapOf( "a2", "agent_2", "end", END ) ); | ||
|
||
CompiledGraph<AgentState> app = workflow.compile(); | ||
|
||
LangGraphStreamingServer server = LangGraphStreamingServer.of(app); | ||
|
||
server.start().join(); | ||
|
||
} | ||
|
||
} |