LangGraph: Agent Orchestrator

RAJIB DEB
4 min readJan 27, 2024

--

In the traditional microservices world, we have two design patterns for the micro services to interact with each other. One is “Orchestration” and the other is “Choreography”. These are two very popular patterns in the distributed world. I do not intend to re-explain them here. For the un-initiated, below is a good link to read.

https://camunda.com/blog/2023/02/orchestration-vs-choreography/

The purpose of this article is to talk about the applicability of these patterns in the multi-agent interaction space. When I was looking at the various multi-agent system, I found them being developed in a very monolithic way. The agents and the stitching of the agents happen in the same component which creates a tight coupling between the two. If for some reason, I want to change something in the agent, the stitching part also gets impacted. I was not able to figure out why we are not leveraging the design principles of micro-services in the new world of language model based agent interactions. In this case, it is not a “old wine in a new bottle”; we can use the same old bottle, but the the wine is new. The wine now is semantic in nature and not syntactic like the traditional micro-services.

I raised this query in the langchain discord and tagged Harrison to see if langchain is thinking this in a different way. Harrison then pointed me to LangGraph. I spent some time to understand the working of LangGraph. LangGraph is implementing the “Orchestration” pattern to stitch the micro-agents together. But I still did not see a solution or a package that is compatible with the “Choreography” pattern. I will talk about this pattern and how it can be applied to micro-agents in a different article. In this article, I want to talk more about LangGraph and Orchestration.

How does LangGraph work?

One of the core requirement for multi-agent interaction is to make a shared state available to the agents. This state should be visible to all agents and each should be able to read/update that state. LangGraph has created a library that helps in managing that state in a multi-agent system in a very simple way. It does this by extending LCEL(Langchain Expression Language) to enable the agent coordinate multiple computation steps in a cyclic manner.

The concept of orchestration and where LangGraph fits in this, can be easily understood through a diagram and a use case. Let’s say I want to develop a bot that needs to cater to users across the globe. Based on the geography of the user, the bot will present geography specific news topics from different news channels like NDTV, BBC, FOX, CNN. The conceptual solution for this will look like as below.

Composite and Atomic Agents

At the bottom we have the atomic agents, which can be language models with tools. Each of these atomic agents are purpose built to do only one thing. In this case, each agent gathers the news for a particular channel. The composite agent applies the domain specific logic to cater to a particular use-case and domain. And this is where LangGraph sits. LangGraph now acts as the orchestrator of the various atomic agents and shapes the response specific to the requirement.

LangGraph creates an instance of a state graph and exposes the below functions to make this possible. This state graph is what creates the shared state that each node can now see or update.

add_node : Through this we can define the nodes that needs to participate in the flow. These nodes can be the atomic services in the above picture.

set_entry_point: Through this, we can define which is the entry point for the workflow.

add_conditional_edges: Through this, we can add a decision point. For example, we can add a decision whether a particular news channel(atomic agent) should be called or not.

add_edge: Through this, we can stitch two atomic agents together.

set_finish_point: Through this, we can define which is the last node in the workflow. This is optional and not required if any of the edge in the workflow is set to END the workflow.

compile: When we compile the stategraph, it creates an instance of Langchain Runnable interface which now expose all the runnable functions through which I can now invoke the composite agent.

LangGraph has applicability in also bridging the semantic and syntactic world, something I have been talking about for sometimes. The micro-services pattern in the application world is going to morph into a micro-agent pattern where both syntactic(Python, SpringBoot based traditional services) and semantic(enabled by language models and prompts) world will come together to solve more complex use cases.

Stay tuned. In my next article, I plan to bring in more hands-on examples leveraging LangGraph.

Reference: https://python.langchain.com/docs/langgraph

--

--