LangGraph: Challenges as a Multi-Agent Orchestrator?
In the realm of artificial intelligence and multi-agent systems, LangGraph stands out as a powerful tool for orchestrating agent interactions and streamlining complex workflows. One key aspect of LangGraph is its ability to facilitate the role of an Agent Supervisor, a crucial entity responsible for managing and delegating tasks among a team of agents. But, is LangGraph the best to deal with multi-agent workflows? We will get insights about this by the end of this post.
Introduction
In this blog post, we will delve into the world of LangGraph and explore how we can leverage its capabilities to implement an Agent Supervisor effectively. In addition, we will perform some hands-on over the Agent Supervisor in a use-case involving Document Analyzer as well as Internet Researcher as agent nodes. Lastly, we will talk about the limitations LangGraph currently has.

How LangGraph Improves Upon LangChain
LangGraph offers several advantages over LangChain's original functionalities, particularly when building complex applications with large language models (LLMs).
— Enables Cyclical Workflows:
- LangChain struggles to represent cycles in its chain definitions, which are crucial for building agent runtimes. These cycles allow the LLM to reason about its next action within the loop, leading to more adaptable and flexible applications.
- LangGraph addresses this limitation by introducing a way to create cyclical graphs, empowering developers to design agent-like behaviors.
— Enhances Control and Flexibility:
- While LangChain excels at creating custom chains (DAGs), it lacks fine-grained control within these chains.
- LangGraph offers more control over how the LLM interacts with various tools, allowing developers to:
- Specify the order in which tools are called.
- Customize prompts based on the application's state.
— Simplifies Complex State Machines:
- Building intricate state machines with LangChain can be cumbersome.
- LangGraph simplifies the process by allowing developers to define state machines as graphs, making them easier to understand and manage.
— Ideal for Complex LLM Applications:
- LangChain shines in simpler linear workflows, but struggles with complex applications requiring reasoning and decision-making by the LLM.
- LangGraph caters specifically to these complex scenarios, enabling developers to build more powerful and versatile LLM applications.
In essence, LangGraph builds upon LangChain's foundation, offering a more flexible and powerful toolset for creating sophisticated and adaptable LLM applications.
LangGraph Hands-On
Step 1: Understanding LangGraph and Agent Supervision
LangGraph is a versatile framework that enables the creation and management of multi-agent systems. At the heart of LangGraph lies the concept of Agent Supervision, where a designated supervisor oversees the activities of individual agents within a collaborative environment. By defining roles, responsibilities, and communication protocols, the Agent Supervisor plays a pivotal role in ensuring seamless coordination and efficient task allocation.

Step 2: Setting Up Our Environment
Before diving into the implementation process, it is essential to configure our environment to work with Langgraph. Start by installing the necessary dependencies, including Langchain, Langchain OpenAI, Langchain Experimental, Langsmith, and Pandas. These libraries will provide us with the tools and resources needed to build and deploy our Agent Supervisor within Langgraph.

Step 3: Creating an Agent Group
To begin building our Agent Supervisor system, we will need to create an agent group comprising individual agents with specific roles and functions. We have to define the characteristics of each agent, such as their capabilities, tools, and communication protocols. By structuring our agent group effectively, we can ensure a cohesive and coordinated workflow within LangGraph.
In this use-case, we are creating two agents — PDF_Reader and Researcher.
Defining PDF_Reader function –

Creating PDF_Reader tool –

Defining Researcher function and creating tool –

We are using TavilySearchResults for the Researcher function and then creating the Researcher tool.
Creating Agents –

Step 4: Implementing the Agent Supervisor
Next, it's time to implement the Agent Supervisor within our agent group. Utilize LangGraph's advanced features, such as the StateGraph and AgentState, to define the behavior and decision-making logic of the Supervisor node. By incorporating function calling and output parsing mechanisms, we can enable the Supervisor to route tasks to the appropriate agents based on predefined criteria.


Step 5: Connecting the Nodes
Once we have defined the roles and behaviors of each agent within the group, connect all the nodes in the graph to establish a seamless flow of communication and task delegation.

Use conditional mapping and edge connections to ensure that each agent reports back to the Supervisor upon task completion, enabling the Supervisor to manage the overall progress of the workflow effectively.

Step 6: Invoking the Graph
After setting up our Agent Supervisor system within LangGraph, we have to invoke the graph and stream it. The PDF document that is provided to the agent is based on "Link Prediction". So, when the question is related to Link Prediction, supervisor choose PDF_Reader agent node to answer the question first.

In the output above, we can see that the flow is iterating over both the agent multiple times, which is not ideal as it is using excess tokens than required and the output may even hallucinate when the agents start talking to themselves. We will show this in further examples below.
Now, invoking the graph with something that is not present in the PDF, like "What is LangChain?". In the output below, we can see that the supervisor is choosing the right agent node to send the query.

We should conduct thorough testing scenarios to validate the behavior of the Supervisor node and its interactions with individual agents. We should also iterate on the design, optimize the workflow, and fine-tune the decision-making logic to enhance the efficiency and effectiveness of the Agent Supervisor. I tried many things to improve the outputs produced like giving system message to the query and refining prompts for the supervisor. For example, in the output below, we can see that the supervisor should have chosen PDF_Reader instead of Researcher agent node.

One other problem we could face is that the supervisor keeps sending the output of one agent to itself again and again like in the picture given below.


I also tried to strictly define the flow and edges in the graph as given below.

Limitations for LangGraph
Till now, we have been talking about the advantages of using LangGraph. Now we will note down the limitations we have faced.
Some limitations that we are facing are as follows:
- It is often seen that the supervisor keeps sending the output of one agent to itself again and again.
- The agents start talking to themselves which results in higher runtime and higher token consumption even when not required.
- Also, it is often seen that the supervisor chooses other agents than which is preferred, thus leading to hallucinations.


I'm confident there would be solutions to these issues. While LangGraph is a relatively new tool, released about a month ago, it has already seen widespread adoption by professionals around the world and has produced impressive results. Given its potential and ongoing development, I believe these issues will be addressed in future updates.
Conclusion
In conclusion, LangGraph emerges as a cutting-edge framework that empowers users to orchestrate complex interactions among agents effectively. By leveraging its advanced features and capabilities, such as Agent Supervision and StateGraph, users can streamline workflows, optimize task allocation, and enhance collaboration within multi-agent systems. LangGraph opens up a world of possibilities for designing intelligent and efficient agent interactions, paving the way for innovative solutions in artificial intelligence and beyond. Though there are some limitations, we can embrace the power of LangGraph and embark on a journey towards unlocking the full potential of multi-agent systems.
I'd love to hear your thoughts on LangGraph in the comments below! I'm especially curious about what elements you've found most helpful in optimizing performance of LangGraph.
I will be sharing more about persistence and self-reflecting agents in future LangGraph blogs. In the meantime, feel free to explore my other posts on Generative AI and LangChain!