{"id":9887,"library":"langgraph-swarm","title":"LangGraph Swarm","description":"LangGraph Swarm provides a high-level API for creating and managing a swarm of AI agents, making it easier to build complex multi-agent systems using LangGraph. It is designed to abstract away common patterns in multi-agent orchestration. The current version is 0.1.0, and releases are expected to follow LangGraph's development cadence or as significant features are added.","status":"active","version":"0.1.0","language":"en","source_language":"en","source_url":"https://github.com/langgraph-ai/langgraph-swarm","tags":["langgraph","multi-agent","swarm","ai-agents","orchestration"],"install":[{"cmd":"pip install langgraph-swarm","lang":"bash","label":"Install LangGraph Swarm"}],"dependencies":[{"reason":"Core dependency for building agent graphs.","package":"langgraph","optional":false},{"reason":"Provides core LLM integrations and tools.","package":"langchain","optional":false},{"reason":"Commonly used for LLM interaction in examples and real-world applications.","package":"openai","optional":true}],"imports":[{"symbol":"AgentSwarm","correct":"from langgraph_swarm import AgentSwarm"},{"symbol":"AgentNode","correct":"from langgraph_swarm import AgentNode"},{"symbol":"SwarmGraph","correct":"from langgraph_swarm import SwarmGraph"}],"quickstart":{"code":"import os\nfrom langchain_openai import ChatOpenAI\nfrom langgraph_swarm import AgentSwarm, AgentNode, SwarmGraph\nfrom langgraph_swarm.nodes import LLMNode\n\n# Set your OpenAI API key\nos.environ[\"OPENAI_API_KEY\"] = os.environ.get(\"OPENAI_API_KEY\", \"\")\n\nif not os.environ[\"OPENAI_API_KEY\"]:\n    print(\"Warning: OPENAI_API_KEY environment variable not set. Skipping quickstart.\")\nelse:\n    llm = ChatOpenAI(model=\"gpt-4o\", temperature=0)\n\n    # Define the agents (nodes in the swarm)\n    research_agent = AgentNode(\n        name=\"Researcher\",\n        description=\"Researches given topics and provides factual information.\",\n        llm=llm, # Example LLM, replace with actual agent logic if needed\n        tools=[]\n    )\n    writer_agent = AgentNode(\n        name=\"Writer\",\n        description=\"Writes creative content based on research.\",\n        llm=llm,\n        tools=[]\n    )\n\n    # Create a SwarmGraph\n    graph = SwarmGraph()\n\n    # Add agents to the graph\n    graph.add_agent(research_agent)\n    graph.add_agent(writer_agent)\n\n    # Define the workflow (how agents interact)\n    graph.add_workflow(\n        entry_point=research_agent.name,\n        edges={research_agent.name: writer_agent.name},\n        # The writer agent should only activate if research is complete\n        # Add conditional logic or specific messages to trigger in a real scenario\n        exit_point=writer_agent.name\n    )\n\n    # Create the AgentSwarm instance\n    swarm = AgentSwarm(graph=graph, llm=llm) # LLM for internal swarm coordination if needed\n\n    # Invoke the swarm with an initial task\n    task = \"Write a short summary about the benefits of multi-agent systems.\"\n    print(f\"\\n--- Invoking swarm with task: '{task}' ---\\n\")\n    result = swarm.invoke({\"messages\": [(\"user\", task)]})\n\n    print(\"\\n--- Swarm execution complete ---\\n\")\n    print(f\"Final result: {result}\")\n\n    # Expected output structure might vary, but should contain the agents' messages.\n    # print(result[\"messages\"][-1].content) # Example access to final message","lang":"python","description":"This quickstart demonstrates how to create a simple multi-agent swarm with two agents (Researcher, Writer) using `AgentNode` and orchestrate their interaction using `SwarmGraph`. It initializes an `AgentSwarm` and invokes it with a task, showing how to set up a basic workflow. Ensure your `OPENAI_API_KEY` is set in your environment for this example to run."},"warnings":[{"fix":"Refer to the official GitHub repository for the latest documentation and examples before upgrading. Pin exact versions in `requirements.txt` to avoid unexpected breakage.","message":"As a new library (v0.1.0), the API for LangGraph Swarm is subject to rapid change. Breaking changes may occur in minor versions as the project evolves and stabilizes.","severity":"breaking","affected_versions":"0.1.x"},{"fix":"Familiarize yourself with LangGraph's documentation and examples before diving deep into `langgraph-swarm`. The official LangGraph documentation is the best starting point.","message":"A solid understanding of LangGraph core concepts (nodes, edges, state, graph compilation) is essential for effective use of `langgraph-swarm`. This library builds on top of LangGraph.","severity":"gotcha","affected_versions":"All"},{"fix":"Ensure all required API keys are set in your environment before running applications that use remote LLMs. For example, `export OPENAI_API_KEY='your_key'` or use `.env` files with `python-dotenv`.","message":"Agent nodes often require LLM instances (e.g., `ChatOpenAI`). For remote LLMs, appropriate API keys (e.g., `OPENAI_API_KEY`) must be set as environment variables.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run `pip install langgraph-swarm` to install the library.","cause":"The `langgraph-swarm` library has not been installed in your Python environment.","error":"ModuleNotFoundError: No module named 'langgraph_swarm'"},{"fix":"Set the `OPENAI_API_KEY` environment variable (e.g., `export OPENAI_API_KEY='your_key'`) or pass it directly to the LLM constructor if supported.","cause":"You are using `langchain_openai.ChatOpenAI` or similar LLM without providing the necessary API key.","error":"ValueError: Missing `OPENAI_API_KEY` environment variable."},{"fix":"Ensure you pass `AgentNode` instances directly, not just their string `name` attributes, when methods expect `AgentNode` objects. Example: `graph.add_agent(my_agent_instance)` instead of `graph.add_agent(my_agent_instance.name)`.","cause":"You're trying to add agents or define workflows using agent names (strings) where `AgentNode` instances are expected. The `add_agent` and `add_workflow` methods typically expect actual `AgentNode` objects.","error":"TypeError: 'str' object cannot be interpreted as an AgentNode"}]}