DEV Community

Cover image for Building Multi-Agent Systems with LangGraph Swarm: A New Approach to Agent Collaboration
Seenivasa Ramadurai
Seenivasa Ramadurai

Posted on

Building Multi-Agent Systems with LangGraph Swarm: A New Approach to Agent Collaboration

In the rapidly evolving landscape of AI agent architectures, two prominent paradigms have emerged: supervisor-based systems and swarm-based collaboration. Today, I want to dive into a practical implementation that highlights how LangGraph Swarm offers a more flexible approach to multi-agent collaboration compared to traditional supervisor models.

The Evolution of Multi-Agent Systems

Traditional multi-agent systems typically follow a hierarchical structure—a supervisor agent directs specialized agents, controlling the workflow. This approach works well for defined tasks with clear boundaries, but it can introduce bottlenecks and rigidity.

Enter LangGraph Swarm: a decentralized approach where agents operate with greater autonomy, observing a shared workspace and contributing when their expertise is relevant. This results in more emergent problem-solving capabilities.

A Practical Example: Question Answering, Science, and Translation

Let's examine a practical implementation of a LangGraph Swarm system that handles three distinct types of queries:

  1. General knowledge questions
  2. Scientific inquiries
  3. Language translation requests

The Architecture

Image description

Our system consists of three specialized agents:

# Create the agents with their respective tools and prompts
question_answering_agent = create_react_agent(
    model=llm,
    tools=[question_answering, create_handoff_tool(agent_name="science_agent"), create_handoff_tool(agent_name="translator_agent")],
    name="question_answering_agent",
    prompt=(
        "You are a general question answering agent. For any questions related to science, physics, chemistry, "
        "biology, astronomy, or other scientific topics, you MUST use the handoff tool to transfer the question "
        "to the science_agent. For any translation requests, transfer to translator_agent. "
        "Only answer general knowledge questions yourself."
    )
)

science_agent = create_react_agent(
    model=llm,
    tools=[science_agent, create_handoff_tool(agent_name="question_answering_agent"), create_handoff_tool(agent_name="translator_agent")],
    prompt=(
        "You are a science expert agent specializing in physics, chemistry, biology, astronomy, and all scientific topics. "
        "If a question is NOT related to science, use the handoff tool to transfer it to question_answering_agent. "
        "For translation requests, transfer to translator_agent. "
        "For scientific questions, provide detailed, accurate answers using scientific principles."
    ),
    name="science_agent"
)

translator_agent = create_react_agent(
    model=llm,
    tools=[translate_text, create_handoff_tool(agent_name="question_answering_agent"), create_handoff_tool(agent_name="science_agent")],
    prompt=(
        "You are a language translation agent. Your primary task is to help with translations..."
    ),
    name="translator_agent"
)
Enter fullscreen mode Exit fullscreen mode

Key Components of the Swarm Approach

What makes this implementation genuinely swarm-based rather than supervisor-based? Several key features:

  1. Direct Agent-to-Agent Handoffs: Each agent has handoff tools that allow it to pass requests to other agents when appropriate.

  2. Autonomous Decision Making: Agents independently determine when to hand off to another agent without instructions from a central controller.

  3. Shared Workspace: All agents operate in a shared environment where they can observe the current state of the conversation.

  4. Dynamic Routing: The system routes requests based on content recognition rather than predefined workflows.

# Initialize the supervisor and application
checkpoint = InMemorySaver()
supervisor = create_swarm(
    agents=[question_answering_agent, science_agent, translator_agent],
    default_active_agent="question_answering_agent",
)
app = supervisor.compile(checkpointer=checkpoint)
Enter fullscreen mode Exit fullscreen mode

The Benefits of Swarm-Based Collaboration

1. Emergent Problem Solving

In a swarm-based system, complex problems can be solved through the collaborative efforts of specialized agents without explicit coordination. For instance, a query that starts as a general question might evolve to include scientific aspects, and the system can smoothly transition between agents.

2. Reduced Bottlenecks

Unlike supervisor-based systems where all decisions must flow through a central node, swarm architectures allow direct agent-to-agent communication. This reduces potential bottlenecks and allows for greater parallelization.

3. Adaptability

Swarm systems can more easily adapt to unexpected inputs or queries that cross domain boundaries. If a request doesn't fit neatly into predefined categories, agents can collaborate to construct an appropriate response.

Practical Implementation Details

The system uses Azure OpenAI's models and incorporates several thoughtful design choices:

  1. Specialized Function Implementation: Each agent has a corresponding function that encapsulates its core functionality.

  2. Smart Parsing for Translation: The translation agent includes sophisticated logic to extract languages and text from various request formats.

def extract_language_and_text(request: str):
    """Extract target language and text from a translation request"""
    request = request.lower()

    # Common language patterns
    to_patterns = [" to ", " in ", " into "]

    # Try to find language in the request
    target_language = None
    text = request

    for pattern in to_patterns:
        if pattern in request:
            parts = request.split(pattern)
            if len(parts) == 2:
                text = parts[0]
                # Take everything after the pattern as language
                target_language = parts[1].strip()
                break

    # Clean up text by removing translation-related prefixes
    text = text.replace("translate", "").replace("say", "").strip()
    return text.strip(), target_language
Enter fullscreen mode Exit fullscreen mode
  1. Interactive Flow: The implementation includes a user-friendly interactive loop for continuous conversation.

Comparing Supervisor and Swarm Approaches

While both approaches have their merits, the implementation we've explored demonstrates why swarm-based systems can be more flexible:

Feature Supervisor Approach Swarm Approach
Control Flow Top-down, centralized Peer-to-peer, decentralized
Adaptability Requires predefined routing Emergent, dynamic routing
Scalability Limited by supervisor capacity Can scale with more agents
Decision Making Centralized in supervisor Distributed across agents
Implementation Complexity Simpler routing logic More complex agent interactions

Customizing LangGraph Swarm

LangGraph Swarm allows for extensive customization through two main approaches: modifying handoff tools and customizing agent implementations. Here's how you can adapt each aspect to create more specialized multi-agent systems:

Customizing Handoff Tools

Handoff tools are the mechanisms that allow agents to transfer control to other agents. By default, these are created using the create_handoff_tool function, but you can customize them in several ways:

1. Change Tool Names and Descriptions

The default handoff tools use generic names, but you can create more descriptive names and detailed descriptions to help the language model understand when to use them. For example, instead of a generic "handoff to science agent," you might create "consult physics specialist" or "refer to biology expert."

2. Add Tool Call Arguments

Standard handoff tools simply transfer control to another agent, but you can enhance them by adding arguments that the language model must provide. These arguments can include:

  • Task descriptions explaining what the next agent should do
  • Priority indicators for urgent requests
  • Context information about why the handoff is occurring
  • Specific questions or subtasks for the receiving agent

3. Modify Data Passed During Handoff

By default, handoff tools pass the complete message history to the next agent. You can customize this to:

  • Pass only recent or relevant messages
  • Filter out certain types of messages
  • Include additional context or instructions
  • Modify the content to emphasize particular aspects of the request

Customizing Agent Implementation

Beyond handoff tools, you can also customize how the agents themselves function:

1. Use Different Agent Types

Instead of using the standard ReAct agents, you can implement:

  • Planning agents that develop strategies before acting
  • Memory-enhanced agents that maintain context more effectively
  • Tool-specialized agents with domain-specific capabilities
  • Multi-step reasoning agents for complex problems

2. Enhance Agent Prompts

The instructions given to each agent significantly impact their behavior. You can customize prompts to:

  • Provide more specific guidelines on when to hand off tasks
  • Include examples of ideal responses for different scenarios
  • Set standards for the depth and format of answers
  • Define boundaries between agent responsibilities

3. Implement Specialized Knowledge

Each agent can be equipped with tools that provide domain-specific capabilities:

  • Research tools for scientific agents
  • Calculation tools for mathematical problems
  • Data analysis tools for statistical questions
  • Language resources for translation agents

4. Custom Memory and State Management

Agents can be customized to maintain and utilize different types of memory:

  • Short-term memory for immediate context
  • Long-term memory for recurring users or topics
  • Shared memory accessible across multiple agents
  • Specialized memory structures for particular domains

By thoughtfully customizing both handoff tools and agent implementations, you can create sophisticated multi-agent systems that efficiently route tasks based on complex criteria while maintaining the flexibility and emergent problem-solving capabilities that make swarm architectures powerful.

Complete code

"""
Multi-Agent System for Question Answering, Science, and Translation

This script implements a multi-agent system using LangGraph and Azure OpenAI that consists of:
1. Question Answering Agent - Handles general knowledge questions
2. Science Agent - Specializes in scientific topics
3. Translation Agent - Handles language translation requests

The system uses a supervisor to route requests to the appropriate agent based on the content.
Agents can hand off tasks to each other when a request better fits another agent's expertise.

Requirements:
- Azure OpenAI API key (set in environment variables)
- Python packages: langchain, langgraph, langgraph_swarm

Usage:
1. For general questions: Just ask normally
2. For science questions: Ask any science-related question
3. For translations: Use formats like:
   - "translate [text] to [language]"
   - "[text] in [language]"
   - "how do you say [text] in [language]"
"""

from langgraph_supervisor import create_supervisor
from dotenv import load_dotenv
from langchain_openai import AzureChatOpenAI
from langgraph.checkpoint.memory import InMemorySaver 
from langgraph.prebuilt import create_react_agent
from langgraph_swarm import create_handoff_tool, create_swarm
import os
load_dotenv()

# Initialize Azure OpenAI model
llm = AzureChatOpenAI(
    deployment_name="gpt-4o-mini",
    model="gpt-4o-mini",
    temperature=0,
    openai_api_version="2023-05-15",
    openai_api_key=os.getenv("AZURE_OPENAI_API_KEY"),
)

def question_answering(question: str):
    """General Question Answering Agent

    Handles non-scientific, general knowledge questions.
    Transfers science questions to science_agent and translation requests to translator_agent.

    Args:
        question (str): The user's question

    Returns:
        str: Response from the language model
    """
    response = llm.invoke(question)
    return response.content

def science_agent(question: str):
    """Science Specialist Agent

    Handles questions about physics, chemistry, biology, astronomy, and other scientific topics.
    Transfers non-science questions to question_answering_agent and translation requests to translator_agent.

    Args:
        question (str): The science-related question

    Returns:
        str: Scientific explanation or answer
    """
    response = llm.invoke(question)
    return response.content

def extract_language_and_text(request: str):
    """Extract target language and text from a translation request

    Parses the user's request to identify:
    1. The text to be translated
    2. The target language for translation

    Handles various formats:
    - "translate X to Y"
    - "X in Y"
    - "X into Y"

    Args:
        request (str): The user's translation request

    Returns:
        tuple: (text_to_translate, target_language)
    """
    request = request.lower()

    # Common language patterns
    to_patterns = [" to ", " in ", " into "]

    # Try to find language in the request
    target_language = None
    text = request

    for pattern in to_patterns:
        if pattern in request:
            parts = request.split(pattern)
            if len(parts) == 2:
                text = parts[0]
                # Take everything after the pattern as language
                target_language = parts[1].strip()
                break

    # Clean up text by removing translation-related prefixes
    text = text.replace("translate", "").replace("say", "").strip()
    return text.strip(), target_language

def translate_text(request: str):
    """Translation Handler

    Processes translation requests in various formats:
    1. Direct translation with language: "translate X to Y"
    2. Help requests: "help with translation"
    3. Text-only requests: Prompts for target language

    Args:
        request (str): The translation request or text to translate

    Returns:
        str: Either translation instructions or the translated text
    """
    # If it's a help request, provide format guidance
    if any(x in request.lower() for x in ["help with", "can you", "need translation", "translate something"]):
        return "I can help you translate. Please provide what you want to translate using this format:\n'translate [your text] to [language]' or '[text] in [language]'"

    # Try to extract language and text
    text, target_language = extract_language_and_text(request)

    # If language wasn't found in the request, ask for it
    if not target_language:
        target_language = input("Which language would you like this translated to? ")

    prompt = f"Translate the following text to {target_language}:\n{text}"
    response = llm.invoke(prompt)
    return response.content

# Create the agents with their respective tools and prompts
question_answering_agent = create_react_agent(
    model=llm,
    tools=[question_answering, create_handoff_tool(agent_name="science_agent"), create_handoff_tool(agent_name="translator_agent")],
    name="question_answering_agent",
    prompt=(
        "You are a general question answering agent. For any questions related to science, physics, chemistry, "
        "biology, astronomy, or other scientific topics, you MUST use the handoff tool to transfer the question "
        "to the science_agent. For any translation requests, transfer to translator_agent. "
        "Only answer general knowledge questions yourself."
    )
)

science_agent = create_react_agent(
    model=llm,
    tools=[science_agent, create_handoff_tool(agent_name="question_answering_agent"), create_handoff_tool(agent_name="translator_agent")],
    prompt=(
        "You are a science expert agent specializing in physics, chemistry, biology, astronomy, and all scientific topics. "
        "If a question is NOT related to science, use the handoff tool to transfer it to question_answering_agent. "
        "For translation requests, transfer to translator_agent. "
        "For scientific questions, provide detailed, accurate answers using scientific principles."
    ),
    name="science_agent"
)

translator_agent = create_react_agent(
    model=llm,
    tools=[translate_text, create_handoff_tool(agent_name="question_answering_agent"), create_handoff_tool(agent_name="science_agent")],
    prompt=(
        "You are a language translation agent. Your primary task is to help with translations:\n"
        "1. When user asks for help with translation, show them the format examples\n"
        "2. When user provides text with language (e.g., 'translate hello to spanish' or 'hello in spanish'), translate immediately\n"
        "3. When user provides only text, ask for the target language\n"
        "4. For questions about languages or translation in general, answer them directly\n"
        "5. For science questions, transfer to science_agent\n"
        "6. For other general questions, transfer to question_answering_agent\n"
        "Always aim for a natural single-step translation process."
    ),
    name="translator_agent"
)

# Initialize the supervisor and application
checkpoint = InMemorySaver()
supervisor = create_swarm(
    agents=[question_answering_agent, science_agent, translator_agent],
    default_active_agent="question_answering_agent",
)
app = supervisor.compile(checkpointer=checkpoint)

# Save the workflow diagram
image = app.get_graph().draw_mermaid_png()
with open("swarm.png", "wb") as f:
    f.write(image)

# Configuration for the conversation thread
config = {"configurable": {"thread_id": "1"}}

# Main interaction loop
while True:
    user_input = input("\nEnter your request (or 'exit' to quit): ")

    if user_input.lower() == 'exit':
        print("Goodbye!")
        break

    result = app.invoke(
        {"messages": [{
            "role": "user",
            "content": user_input
        }]},
        config,
    )

    # Display the response
    for m in result["messages"]:
        print(m.pretty_print())

Enter fullscreen mode Exit fullscreen mode

Testing the Agents

(sreenisub) (base) sreenir@Seenivasaragavans-MacBook-Pro sreeni-sup-agent % /Users/sreenir/sreeni-sup-agent/sreenisub/bin/python /
Users/sreenir/sreeni-sup-agent/swarm.py

Enter your request (or 'exit' to quit): i need help with translation
================================ Human Message =================================

i need help with translation
None
================================== Ai Message ==================================
Name: question_answering_agent
Tool Calls:
transfer_to_translator_agent (call_9nlM29pvddlic06baF5vB01H)
Call ID: call_9nlM29pvddlic06baF5vB01H
Args:
None
================================= Tool Message =================================
Name: transfer_to_translator_agent
Successfully transferred to translator_agent
None
================================== Ai Message ==================================
Name: translator_agent

Please provide the text you would like to translate and specify the target language. Here are some format examples you can use:

  1. "Translate 'hello' to Spanish."
  2. "'hello' in Spanish."
  3. "How do you say 'thank you' in French?" None

Enter your request (or 'exit' to quit): sreeni how are you doing to tamil
================================ Human Message =================================

i need help with translation
None
================================== Ai Message ==================================
Name: question_answering_agent
Tool Calls:
transfer_to_translator_agent (call_9nlM29pvddlic06baF5vB01H)
Call ID: call_9nlM29pvddlic06baF5vB01H
Args:
None
================================= Tool Message =================================
Name: transfer_to_translator_agent

Successfully transferred to translator_agent
None
================================== Ai Message ==================================
Name: translator_agent

Please provide the text you would like to translate and specify the target language. Here are some format examples you can use:

  1. "Translate 'hello' to Spanish."
  2. "'hello' in Spanish."
  3. "How do you say 'thank you' in French?" None ================================ Human Message =================================

sreeni how are you doing to tamil
None
================================== Ai Message ==================================
Name: translator_agent
Tool Calls:
translate_text (call_IRMlcnhS2qJpv43NfsSLqhWU)
Call ID: call_IRMlcnhS2qJpv43NfsSLqhWU
Args:
request: sreeni how are you doing in tamil
None
================================= Tool Message =================================
Name: translate_text

The translation of "Sreeni, how are you doing?" in Tamil is: "ஸ்ரீனி, நீ எப்படி இருக்கிறாய்?"
None
================================== Ai Message ==================================
Name: translator_agent

The translation of "Sreeni, how are you doing?" in Tamil is: "ஸ்ரீனி, நீ எப்படி இருக்கிறாய்?"
None

Enter your request (or 'exit' to quit): who is indian pm
================================ Human Message =================================

i need help with translation
None
================================== Ai Message ==================================
Name: question_answering_agent
Tool Calls:
transfer_to_translator_agent (call_9nlM29pvddlic06baF5vB01H)
Call ID: call_9nlM29pvddlic06baF5vB01H
Args:
None
================================= Tool Message =================================
Name: transfer_to_translator_agent

Successfully transferred to translator_agent
None
================================== Ai Message ==================================
Name: translator_agent

Please provide the text you would like to translate and specify the target language. Here are some format examples you can use:

  1. "Translate 'hello' to Spanish."
  2. "'hello' in Spanish."
  3. "How do you say 'thank you' in French?" None ================================ Human Message =================================

sreeni how are you doing to tamil
None
================================== Ai Message ==================================
Name: translator_agent
Tool Calls:
translate_text (call_IRMlcnhS2qJpv43NfsSLqhWU)
Call ID: call_IRMlcnhS2qJpv43NfsSLqhWU
Args:
request: sreeni how are you doing in tamil
None
================================= Tool Message =================================
Name: translate_text

The translation of "Sreeni, how are you doing?" in Tamil is: "ஸ்ரீனி, நீ எப்படி இருக்கிறாய்?"
None
================================== Ai Message ==================================
Name: translator_agent

The translation of "Sreeni, how are you doing?" in Tamil is: "ஸ்ரீனி, நீ எப்படி இருக்கிறாய்?"
None
================================ Human Message =================================

who is indian pm **
None
================================== Ai Message ==================================
Name: translator_agent
Tool Calls:
transfer_to_question_answering_agent (call_MkZ7TIi7EU5BY0JKHwT2NdbA)
Call ID: call_MkZ7TIi7EU5BY0JKHwT2NdbA
Args:
None
================================= Tool Message =================================
**Name: transfer_to_question_answering_agent

Successfully transferred to question_answering_agent
None
================================== Ai Message ==================================
Name: question_answering_agent
Tool Calls:
question_answering (call_hGXdhxzSHrBfG8x5R7MeNVLU)
Call ID: call_hGXdhxzSHrBfG8x5R7MeNVLU
Args:
question: Who is the current Prime Minister of India?
None
================================= Tool Message =================================
Name: question_answering

As of my last update in October 2023, the Prime Minister of India is Narendra Modi. He has been in office since May 26, 2014. Please verify with up-to-date sources to confirm if this information is still current.
None
================================== Ai Message ==================================
Name: question_answering_agent

As of my last update in October 2023, the Prime Minister of India is Narendra Modi. He has been in office since May 26, 2014. Please verify with up-to-date sources to confirm if this information is still current.
None

Enter your request (or 'exit' to quit): what is name for ch4

================================ Human Message =================================

i need help with translation
None
================================== Ai Message ==================================
Name: question_answering_agent
Tool Calls:
transfer_to_translator_agent (call_9nlM29pvddlic06baF5vB01H)
Call ID: call_9nlM29pvddlic06baF5vB01H
Args:
None
================================= Tool Message =================================
Name: transfer_to_translator_agent

Successfully transferred to translator_agent
None
================================== Ai Message ==================================
Name: translator_agent

Please provide the text you would like to translate and specify the target language. Here are some format examples you can use:

  1. "Translate 'hello' to Spanish."
  2. "'hello' in Spanish."
  3. "How do you say 'thank you' in French?" None ================================ Human Message =================================

sreeni how are you doing to tamil
None
================================== Ai Message ==================================
Name: translator_agent
Tool Calls:
translate_text (call_IRMlcnhS2qJpv43NfsSLqhWU)
Call ID: call_IRMlcnhS2qJpv43NfsSLqhWU
Args:
request: sreeni how are you doing in tamil
None
================================= Tool Message =================================
Name: translate_text

The translation of "Sreeni, how are you doing?" in Tamil is: "ஸ்ரீனி, நீ எப்படி இருக்கிறாய்?"
None
================================== Ai Message ==================================
Name: translator_agent

The translation of "Sreeni, how are you doing?" in Tamil is: "ஸ்ரீனி, நீ எப்படி இருக்கிறாய்?"
None
================================ Human Message =================================

who is indian pm
None
================================== Ai Message ==================================
Name: translator_agent
Tool Calls:
transfer_to_question_answering_agent (call_MkZ7TIi7EU5BY0JKHwT2NdbA)
Call ID: call_MkZ7TIi7EU5BY0JKHwT2NdbA
Args:
None
================================= Tool Message =================================
Name: transfer_to_question_answering_agent

Successfully transferred to question_answering_agent
None
================================== Ai Message ==================================
Name: question_answering_agent
Tool Calls:
question_answering (call_hGXdhxzSHrBfG8x5R7MeNVLU)
Call ID: call_hGXdhxzSHrBfG8x5R7MeNVLU
Args:
question: Who is the current Prime Minister of India?
None
================================= Tool Message =================================
Name: question_answering

As of my last update in October 2023, the Prime Minister of India is Narendra Modi. He has been in office since May 26, 2014. Please verify with up-to-date sources to confirm if this information is still current.
None
================================== Ai Message ==================================
Name: question_answering_agent

As of my last update in October 2023, the Prime Minister of India is Narendra Modi. He has been in office since May 26, 2014. Please verify with up-to-date sources to confirm if this information is still current.
None
================================ Human Message =================================

what is name for ch4
None
================================== Ai Message ==================================
Name: question_answering_agent
Tool Calls:
question_answering (call_GaMaOibylYuZntXbH9dlOeHw)
Call ID: call_GaMaOibylYuZntXbH9dlOeHw
Args:
question: What is the name for CH4?
None
================================= Tool Message =================================
Name: question_answering

The chemical name for CH₄ is methane.
None
================================== Ai Message ==================================
Name: question_answering_agent

The chemical name for CH₄ is methane.
None

Enter your request (or 'exit' to quit): in science what is force
================================ Human Message =================================

i need help with translation
None
================================== Ai Message ==================================
Name: question_answering_agent
Tool Calls:
transfer_to_translator_agent (call_9nlM29pvddlic06baF5vB01H)
Call ID: call_9nlM29pvddlic06baF5vB01H
Args:
None
================================= Tool Message =================================
Name: transfer_to_translator_agent

Successfully transferred to translator_agent
None
================================== Ai Message ==================================
Name: translator_agent

Please provide the text you would like to translate and specify the target language. Here are some format examples you can use:

  1. "Translate 'hello' to Spanish."
  2. "'hello' in Spanish."
  3. "How do you say 'thank you' in French?" None ================================ Human Message =================================

sreeni how are you doing to tamil
None
================================== Ai Message ==================================
Name: translator_agent
Tool Calls:
translate_text (call_IRMlcnhS2qJpv43NfsSLqhWU)
Call ID: call_IRMlcnhS2qJpv43NfsSLqhWU
Args:
request: sreeni how are you doing in tamil
None
================================= Tool Message =================================
Name: translate_text

The translation of "Sreeni, how are you doing?" in Tamil is: "ஸ்ரீனி, நீ எப்படி இருக்கிறாய்?"
None
================================== Ai Message ==================================
Name: translator_agent

The translation of "Sreeni, how are you doing?" in Tamil is: "ஸ்ரீனி, நீ எப்படி இருக்கிறாய்?"
None
================================ Human Message =================================

who is indian pm
None
================================== Ai Message ==================================
Name: translator_agent
Tool Calls:
transfer_to_question_answering_agent (call_MkZ7TIi7EU5BY0JKHwT2NdbA)
Call ID: call_MkZ7TIi7EU5BY0JKHwT2NdbA
Args:
None
================================= Tool Message =================================
Name: transfer_to_question_answering_agent

Successfully transferred to question_answering_agent
None
================================== Ai Message ==================================
Name: question_answering_agent
Tool Calls:
question_answering (call_hGXdhxzSHrBfG8x5R7MeNVLU)
Call ID: call_hGXdhxzSHrBfG8x5R7MeNVLU
Args:
question: Who is the current Prime Minister of India?
None
================================= Tool Message =================================
Name: question_answering

As of my last update in October 2023, the Prime Minister of India is Narendra Modi. He has been in office since May 26, 2014. Please verify with up-to-date sources to confirm if this information is still current.
None
================================== Ai Message ==================================
Name: question_answering_agent

As of my last update in October 2023, the Prime Minister of India is Narendra Modi. He has been in office since May 26, 2014. Please verify with up-to-date sources to confirm if this information is still current.
None
================================ Human Message =================================

what is name for ch4
None
================================== Ai Message ==================================
Name: question_answering_agent
Tool Calls:
question_answering (call_GaMaOibylYuZntXbH9dlOeHw)
Call ID: call_GaMaOibylYuZntXbH9dlOeHw
Args:
question: What is the name for CH4?
None
================================= Tool Message =================================
Name: question_answering

The chemical name for CH₄ is methane.
None
================================== Ai Message ==================================
Name: question_answering_agent

The chemical name for CH₄ is methane.
None
================================ Human Message =================================

in science what is force
None
================================== Ai Message ==================================
Name: question_answering_agent
Tool Calls:
transfer_to_science_agent (call_rGwAqYoK6otlB433ykkE6Vn9)
Call ID: call_rGwAqYoK6otlB433ykkE6Vn9
Args:
None
================================= Tool Message =================================
Name: transfer_to_science_agent

Successfully transferred to science_agent
None
================================== Ai Message ==================================
Name: science_agent
Tool Calls:
science_agent (call_Qr7XbhGhtuo4sQccTD5NmU1R)
Call ID: call_Qr7XbhGhtuo4sQccTD5NmU1R
Args:
question: What is force in science?
None
================================= Tool Message =================================
Name: science_agent
In science, force is defined as an interaction that causes an object to change its velocity, which includes starting, stopping, or changing direction. It is a vector quantity, meaning it has both magnitude and direction. The standard unit of force in the International System of Units (SI) is the newton (N).

Forces can arise from various interactions, such as:

  1. Gravitational Force: The attraction between two masses, such as the Earth and an object.
  2. Electromagnetic Force: The interaction between charged particles, which can be attractive or repulsive.
  3. Nuclear Force: The force that holds protons and neutrons together in an atomic nucleus.
  4. Frictional Force: The resistance that one surface or object encounters when moving over another.
  5. Tension Force: The force transmitted through a string, rope, or cable when it is pulled tight.

According to Newton's second law of motion, the relationship between force (F), mass (m), and acceleration (a) is given by the equation:

[ F = m \cdot a ]

This means that the force acting on an object is equal to the mass of the object multiplied by its acceleration. This fundamental concept helps to explain how forces affect the motion of objects in various contexts.
None
================================== Ai Message ==================================
*Name: science_agent
*

In science, force is defined as an interaction that causes an object to change its velocity, which includes starting, stopping, or changing direction. It is a vector quantity, meaning it has both magnitude and direction. The standard unit of force in the International System of Units (SI) is the newton (N).

Forces can arise from various interactions, such as:

  1. Gravitational Force: The attraction between two masses, such as the Earth and an object.
  2. Electromagnetic Force: The interaction between charged particles, which can be attractive or repulsive.
  3. Nuclear Force: The force that holds protons and neutrons together in an atomic nucleus.
  4. Frictional Force: The resistance that one surface or object encounters when moving over another.
  5. Tension Force: The force transmitted through a string, rope, or cable when it is pulled tight.

According to Newton's second law of motion, the relationship between force (F), mass (m), and acceleration (a) is given by the equation:

[ F = m \cdot a ]

This means that the force acting on an object is equal to the mass of the object multiplied by its acceleration. This fundamental concept helps to explain how forces affect the motion of objects in various contexts.
None

Enter your request (or 'exit' to quit):

Conclusion

LangGraph Swarm represents a significant advancement in how we approach multi-agent systems. By allowing agents to collaborate in a more decentralized fashion, we can build systems that better handle the complexity and ambiguity inherent in real-world language tasks.

This implementation demonstrates how three specialized agents can work together seamlessly, routing requests appropriately without a rigid hierarchical structure. The result is a more flexible, adaptable, and potentially more powerful approach to multi-agent systems.

For developers looking to build their own multi-agent systems, LangGraph Swarm offers a compelling alternative to traditional supervisor-based architectures, particularly for applications where problem boundaries are fluid and collaborative problem-solving is essential.

Thanks
Sreeni Ramadorai

Top comments (0)