A minimalist LLM framework, ported from Python to Java.
PocketFlow Java is a direct port of the original Python PocketFlow framework. It provides a lightweight, flexible system for building and executing LLM-based workflows through a simple node-based architecture.
Note: This is an initial implementation that currently does not support asynchronous operations. Community contributors are welcome to help enhance and maintain this project.
Add the following dependency to your pom.xml:
<dependency>
<groupId>io.github.the-pocket</groupId>
<artifactId>PocketFlow</artifactId>
<version>1.0.0</version>
</dependency>Groovy DSL (build.gradle):
dependencies {
implementation 'io.github.the-pocket:PocketFlow:1.0.0'
}Kotlin DSL (build.gradle.kts):
dependencies {
implementation("io.github.the-pocket:PocketFlow:1.0.0")
}Here's a simple example of how to use PocketFlow Java in your application:
importio.github.the_pocket.PocketFlow;
importio.github.the_pocket.PocketFlow.*;
importjava.util.HashMap;
importjava.util.Map;
publicclassMyWorkflowApp {
// Define a custom start nodestaticclassMyStartNodeextendsNode<Void, String, String> {
@OverridepublicStringexec(VoidprepResult) {
System.out.println("Starting workflow...");
return"started";
}
}
// Define a custom end nodestaticclassMyEndNodeextendsNode<String, Void, Void> {
@OverridepublicStringprep(Map<String, Object> ctx) {
return"Preparing to end workflow"; }
@OverridepublicVoidexec(StringprepResult) {
System.out.println("Ending workflow with: " + prepResult);
returnnull;
}
}
publicstaticvoidmain(String[] args) {
// Create instances of your nodesMyStartNodestartNode = newMyStartNode();
MyEndNodeendNode = newMyEndNode();
// Connect the nodesstartNode.next(endNode, "started");
// Create a flow with the start nodeFlow<String> flow = newFlow<>(startNode);
// Create a context and run the flowMap<String, Object> context = newHashMap<>();
System.out.println("Executing workflow...");
flow.run(context);
System.out.println("Workflow completed successfully.");
}
}mvn compilemvn testContributions are welcome! We're particularly looking for volunteers to:
- Implement asynchronous operation support
- Add comprehensive test coverage
- Improve documentation and provide examples
Please feel free to submit pull requests or open issues for discussion.