AI Agent in Java with LangGraph4j
bsorrentino
Posted on May 21, 2024
LangChain and LangGraph
In the previous article AI Agent on iOS with LangGraph for Swift I've introduced [LangGraph-Swift] an implementation of LangGraph a library, powered by LangChain for building stateful, multi-agent applications with LLMs that lets you coordinate and checkpoint multiple chains across cyclic computational steps using regular python
or Javascript
functions.
As said, I developed [LangGraph-Swift] to reuse my knowledege around LangGraph and LangChain for building
LangChain iOS apps powered by LLM.
Why LangGraph for Java ❓
Since I've dealt with companies which IT department is mainly based on Java technology and they would want explore and experiment LLM in their application, I've choose to use LangChain4j framework and, as consequence, I've decided to develop LangGraph4j to reuse, again, my knowledge around both LangGraph and LangChain.
Use LangGraph4j with LangChain4j
LangGraph4j can work seamlessly with LangChain4j and to proof that I've implemented a couple of use cases described below
Agent Executor
The agent executor is the runtime for an agent. This is what actually calls the agent, executes the actions it chooses, passes the action outputs back to the agent, and repeats. Below the diagram representing the implemented graph, for the complete code take look here 👀
Image To Diagram
I've also experimented LLM multi-modality capabilities developing a graph where, initially, an agent receives an image and is responsible for analyzing and describing its content, such description is then passed to a specialized agent equipped with the skills to translate the description into PlantUML code.
Take note that to ensure precision in diagram generation, the type of diagram identified within the image dictates the selection of the appropriately skilled agent for the translation task.
Finally, in the case that there are errors in result of PlantUML code we have established a supplementary flow that provided a correction process consisting of iteration between both verification and rewrite steps.
Below the diagram representing the implemented graph, for the complete code take look here 👀
Conclusion
LangGraph4j is a side project that try to brings flexibility of the original LangGraph to develop stateful, multi-agents applications with LLMs in Java. Currently, I haven't relased a stable version yet, only the developer one 1.0-SNAPSHOT
. Let me know if you are interest in its usage and evolution. In the meanwhile, enjoy coding! 👋
Originally published at https://bsorrentino.github.io on May 20, 2024.
Posted on May 21, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.