LangGroup
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
- Set up your environment:
cp .env.example .env
# Edit .env and add your OPENAI_API_KEY
- 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"
- 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:
- The top-level supervisor receives the task
- It intelligently routes to the appropriate group supervisor (e.g., ResearchGroupSupervisor)
- The group supervisor manages its specialized agents
- Results flow back up to coordinate between groups
- 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:
- Supervisor receives the task
- Supervisor routes to appropriate sub-agent
- Sub-agent completes its work
- Control returns to supervisor
- 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.
Metadata
Release files for langgroup 0.2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| langgroup-0.2.4.tar.gz | 12.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| langgroup-0.2.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.6 kB
Release files / langgroup-0.2.4.tar.gz
| Download URL | langgroup-0.2.4.tar.gz |
|---|---|
| Size | 12.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f91e32c5dae925e48d828ce174636e14e40eb389bbfca5ebfad1cc69beb1945c
|
|
BLAKE2b-256 checksum How to use checksums |
cdbae83e2d3c147c9c9b2f81747149c2cfd6077780c478e61d9ae08e2c348c77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.6
|
Release files / langgroup-0.2.4-py3-none-any.whl
| Download URL | langgroup-0.2.4-py3-none-any.whl |
|---|---|
| Size | 11.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7fad5fb6e29fbd587655b355acb4345a8313e2b423110e641a271f086df9023f
|
|
BLAKE2b-256 checksum How to use checksums |
4366520d442077c9b356c638a1a3c711c89851972a4d90fc585478fa85d16f39
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.6
|