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:
import io.github.the_pocket.PocketFlow;
import io.github.the_pocket.PocketFlow.*;
import java.util.HashMap;
import java.util.Map;
public class MyWorkflowApp {
// Define a custom start node
static class MyStartNode extends Node<Void, String, String> {
@Override
public String exec(Void prepResult) {
System.out.println("Starting workflow...");
return "started";
}
}
// Define a custom end node
static class MyEndNode extends Node<String, Void, Void> {
@Override
public String prep(Map<String, Object> ctx) {
return "Preparing to end workflow";
}
@Override
public Void exec(String prepResult) {
System.out.println("Ending workflow with: " + prepResult);
return null;
}
}
public static void main(String[] args) {
// Create instances of your nodes
MyStartNode startNode = new MyStartNode();
MyEndNode endNode = new MyEndNode();
// Connect the nodes
startNode.next(endNode, "started");
// Create a flow with the start node
Flow<String> flow = new Flow<>(startNode);
// Create a context and run the flow
Map<String, Object> context = new HashMap<>();
System.out.println("Executing workflow...");
flow.run(context);
System.out.println("Workflow completed successfully.");
}
}
mvn compile
mvn test
Contributions 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.