langgraph-supervisor


Namelanggraph-supervisor JSON
Version 0.0.1 PyPI version JSON
download
home_pageNone
SummaryAn implementation of a supervisor multi-agent architecture using LangGraph
upload_time2025-02-07 19:00:03
maintainerNone
docs_urlNone
authorNone
requires_python>=3.11
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 🤖 LangGraph Multi-Agent Supervisor

A Python library for creating hierarchical multi-agent systems using [LangGraph](https://github.com/langchain-ai/langgraph). Hierarchical systems are a type of [multi-agent](https://langchain-ai.github.io/langgraph/concepts/multi_agent) architecture where specialized agents are coordinated by a central **supervisor** agent. The supervisor controls all communication flow and task delegation, making decisions about which agent to invoke based on the current context and task requirements.

## Features

- 🤖 **Create a supervisor agent** to orchestrate multiple specialized agents
- 🔄 **Support for both router and orchestrator patterns**
- 🛠️ **Tool-based agent handoff mechanism** for communication between agents
- 📝 **Flexible message history management** for conversation control

This library is built on top of [LangGraph](https://github.com/langchain-ai/langgraph), a powerful framework for building agent applications, and comes with out-of-box support for [streaming](https://langchain-ai.github.io/langgraph/how-tos/#streaming), [short-term and long-term memory](https://langchain-ai.github.io/langgraph/concepts/memory/) and [human-in-the-loop](https://langchain-ai.github.io/langgraph/concepts/human_in_the_loop/)

## Installation

```bash
pip install langgraph-supervisor
```

## Quickstart

Here's a simple example of a supervisor managing two specialized agents:

```bash
pip install langgraph-supervisor langchain-openai

export OPENAI_API_KEY=<your_api_key>
```

```python
from langchain_openai import ChatOpenAI

from langgraph_supervisor import create_supervisor
from langgraph.prebuilt import create_react_agent

model = ChatOpenAI(model="gpt-4o")

# Create specialized agents

def add(a: float, b: float) -> float:
    """Add two numbers."""
    return a + b

def multiply(a: float, b: float) -> float:
    """Multiply two numbers."""
    return a * b

def web_search(query: str) -> str:
    """Search the web for information."""
    return (
        "Here are the headcounts for each of the FAANG companies in 2024:\n"
        "1. **Facebook (Meta)**: 67,317 employees.\n"
        "2. **Apple**: 164,000 employees.\n"
        "3. **Amazon**: 1,551,000 employees.\n"
        "4. **Netflix**: 14,000 employees.\n"
        "5. **Google (Alphabet)**: 181,269 employees."
    )

math_agent = create_react_agent(
    model=model,
    tools=[add, multiply],
    name="math_expert",
    prompt="You are a math expert. Always use one tool at a time."
)

research_agent = create_react_agent(
    model=model,
    tools=[web_search],
    name="research_expert",
    prompt="You are a world class researcher with access to web search. Do not do any math."
)

# Create supervisor workflow
workflow = create_supervisor(
    [research_agent, math_agent],
    model=model,
    prompt="You are a team supervisor managing a research expert and a math expert.",
)

# Compile and run
app = workflow.compile()
result = app.invoke({
    "messages": [
        {
            "role": "user",
            "content": "what's the combined headcount of the FAANG companies in 2024?"
        }
    ]
})
```

## Agent Interaction Patterns

### Orchestrator Pattern

In orchestrator mode (`is_router=False`), agents always return control to the supervisor. The supervisor can then decide who to call next, or respond to the user.

```python
orchestrator = create_supervisor(
    [agent1, agent2],
    is_router=False,
    ...
)
```

### Router Pattern

In router mode (`is_router=True`), agents can respond directly to the user. The supervisor just routes the user's message to the appropriate agent.

```python
router = create_supervisor(
    [agent1, agent2],
    is_router=True,
    ...
)
```

## Message History Management

You can control how agent messages are added to the overall conversation history of the multi-agent system:

Include full message history from an agent:

```python
workflow = create_supervisor(
    agents=[agent1, agent2],
    agent_output_mode="full_history"
)
```

Include only the final agent response:

```python
workflow = create_supervisor(
    agents=[agent1, agent2],
    agent_output_mode="last_message"
)
```

## Multi-level Hierarchies

You can create multi-level hierarchical systems by creating a supervisor that manages multiple supervisors.

```python
research_team = create_supervisor(
    [research_agent, math_agent],
    model=model,
).compile(name="research_team")

writing_team = create_supervisor(
    [writing_agent, publishing_agent],
    model=model,
).compile(name="writing_team")

top_level_supervisor = create_supervisor(
    [research_team, writing_team],
    model=model,
).compile(name="top_level_supervisor")
```
            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "langgraph-supervisor",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "Vadym Barda <19161700+vbarda@users.noreply.github.com >",
    "download_url": "https://files.pythonhosted.org/packages/e6/05/702f0d7583fa1d28f6a4936b7e40c9a392fbc6617f0afb353bb50691e142/langgraph_supervisor-0.0.1.tar.gz",
    "platform": null,
    "description": "# \ud83e\udd16 LangGraph Multi-Agent Supervisor\n\nA Python library for creating hierarchical multi-agent systems using [LangGraph](https://github.com/langchain-ai/langgraph). Hierarchical systems are a type of [multi-agent](https://langchain-ai.github.io/langgraph/concepts/multi_agent) architecture where specialized agents are coordinated by a central **supervisor** agent. The supervisor controls all communication flow and task delegation, making decisions about which agent to invoke based on the current context and task requirements.\n\n## Features\n\n- \ud83e\udd16 **Create a supervisor agent** to orchestrate multiple specialized agents\n- \ud83d\udd04 **Support for both router and orchestrator patterns**\n- \ud83d\udee0\ufe0f **Tool-based agent handoff mechanism** for communication between agents\n- \ud83d\udcdd **Flexible message history management** for conversation control\n\nThis library is built on top of [LangGraph](https://github.com/langchain-ai/langgraph), a powerful framework for building agent applications, and comes with out-of-box support for [streaming](https://langchain-ai.github.io/langgraph/how-tos/#streaming), [short-term and long-term memory](https://langchain-ai.github.io/langgraph/concepts/memory/) and [human-in-the-loop](https://langchain-ai.github.io/langgraph/concepts/human_in_the_loop/)\n\n## Installation\n\n```bash\npip install langgraph-supervisor\n```\n\n## Quickstart\n\nHere's a simple example of a supervisor managing two specialized agents:\n\n```bash\npip install langgraph-supervisor langchain-openai\n\nexport OPENAI_API_KEY=<your_api_key>\n```\n\n```python\nfrom langchain_openai import ChatOpenAI\n\nfrom langgraph_supervisor import create_supervisor\nfrom langgraph.prebuilt import create_react_agent\n\nmodel = ChatOpenAI(model=\"gpt-4o\")\n\n# Create specialized agents\n\ndef add(a: float, b: float) -> float:\n    \"\"\"Add two numbers.\"\"\"\n    return a + b\n\ndef multiply(a: float, b: float) -> float:\n    \"\"\"Multiply two numbers.\"\"\"\n    return a * b\n\ndef web_search(query: str) -> str:\n    \"\"\"Search the web for information.\"\"\"\n    return (\n        \"Here are the headcounts for each of the FAANG companies in 2024:\\n\"\n        \"1. **Facebook (Meta)**: 67,317 employees.\\n\"\n        \"2. **Apple**: 164,000 employees.\\n\"\n        \"3. **Amazon**: 1,551,000 employees.\\n\"\n        \"4. **Netflix**: 14,000 employees.\\n\"\n        \"5. **Google (Alphabet)**: 181,269 employees.\"\n    )\n\nmath_agent = create_react_agent(\n    model=model,\n    tools=[add, multiply],\n    name=\"math_expert\",\n    prompt=\"You are a math expert. Always use one tool at a time.\"\n)\n\nresearch_agent = create_react_agent(\n    model=model,\n    tools=[web_search],\n    name=\"research_expert\",\n    prompt=\"You are a world class researcher with access to web search. Do not do any math.\"\n)\n\n# Create supervisor workflow\nworkflow = create_supervisor(\n    [research_agent, math_agent],\n    model=model,\n    prompt=\"You are a team supervisor managing a research expert and a math expert.\",\n)\n\n# Compile and run\napp = workflow.compile()\nresult = app.invoke({\n    \"messages\": [\n        {\n            \"role\": \"user\",\n            \"content\": \"what's the combined headcount of the FAANG companies in 2024?\"\n        }\n    ]\n})\n```\n\n## Agent Interaction Patterns\n\n### Orchestrator Pattern\n\nIn orchestrator mode (`is_router=False`), agents always return control to the supervisor. The supervisor can then decide who to call next, or respond to the user.\n\n```python\norchestrator = create_supervisor(\n    [agent1, agent2],\n    is_router=False,\n    ...\n)\n```\n\n### Router Pattern\n\nIn router mode (`is_router=True`), agents can respond directly to the user. The supervisor just routes the user's message to the appropriate agent.\n\n```python\nrouter = create_supervisor(\n    [agent1, agent2],\n    is_router=True,\n    ...\n)\n```\n\n## Message History Management\n\nYou can control how agent messages are added to the overall conversation history of the multi-agent system:\n\nInclude full message history from an agent:\n\n```python\nworkflow = create_supervisor(\n    agents=[agent1, agent2],\n    agent_output_mode=\"full_history\"\n)\n```\n\nInclude only the final agent response:\n\n```python\nworkflow = create_supervisor(\n    agents=[agent1, agent2],\n    agent_output_mode=\"last_message\"\n)\n```\n\n## Multi-level Hierarchies\n\nYou can create multi-level hierarchical systems by creating a supervisor that manages multiple supervisors.\n\n```python\nresearch_team = create_supervisor(\n    [research_agent, math_agent],\n    model=model,\n).compile(name=\"research_team\")\n\nwriting_team = create_supervisor(\n    [writing_agent, publishing_agent],\n    model=model,\n).compile(name=\"writing_team\")\n\ntop_level_supervisor = create_supervisor(\n    [research_team, writing_team],\n    model=model,\n).compile(name=\"top_level_supervisor\")\n```",
    "bugtrack_url": null,
    "license": null,
    "summary": "An implementation of a supervisor multi-agent architecture using LangGraph",
    "version": "0.0.1",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "9c5984998ebf1077d8369485ea548a7230e4d057ba988ccdb946c981f54d0414",
                "md5": "57323182ccaad847e9e616db5c044fee",
                "sha256": "910354de37d442d86e69e5d2830feba622f586243f2648aa21ede9fdfb220b3f"
            },
            "downloads": -1,
            "filename": "langgraph_supervisor-0.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "57323182ccaad847e9e616db5c044fee",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 7016,
            "upload_time": "2025-02-07T19:00:01",
            "upload_time_iso_8601": "2025-02-07T19:00:01.175924Z",
            "url": "https://files.pythonhosted.org/packages/9c/59/84998ebf1077d8369485ea548a7230e4d057ba988ccdb946c981f54d0414/langgraph_supervisor-0.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "e605702f0d7583fa1d28f6a4936b7e40c9a392fbc6617f0afb353bb50691e142",
                "md5": "727781f1c3330406c7bac003fa9fb688",
                "sha256": "cdf7b4f2e68838b96bbb039862e1ccf57623adf408590c10d84033e58ba3d55c"
            },
            "downloads": -1,
            "filename": "langgraph_supervisor-0.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "727781f1c3330406c7bac003fa9fb688",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 5555,
            "upload_time": "2025-02-07T19:00:03",
            "upload_time_iso_8601": "2025-02-07T19:00:03.571859Z",
            "url": "https://files.pythonhosted.org/packages/e6/05/702f0d7583fa1d28f6a4936b7e40c9a392fbc6617f0afb353bb50691e142/langgraph_supervisor-0.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-07 19:00:03",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "langgraph-supervisor"
}
        
Elapsed time: 1.51093s