by czelabueno
Build programmatically custom agentic workflows, AI Agents, RAG systems for java
# Add to your Claude Code skills
git clone https://github.com/czelabueno/jai-workflowAn open-source Java library to build, package, integrate, orchestrate and monitor agentic AI systems for java developers 💡

class MyStatefulBean extends AbstractStatefulBean {
private List<String> documents;
// other additional input/output fields that you want to store
}
StreamingChatLanguageModel model = OpenAiStreamingChatModel.builder()
.apiKey(System.getenv("OPENAI_API_KEY"))
.modelName(GPT_4_O_MINI)
.build();
var parserDocsNode = Node.from("Docs", obj -> transformDocsFromUrl(obj, uris));
var retrieveNode = Node.from("Vector DB", obj -> extractRelevantDocumentsFromVectorDB(obj));
var generateAnswerNode = StreamingNode.from("Generate",obj -> generateAnswer(obj), model);
var jAiWorkflow = new DefaultJAiWorkflow<MyStatefulBean>(
new MyStatefulBean(),
List.of(Transition.from(parserDocsNode, retrieveNode),
Transition.from(retrieveNode, Conditional.eval("enoughData",
obj -> obj.isEnoughData() ? generateAnswerNode : parserDocsNode,
List.of(parserDocsNode, generateAnswerNode))),
Transition.from(generateAnswerNode, WorkflowStateName.END)),
retrieveNode, // Start node
true // Run in streaming mode
);
// Chat with your JAiWorkflow
var question = "Summarizes the importance of building AI agentic systems";
Flux<String> response = jAiWorkflow.answerStream(question);
No comments yet. Be the first to share your thoughts!
🌟 Starring me: If you find this repository beneficial, don't forget to give it a star! 🌟 It's a simple way to show your appreciation and help this project grow!
JavAI Workflow (named initially Langchain4j-workflow) is a dynamic, stateful workflow engine crafted as a Java library. It empowers java developers with granular control over the orchestrated workflows as a graph, iteratively, with cycles, flexibility, control, and conditional decisions. This engine is a game-changer for building sophisticated AI applications, such as multiples RAG-based approaches using modern paradigms and agent architectures. It enables the crafting of custom behavior, leading to a significant reduction in hallucinations and an increase in response reliability.

A Node represents a single unit of work within the workflow. It encapsulates a specific function or task that processes the stateful bean and updates it. Nodes can be synchronous or asynchronous (streaming).
A Module is a collection of nodes grouped together to perform a higher-level function. Modules can be reused across different workflows, providing modularity and reusability.
A Workflow is a directed graph of nodes, modules and edges that defines the sequence of operations to be performed. It manages the state transitions and execution flow, ensuring that each node processes the stateful bean in the correct order.
one-way, parallelization, routing, branching and conditional inspired on Modular RAG AI paper. All of these patterns can be used at definition, build and run time, except for parallelization which is not supported at run time.Split, Merge, Parallel, Conditional with a list of expected nodes to be returned. These nodes allow you to define complex workflows patterns with multiple transitions between nodes.ComputedTransition with all details of the workflow execution. This feature allows you to debug the flow of your application and trace the inputs, outputs, execution order, datetime of each node.myworkflow.putEdge(..), add more nodes myworkflow.addNode(..) and override the start node myworkflow.startNode(..) at Just-in-time after workflow runs. This feature allows you to modify the workflow behavior dynamically during execution.File or as BufferedImage to be displayed in a java notebook. Also, you can use StyleGraph.SKETCHY as StyleAttribute to generate workflow images with excalidraw style. This style is supported in Graphviz implementation only.Nodes, Conditional Nodes, Edges, and workflows as a graph. This feature allows you to define custom workflows with multiple Transitions between nodes such as one-way, round trip and recursive.workflow.run() and streaming worflow.runStream() runs the outputs as they are produced by each node. This last feature allows for real-time processing and response in your application.Graphhviz lib to generate the image, but you implement your own image generator on GraphImageGenerator.java interface.
This is a prototype, the final version will be available soon. Open an issue if you want to share your ideas or contribute to this feature.
jAI Workflow is designed with a modular architecture, enabling you to define custom workflows, modules, or agents to build RAG systems as LEGO-like. A module can be decoupled and integrated into any other workflow.