Pre-Requisites
- Basic understanding of Agentic AI concepts.
- Familiarity with Embabel platform.
For quick refresher, please refer to the previous post.
Introduction
Agentic AI workflows automate complex tasks by splitting them into smaller subtasks. As the complexity of an application increases, the number of subtasks in a workflow also grows. Managing such a workflow with a single agent becomes challenging. To address this, related subtasks can be grouped into separate sub-agentic workflows. These sub-agentic workflows can then be combined into a final workflow. This approach is referred to as a Multi-Agent AI Workflow. For example, an automated e-commerce support system may contain:
- Customer facing agent
- Inventory support agent
- Billing agent
- Dispatch service agent etc.
Another major advantage of splitting a workflow is the ability to develop components in parallel, making debugging easier and improving maintainability and reusability.
It is very similar to the standard software engineering practice of modular design and reusability.
Communication Patterns of Multi-Agent Workflow
There are various ways in which multi-agent workflows can be setup depending on our need.
Linear Communication Pattern
Here, once the previous agent has completed its tasks, it delegates to the next agent as defined.
For example, the Customer Facing Agent infers an action item based on the customer request. Then, it delegates the concrete action item to next agent, which is the Inventory Support Agent. Inventory Support Agent checks the inventory and responds back to Customer Facing Agent and so on.
Hierarchical Communication Pattern
A supervisor agent manages the communication flow between agents. The supervisor agent selects which subagents to communicate with. For example, the Supervisor agent decides whether the next agent to execute is Inventory or Billing Agent based on feedback from the Customer Facing Agent feedback.
Deep Hierarchy Communication Pattern
It is similar to hierarchical communication pattern except that subagents can themselves act as a supervisor for other subagents. For example, the Dispatch Service Agent might request location-related information from the Delivery Agent.
All-to-all Communication Pattern
Agents have the capability to interact with any other agent based on the context. This pattern is suitable for repetitive tasks and chatbot-like scenarios.
Implementation
Consider the following use case:
In an ecommerce support system, customers can log their support requests in their own language. The customer support assistant can translate the query into English and process the request.
For this, we will create following two agents:
- Translation Agent - translates from any language into English
- Summarization Agent - processes the translated query to infer the exact user request
Embabel provides various ways to support different agentic communication patterns.
Linear Communication Pattern
Full code is available here.
Each agent is defined as a separate workflow.
TranslationAgent takes UserInput as input and produces TranslatedQuery as output.
SummarizationAgent takes TranslatedQuery as input and produces SummarisedQuery as output.
TranslationAgent delegates to SummarizationAgent after translation using RunSubagent#fromAnnotatedInstance.
@Action
@AchievesGoal(description = "Translate customer query to English")
public SummarisedQuery delegateToSummarizationAgent(TranslatedQuery translatedQuery) {
return RunSubagent.fromAnnotatedInstance(summarizationAgent, SummarisedQuery.class);
}
Embabel automatically shares context between agents via Blackboard.
Hierarchical Communication Pattern
Full code is available here.
Here, we define a SupervisorAgent workflow that manages communication between TranslationAgent and SummarizationAgent.
SupervisorInvocation provides an easy way to invoke subagents from supervisor agent.
SupervisorInvocation.on(agentPlatform)
.returning(SummarisedQuery.class)
.invoke(new UserInput(query));
First, supervisor agent is invoked with UserInput which matches the TranslationAgent since it is invoked with UserInput.
The TranslationAgent returns a TranslatedQuery, which is then passed to the SummarizationAgent by the supervisor agent.
Apart from these, Embabel provides various other APIs to implement different communication patterns.
Testing
- Customer submits a support request in English
$ curl --get "http://localhost:8080/api" --data-urlencode "query=I want to return my order ORD-01. Thanks. - Omkar"
{"orderId":"ORD-01","query":"Request to return the order."
- Customer submits a support request in Hindi -
मैं अपने ऑर्डर ORD-003 का डिलीवरी पता मैसूर के बजाय बैंगलोर में बदलना चाहता हूँ। धन्यवाद। - प्रताप
Output: {"orderId":"ORD-003","query":"Change delivery address from Mysore to Bangalore"}
- Customer submits a support request in Kannada
ನಾನು ನನ್ನ ಆರ್ಡರ್ ORD-002 ಅನ್ನು ರದ್ದುಪಡಿಸಲು ಬಯಸುತ್ತೇನೆ. ಧನ್ಯವಾದಗಳು. - ಶ್ರೀನಿವಾಸ್
Output: {"orderId":"ORD-002","query":"Request to cancel the order."}
Congratulations!🎉 You have successfully implemented a multi-agent AI workflow using Embabel.
Conclusion
Multi-Agent AI workflows help in managing complex workflows by splitting them into simpler sub-workflows. Embabel provides easy to use APIs to implement various communication patterns between agents.
Let me know your thoughts in the comments section below!