A state-based agent orchestration system that allows transitions between different states (IDLE, PLANNING, RESEARCHING, EXECUTING, REVIEWING, ERROR) while maintaining conversation context and providing state-specific prompts.
A Python implementation of a state-based agent orchestration system using the Model Context Protocol (MCP).
The Model Context Protocol (MCP) allows applications to provide context for LLMs in a standardized way, separating the concerns of providing context from the actual LLM interaction. With MCP, you can build servers that expose:
# Install uv curl -LsSf https://astral.sh/uv/install.sh | sh # Create a new directory for our project uv init mcp-agents-orchestra cd mcp-agents-orchestra # Create virtual environment and activate it uv venv source .venv/bin/activate # On Unix/macOS .venv\Scripts\activate # On Windows # Install dependencies uv add "mcp[cli]" httpx
# Create a new directory for our project mkdir mcp-agents-orchestra cd mcp-agents-orchestra # Create a virtual environment python -m venv venv source venv/bin/activate # On Unix/macOS venv\Scripts\activate # On Windows # Install dependencies pip install "mcp[cli]" httpx
Place the project files in your directory:
orchestrator.py
- The main MCP server implementing the state machineorchestrator_client.py
- Client demonstrating the orchestration flowrequirements.txt
- Dependencies for the project.gitignore
- Git ignore fileorchestrator.py
- The main MCP server implementing the state machineorchestrator_client.py
- Client demonstrating the orchestration flowrequirements.txt
- Dependencies for the projectpython orchestrator.py
python orchestrator_client.py
Make sure you have Claude for Desktop installed. You can download the latest version from Anthropic's website.
Open your Claude for Desktop configuration file:
macOS/Linux:
# Create or edit the configuration file code ~/Library/Application\ Support/Claude/claude_desktop_config.json
Windows:
# Path may vary depending on your Windows version code %APPDATA%\Claude\claude_desktop_config.json
Add the orchestrator server configuration:
{ "mcpServers": { "agent-orchestrator": { "command": "python", "args": [ "/ABSOLUTE/PATH/TO/YOUR/PROJECT/orchestrator.py" ] } } }
Replace the path with the absolute path to your orchestrator.py file.
Save the configuration file and restart Claude for Desktop.
Once configured, you can:
Claude will be able to:
The orchestration system implements a state machine with the following states:
AgentState
enum in orchestrator.py
_get_available_transitions()
Add new tools by creating functions decorated with @mcp.tool()
:
@mcp.tool() def my_custom_tool(arg1: str, arg2: int, ctx: Context) -> str: """Description of what this tool does Args: arg1: Description of arg1 arg2: Description of arg2 """ # Implementation here return "Result"
The MCP CLI provides tools for development and testing:
# Install MCP CLI if you haven't already pip install "mcp[cli]" # Test your server with the MCP Inspector mcp dev orchestrator.py # Install in Claude Desktop mcp install orchestrator.py
from mcp import ClientSession, StdioServerParameters from mcp.client.stdio import stdio_client async with stdio_client(StdioServerParameters(command="python", args=["orchestrator.py"])) as (read, write): async with ClientSession(read, write) as session: await session.initialize() # Test state transitions await session.call_tool("transition_state", arguments={"new_state": "PLANNING"})
This project is licensed under the MIT License - see the LICENSE file for details.
Discover shared experiences
Shared threads will appear here, showcasing real-world applications and insights from the community. Check back soon for updates!