Skip to main content

A multiagent system framework built on LangChain and LangGraph with supervisor-based coordination

Project description

LangGroup

PyPI version Python 3.10+ License: MIT

A multiagent system framework built on LangChain and LangGraph with supervisor-based coordination.

LangGroup provides a flexible architecture for creating groups of specialized AI agents that collaborate on complex tasks under the guidance of a supervisor agent.

Features

  • Supervisor Architecture: Intelligent task routing and coordination
  • Hierarchical Supervisors: Supervisors can manage other supervisors, enabling nested group structures
  • Extensible Agent System: Easy-to-extend base classes for custom agents
  • LangGraph Integration: Stateful workflows with LangGraph
  • Type-Safe: Full type hints and Pydantic models

Installation

pip install langgroup

For development:

pip install -e ".[dev]"

Quick Start

  1. Set up your environment:
cp .env.example .env
# Edit .env and add your OPENAI_API_KEY
  1. Create your custom agents by extending BaseAgent:
from langgroup import BaseAgent
from typing import List, Callable

class MyAgent(BaseAgent):
    @property
    def description(self) -> str:
        return "Description of what this agent does"
    
    @property
    def tools(self) -> List[Callable]:
        return [my_tool_function]
    
    @property
    def system_prompt(self) -> str:
        return "System prompt for the agent"
  1. Set up the agent system:
from langgroup import AgentSystem
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
agents = [MyAgent(llm), AnotherAgent(llm)]
system = AgentSystem(llm, agents)

result = system.run("Your task here")

Hierarchical Supervisors

💡 Key Feature: SupervisorAgent can be used as a regular agent within another AgentSystem, enabling powerful hierarchical group structures.

Create groups of agents for complex workflows:

from langgroup import AgentSystem, SupervisorAgent
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)

# Create specialized groups
research_group = [ResearchAgent(llm), AnalysisAgent(llm)]
research_supervisor = SupervisorAgent(
    llm, research_group, 
    name="ResearchGroupSupervisor"
)

content_group = [WritingAgent(llm), EditingAgent(llm)]
content_supervisor = SupervisorAgent(
    llm, content_group, 
    name="ContentGroupSupervisor"
)

# Top-level supervisor coordinates the groups
top_system = AgentSystem(llm, [research_supervisor, content_supervisor])
result = top_system.run("Research AI trends and write a comprehensive report")

How it works:

  1. The top-level supervisor receives the task
  2. It intelligently routes to the appropriate group supervisor (e.g., ResearchGroupSupervisor)
  3. The group supervisor manages its specialized agents
  4. Results flow back up to coordinate between groups
  5. Complex multi-stage tasks are handled seamlessly

This architecture allows you to build sophisticated agent organizations with clear separation of concerns.

Usage

Single Agent (Basic)

Run the basic agent:

python main.py

The agent includes two tools:

  • Calculator: Performs mathematical calculations
  • Weather: Returns weather information (mock implementation)

Multiagent System with Supervisor

Run the multiagent system:

python multiagent_supervisor.py

The multiagent system includes:

  • Supervisor Agent: Orchestrates and routes tasks to specialized agents
  • Research Agent: Handles research and information gathering
  • Analysis Agent: Analyzes data and provides insights
  • Writing Agent: Writes and formats content
  • Math Agent: Performs calculations

The supervisor dynamically decides which agents to invoke and coordinates their work, allowing agents to collaborate back and forth on complex tasks.

Architecture

The multiagent system uses LangGraph to create a stateful workflow where:

  1. Supervisor receives the task
  2. Supervisor routes to appropriate sub-agent
  3. Sub-agent completes its work
  4. Control returns to supervisor
  5. Process repeats until task is complete

Customization

Add your own tools by creating functions and registering them with the Tool class in either main.py or multiagent_supervisor.py.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langgroup-0.2.1.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langgroup-0.2.1-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file langgroup-0.2.1.tar.gz.

File metadata

  • Download URL: langgroup-0.2.1.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for langgroup-0.2.1.tar.gz
Algorithm Hash digest
SHA256 042b4f5302c3afbff6a1f3d89694b4237d953038af2c9fc41a2ed3e9d39674bc
MD5 ea295b57882f097cd5fa091cba869318
BLAKE2b-256 edc139e1350c52aeed85963f1c8f05dd28a4f17134f1634459216e4a47ee01e4

See more details on using hashes here.

File details

Details for the file langgroup-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: langgroup-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for langgroup-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b04e8baf43b98660a60a5d82a62531ca48134f4c4dbfde50db2fd4264008b0ca
MD5 39803de16ec1375e5fecd749ab74db3a
BLAKE2b-256 b4d3b6a2192e297732479a47ad4310e2fe0dc02d850d4704293392a48b9b10da

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page