
Future-Proofing the Insurance Target Operating Model
Explore insights from top insurance CIOs on future-proofing operating models in our latest report with Clearwater Analytics.
Multi-agent systems represent a paradigm shift in artificial intelligence, moving beyond single-model approaches to orchestrated teams of specialized AI agents working collaboratively. These systems provide several key advantages:
In a multi-agent system, specialized AI agents with distinct roles collaborate to solve complex problems that would be challenging for a single agent. This approach mirrors human team collaboration, where different specialists contribute their expertise to achieve a common goal.
Zoom image will be displayed
At Clearwater Analytics, we embarked on a journey to build an AI-driven multi-agent system long before frameworks like LangGraph emerged. Our solution, Clearwater Intelligent Console Flow (CWIC Flow), is a sophisticated AI platform that supports knowledge, application, and data awareness. Unlike traditional chatbot solutions, CWIC Flow orchestrates specialists — intelligent agents with tools, skills, and memory — to deliver highly contextualized and actionable insights to our clients. This architectural leap positioned Clearwater ahead of the curve, showcasing a multi-agent AI system before the industry widely adopted such paradigms.
CWIC Flow integrates a hierarchy of intelligent components:
Through this layered approach, CWIC Flow achieves real-time data awareness, contextual reasoning, and seamless automation, reducing operational overhead while enhancing user experience. The platform supports RAG (Retrieval-Augmented Generation) techniques, tool chaining, and LLM-based decision-making, all within a governed AI framework that ensures accuracy and compliance.
More details about CWIC architecture can be found in the article Constructing the Ultimate Gen AI Chat/Copilot Experience (Part 1).
Zoom image will be displayed
While new frameworks, such as LangGraph, now provide structured workflows for multi-agent AI applications, Clearwater Analytics had already developed a similar, robust system before these frameworks became mainstream. The key differentiators of CWIC Flow include:
For a demo of our Multi-Agent system, you can watch the Webinar: How Clearwater Analytics Creates Agentic Systems with SLMs.
Zoom image will be displayed
CWIC Flow represents a very complex multi-agent system that has been developed and refined over time at Clearwater Analytics. Before we delve deeper into the intricacies of CWIC Flow’s architecture, it’s beneficial to understand the fundamental concepts of multi-agent systems through a simpler implementation. In this article, we’ll build a straightforward multi-agent system using LangChain. This approach allows us to illustrate the core principles of agent collaboration, specialized roles, and orchestrated workflows in a more accessible manner. By starting with this foundation, readers can better appreciate the sophisticated design choices and advanced capabilities that make CWIC Flow such a powerful enterprise solution. The concepts demonstrated in our LangChain example — though simpler — share the same fundamental principles that underpin CWIC Flow’s more comprehensive implementation.
While frameworks like LangGraph provide structured ways to build multi-agent systems, it’s important to understand that you can create effective multi-agent architectures without specialized frameworks. Let’s explore a straightforward approach to building a multi-agent system using basic Python and LangChain components.
Zoom image will be displayed
Throughout this article, we’ll build a collaborative research assistant system with multiple specialized agents:
By the end of this article, you’ll have a fully functional multi-agent system that can perform research tasks collaboratively.
Let’s start by setting up our environment!
First, we need to set up our environment with the necessary packages:
# Install required packages !pip install langchain python-dotenv openai langchain-community langchain-openai
# Load environment variables import os from dotenv import load_dotenv load_dotenv() # Load API keys from .env file # Verify that the API key is loaded if os.getenv("OPENAI_API_KEY") is None: print("Warning: OPENAI_API_KEY not found in environment variables.") else: print("OPENAI_API_KEY found in environment variables.")
The foundation of our multi-agent system is well-crafted system prompts that define each agent’s role and responsibilities:
RESEARCHER_SYSTEM_PROMPT = """ You are a Researcher Agent, part of a collaborative research assistant system. Your role is to gather and provide accurate, relevant information on any topic or question presented to you. Your responsibilities include: 1. Analyzing research questions to understand what information is being requested 2. Providing comprehensive, well-structured responses based on your knowledge 3. Highlighting key points and important information 4. Being honest about the limitations of your knowledge 5. Maintaining objectivity and avoiding bias in your responses Format your responses in a clear, organized manner with sections, bullet points, or numbered lists as appropriate. Always cite your sources of information when possible. Remember, your goal is to provide the most helpful, accurate information possible to assist in the research process. """
def researcher_agent(messages): """Researcher agent that analyzes questions and provides informative responses.""" # Add the system prompt to guide the researcher agent's behavior researcher_messages = [SystemMessage(content=RESEARCHER_SYSTEM_PROMPT)] + messages # Create a ChatOpenAI instance llm = ChatOpenAI( temperature=0.5, # Lower temperature for more factual responses model_name="gpt-4o", openai_api_key=os.environ.get("OPENAI_API_KEY") ) # Get a response from the LLM response = llm(researcher_messages) print("\n--- Researcher Agent Response ---") print(f"{response.content[:300]}...\n") return response
CRITIC_SYSTEM_PROMPT = """ You are a Critic Agent, part of a collaborative research assistant system. Your role is to evaluate and challenge information provided by the Researcher Agent to ensure accuracy, completeness, and objectivity. Your responsibilities include: 1. Analyzing research findings for accuracy, completeness, and potential biases 2. Identifying gaps in the information or logical inconsistencies 3. Asking important questions that might have been overlooked 4. Suggesting improvements or alternative perspectives 5. Ensuring that the final information is balanced and well-rounded Be constructive in your criticism. Your goal is not to dismiss the researcher's work, but to strengthen it. Format your feedback in a clear, organized manner, highlighting specific points that need attention. Remember, your ultimate goal is to ensure that the final research output is of the highest quality possible. """
def critic_agent(messages): """Critic agent that evaluates and challenges the researcher's findings.""" # Add the system prompt to guide the critic agent's behavior critic_messages = [SystemMessage(content=CRITIC_SYSTEM_PROMPT)] + messages # Create a ChatOpenAI instance llm = ChatOpenAI( temperature=0.7, # Slightly higher temperature for more creative criticism model_name="gpt-4o", openai_api_key=os.environ.get("OPENAI_API_KEY") ) # Get a response from the LLM response = llm(critic_messages) print("\n--- Critic Agent Response ---") print(f"{response.content[:300]}...\n") return response
WRITER_SYSTEM_PROMPT = """ You are a Writer Agent, part of a collaborative research assistant system. Your role is to synthesize information from the Researcher Agent and feedback from the Critic Agent into a coherent, well-written response. Your responsibilities include: 1. Analyzing the information provided by the researcher and the feedback from the critic 2. Organizing the information in a logical, easy-to-understand structure 3. Presenting the information in a clear, engaging writing style 4. Balancing different perspectives and ensuring objectivity 5. Creating a final response that is comprehensive, accurate, and well-written Format your response in a clear, organized manner with appropriate headings, paragraphs, and bullet points. Use simple language to explain complex concepts, and provide examples where helpful. Remember, your goal is to create a final response that effectively communicates the information to the user. """
def writer_agent(messages): """Writer agent that synthesizes information from the researcher and critic.""" # Add the system prompt to guide the writer agent's behavior writer_messages = [SystemMessage(content=WRITER_SYSTEM_PROMPT)] + messages # Create a ChatOpenAI instance llm = ChatOpenAI( temperature=0.6, # Balanced temperature for creativity and accuracy model_name="gpt-4o", openai_api_key=os.environ.get("OPENAI_API_KEY") ) # Get a response from the LLM response = llm(writer_messages) print("\n--- Writer Agent Response ---") print(f"{response.content[:300]}...\n") return response
As with our other agents, we’ll start by defining a system prompt that outlines the coordinator’s role and responsibilities:
# Define the system prompts for each agent COORDINATOR_SYSTEM_PROMPT = """ You are a Coordinator Agent, responsible for managing the workflow between specialized agents in a collaborative research assistant system. Your role is to analyze queries, determine which agents should be involved, and ensure that the final response meets the user's needs. Your team includes: 1. Researcher Agent: Gathers and provides accurate, relevant information on topics 2. Critic Agent: Evaluates and challenges information to ensure accuracy and completeness 3. Writer Agent: Synthesizes information into coherent, well-written responses Your responsibilities include: 1. Analyzing the user's query to determine which agents should be involved 2. Deciding the order in which agents should process the query 3. Determining when additional research or feedback is needed 4. Ensuring that the final response meets the user's needs For each query, you must decide on one of the following next steps: - "researcher": Send the query to the researcher agent first - "done": The query has been fully addressed and no further action is needed Format your response as a JSON object with two fields: 1. "reasoning": Your step-by-step thought process 2. "next": Your decision on the next step ("researcher" or "done") Example: { "reasoning": "This query asks for factual information about quantum computing, which requires research.", "next": "researcher" } """
This prompt establishes the coordinator’s decision-making role and provides a structured format for its responses, which helps with programmatic routing in our system.
Now, let’s implement the coordinator agent function that will analyze the state and determine the next step in the workflow:
# Define the agent functions def coordinator_agent(messages): """Coordinator agent that manages the workflow between other agents.""" # Add the system prompt to guide the coordinator agent's behavior coordinator_messages = [SystemMessage(content=COORDINATOR_SYSTEM_PROMPT)] + messages # Create a ChatOpenAI instance llm = ChatOpenAI( temperature=0.3, # Lower temperature for more consistent decision-making model_name="gpt-4o", openai_api_key=os.environ.get("OPENAI_API_KEY") ) # Get a response from the LLM response = llm(coordinator_messages) # Parse the JSON response to get the next step try: response_content = response.content decision = json.loads(response_content) # Default to researcher if not specified next_step = decision.get("next", "researcher") # Print the coordinator's reasoning print(f"Coordinator reasoning: {decision.get('reasoning', 'No reasoning provided')}") print(f"Next step: {next_step}") except Exception as e: # If there's an error parsing the JSON, default to the researcher print(f"Error parsing coordinator response: {e}") print(f"Defaulting to researcher agent") next_step = "researcher" return next_step
Notice that we’re using a lower temperature (0.3) for the coordinator compared to our other agents. This promotes consistent, reliable decision-making — exactly what we want from the “manager” of our system.
With our coordinator agent implemented, we can transform our system from a fixed, sequential workflow to a dynamic one where the coordinator decides which path to take:
# Function to run the multi-agent system def run_multi_agent_system(question): """Run the multi-agent system with the given question.""" print(f"\n\n{'='*50}") print(f"QUERY: {question}") print(f"{'='*50}\n") # Initialize the messages with the question messages = [HumanMessage(content=question)] # Start with the coordinator next_step = coordinator_agent(messages) # Continue until the coordinator decides we're done while next_step != "done": if next_step == "researcher": # Run the researcher agent researcher_response = researcher_agent(messages) messages.append(researcher_response) # Run the critic agent critic_response = critic_agent(messages) messages.append(critic_response) # Run the writer agent writer_response = writer_agent(messages) messages.append(writer_response) # Back to the coordinator next_step = coordinator_agent(messages) else: # If the next step is not recognized, default to done print(f"Unrecognized next step: {next_step}") next_step = "done" # Find the final response (last AI message) final_response = None for message in reversed(messages): if isinstance(message, AIMessage): final_response = message.content break if final_response: print("\n--- Final Response ---") print(final_response) return messages
This creates a dynamic workflow where:
Let’s visualize our multi-agent system architecture using Mermaid diagrams:
Let’s also visualize how different types of queries flow through the system:
Here’s a more detailed view of how information flows through our multi-agent system:
Zoom image will be displayed
The coordinator agent makes decisions based on several factors:
Zoom image will be displayed
Let’s see how our dynamic system handles different types of queries:
# Main execution if __name__ == "__main__": print("Starting the multi-agent system...") # Test with different questions print("\n--- Testing with a complex research question ---") result1 = run_multi_agent_system("What are the latest advancements in renewable energy technologies and their potential impact on climate change?") print("\n--- Testing with a simple factual question ---") result2 = run_multi_agent_system("What is the capital of France?") print("\n--- Testing with a nuanced ethical question ---") result3 = run_multi_agent_system("What are the ethical implications of using AI in healthcare decision-making?") print("\nTesting complete!")
QUERY: What is the capital of France?
Coordinator reasoning:
This query is a straightforward factual question that requires specific information.
Next step: done
For simple factual queries, the coordinator can immediately determine that no complex research process is needed.
--- Testing with a simple factual question --- ================================================== QUERY: What is the capital of France? ================================================== Coordinator reasoning: This query is a straightforward factual question that requires specific information. Next step: done
QUERY: What are the latest advancements in renewable energy technologies and their potential impact on climate change?
Coordinator reasoning:
This query requires gathering up-to-date information on advancements in renewable energy technologies and their potential impact on climate change, which involves both research and analysis.
Next step: researcher
For complex research queries, the coordinator engages the full team of specialized agents to provide a comprehensive response.
Starting the multi-agent system... --- Testing with a complex research question --- ================================================== QUERY: What are the latest advancements in renewable energy technologies and their potential impact on climate change? ================================================== Coordinator reasoning: This query requires gathering up-to-date information on advancements in renewable energy technologies and their potential impact on climate change, which involves both research and analysis. Next step: researcher --- Researcher Agent Response --- Advancements in renewable energy technologies are crucial in combating climate change by reducing greenhouse gas emissions and transitioning to cleaner energy sources. Here are some of the latest advancements in renewable energy technologies and their potential impact on climate change: 1. **Solar ... --- Critic Agent Response --- While the overview of advancements in renewable energy technologies is generally accurate, there are a few areas where additional detail and clarification could enhance understanding and balance the perspective: 1. **Solar Power**: - **Perovskite Solar Cells**: While promising, perovskite solar ... --- Writer Agent Response --- In reviewing the latest advancements in renewable energy technologies and their potential impact on climate change, it is evident that these innovations play a crucial role in transitioning towards a sustainable energy future. Here's a refined overview with additional details and considerations for ... Coordinator reasoning: The query seeks detailed information on the latest advancements in renewable energy technologies and their impact on climate change, requiring in-depth analysis and evaluation of each technology. The response provided an overview of advancements in solar, wind, hydropower, geothermal, and bioenergy, highlighting key developments and their implications. However, to ensure a comprehensive understanding, additional details and considerations were identified for each technology, including challenges, environmental impacts, and sustainability concerns. By addressing these aspects, the response aims to provide a more balanced and informative perspective on the topic. Next step: done --- Final Response --- In reviewing the latest advancements in renewable energy technologies and their potential impact on climate change, it is evident that these innovations play a crucial role in transitioning towards a sustainable energy future. Here's a refined overview with additional details and considerations for a more comprehensive understanding: 1. **Solar Power**: - **Advancements**: - **Perovskite Solar Cells**: Despite their high efficiency, challenges such as stability and toxicity due to lead content are being addressed through ongoing research into alternative materials. - **Bifacial Solar Panels**: Environmental factors like snow coverage and ground reflectivity impact their performance, with varying efficiency based on installation conditions. 2. **Wind Power**: - **Advancements**: - **Floating Wind Turbines**: While promising for deep-water locations, challenges include higher initial costs, maintenance complexities, and grid integration issues. - **Larger Turbines**: Environmental and social considerations, such as wildlife impacts and community acceptance, are crucial aspects to consider alongside increased energy output. 3. **Hydropower**: - **Advancements**: - **Pumped Storage Hydropower**: Geographical and ecological constraints, along with the need for suitable topography, influence the feasibility and scalability of these systems. - **Run-of-River Hydropower**: Despite lower environmental impacts, considerations around aquatic ecosystems and water quality management remain significant. 4. **Geothermal Energy**: - **Advancements**: - **Enhanced Geothermal Systems**: Technical challenges in creating artificial reservoirs and economic viability pose hurdles that ongoing research aims to address. - **Direct-Use Applications**: Understanding the geographical limitations of geothermal resources is essential for maximizing their utilization in heating and cooling applications. 5. **Bioenergy**: - **Advancements**: - **Advanced Biofuels**: Sustainability concerns related to land use, food security, and lifecycle emissions underscore the importance of holistic assessments for biofuel deployment. - **Biogas Production**: Integration of biogas into circular economy practices for waste management and agricultural applications can enhance its role in emissions reduction. By acknowledging the complexities and considerations associated with each renewable energy technology, including environmental impacts, economic challenges, and policy implications, a more nuanced understanding of their potential impact on climate change emerges. Emphasizing the need for a holistic approach that addresses not only technological advancements but also broader sustainability aspects will be essential for maximizing the benefits of renewable energy in combating climate change.
QUERY: What are the ethical implications of using AI in healthcare decision-making?
Coordinator reasoning:
This query involves discussing the ethical implications of AI in healthcare, which requires a combination of research and critical evaluation.
Next step: researcher
For nuanced ethical questions, the coordinator recognizes the need for both factual information and critical analysis.
--- Testing with a nuanced ethical question --- ================================================== QUERY: What are the ethical implications of using AI in healthcare decision-making? ================================================== Coordinator reasoning: This query involves discussing the ethical implications of AI in healthcare, which requires a combination of research and critical evaluation. Next step: researcher --- Researcher Agent Response --- Using AI in healthcare decision-making raises various ethical implications that need to be carefully considered. Here are some key points to consider: 1. **Privacy and Data Security**: - AI systems require access to vast amounts of patient data. Ensuring the privacy and security of this data is ... --- Critic Agent Response --- Here are some additional points and questions to consider, as well as suggestions for strengthening your research: 1. **Regulatory and Ethical Guidelines**: - Explore existing regulatory frameworks and ethical guidelines that govern the use of AI in healthcare. How are they being implemented, an... --- Writer Agent Response --- In response to the feedback provided, I have expanded on the ethical implications of using AI in healthcare decision-making and included additional points and questions to consider: 1. **Regulatory and Ethical Guidelines**: - Explore existing regulatory frameworks and ethical guidelines that gov... Coordinator reasoning: The query delves into the ethical implications of using AI in healthcare decision-making, which requires a comprehensive analysis involving considerations such as privacy, transparency, bias, patient autonomy, accountability, equity, and more. The response provided an in-depth exploration of these ethical implications and suggested additional points and questions to further enhance the understanding of the topic. To address the feedback provided, the response has been expanded to include additional insights and considerations, offering a more holistic view of the ethical challenges and opportunities associated with AI in healthcare. Next step: done --- Final Response --- In response to the feedback provided, I have expanded on the ethical implications of using AI in healthcare decision-making and included additional points and questions to consider: 1. **Regulatory and Ethical Guidelines**: - Explore existing regulatory frameworks and ethical guidelines that govern the use of AI in healthcare. How are they being implemented, and are there any gaps that need to be addressed? - Consider the role of organizations like the FDA in regulating AI-based healthcare technologies to ensure patient safety and ethical use. 2. **Human Oversight**: - While AI can enhance decision-making, the importance of human oversight must be emphasized. How can healthcare systems ensure that AI recommendations are critically evaluated by human experts? - Discuss the concept of shared decision-making between AI systems and healthcare providers to leverage the strengths of both for optimal patient care. 3. **Long-term Implications**: - Consider the long-term implications of AI integration in healthcare. How might it change the patient-provider relationship over time? What are the potential societal impacts? - Explore the concept of algorithmic bias and its long-term effects on healthcare disparities, emphasizing the need for continuous monitoring and mitigation strategies. 4. **Education and Training**: - Healthcare professionals need to be educated about AI technologies and their implications. What are the best practices for training healthcare providers to effectively use and understand AI systems? - Highlight the importance of interdisciplinary education to bridge the gap between healthcare and technology, fostering collaboration and understanding among diverse stakeholders. 5. **International Perspectives**: - Consider how the ethical implications of AI in healthcare may vary across different cultural and legal contexts. How do international standards compare, and what can be learned from global approaches? - Explore case studies from different countries to understand how cultural norms and healthcare systems influence the ethical considerations of AI implementation in diverse settings. 6. **Patient Involvement**: - Investigate ways to actively involve patients in discussions about AI in healthcare. How can patient feedback and perspectives be integrated into the development and implementation of AI systems? - Discuss the concept of patient-centered AI design, where patient preferences and values are incorporated into the development process to ensure ethical and patient-friendly AI solutions. 7. **Success Stories and Challenges**: - Provide examples of successful AI applications in healthcare, as well as challenges faced in real-world implementations. What lessons can be learned from these experiences? - Highlight successful AI applications like IBM Watson for Oncology and discuss challenges such as data interoperability and algorithmic transparency that need to be addressed for widespread adoption and ethical use of AI in healthcare. By addressing these additional points and questions, a more thorough exploration of the ethical implications of using AI in healthcare decision-making can be achieved, offering valuable insights for policymakers, healthcare professionals, and researchers in the field. Testing complete!
The coordinator agent transforms a collection of specialized AI agents into a cohesive, intelligent system capable of handling a wide range of queries with appropriate depth and efficiency. By implementing this architecture, we create a multi-agent system that can:
This approach represents a significant step forward in building AI systems that can adapt their workflow to the specific needs of each user query, delivering more relevant, efficient, and high-quality responses.
While Clearwater Analytics developed CWIC Flow as a sophisticated multi-agent system before frameworks like LangGraph became available, we continue to evaluate emerging technologies to enhance our capabilities. In the next article, we’ll explore how to build multi-agent systems using LangGraph, a framework that provides structured workflows similar to what we’ve already implemented in CWIC Flow.
As AI technology evolves, Clearwater remains committed to adopting innovations that enhance our ability to deliver actionable insights to our clients while maintaining our industry-leading standards for security, compliance, and accuracy.
Rany ElHousieny is an Engineering Leader at Clearwater Analytics with over 30 years of experience in software development, machine learning, and artificial intelligence. He has held leadership roles at Microsoft for two decades, where he led the NLP team at Microsoft Research and Azure AI, contributing to advancements in AI technologies. At Clearwater, Rany continues to leverage his extensive background to drive innovation in AI, helping teams solve complex challenges while maintaining a collaborative approach to leadership and problem-solving.