Skip to main content

QueenBee and WorkerBee for CommandHive.xyz

Project description

CommandHive Agent Orchestrator

Create agents on the fly, manage MCP variables, and execute tasks 24/7.

Visit Website GitHub Repo

Latest updates

Date Update Description
2025/06/03 Released sample orchestrator and listener scripts
2025/05/27 Added Pub/Sub support for MSK and confirmed tool calling with confirmation
2025/05/15 Ensured sampling as MCP feature is working

For a full changelog, see our releases page.


Why CommandHive?

🏆 Build flexible multi-agent orchestrations. Spin up agents dynamically based on MCP configurations and orchestrate complex workflows without rigid architectures.

🔧 Seamlessly integrate with existing tools. Use Redis, Kafka, and MSK for Pub/Sub messaging; connect to Model Context Protocol servers; and configure agents with custom instructions and models.

🚀 Production-ready controls. Compatible with Python 3.11 and 3.12, supports logging, error handling, and run-time configuration via JSON.

[!TIP] Start quickly by exploring the sample agent and listener below to see how CommandHive manages agents and messaging.


Installation

To install via pip:

pip install commandhive-agent

Clone the repository:

git clone https://github.com/CommandHive/agent-orchestrator.git
cd agent-orchestrator

Overview

This is an agent orchestrator backend to create agents on the fly, store all your MCP variables, and get tasks done round the clock from these agents. Visit CommandHive Website.


✅ Completed

  • Ensure sampling as MCP feature is working
  • Create Pub/Sub support using Redis
  • Create Pub/Sub support using Kafka
  • Create Pub/Sub support using MSK (Managed Kafka)
  • Ensure tool calling is done with confirmation
  • Check compatibility with Python 3.11
  • Check compatibility with Python 3.12

⏳ To Do Next

  • Integrate smart contract for tool calling
  • Each agent has its own wallet (defined in config)
  • Pub/Sub support for RabbitMQ
  • Pub/Sub support for Google Pub/Sub

Sample Agent

import asyncio
import json
from typing import Dict, List
import os
from mcp_agent.core.fastagent import FastAgent
from dotenv import load_dotenv
load_dotenv()
import redis.asyncio as aioredis

'''
 redis-cli PUBLISH agent:queen '{"type": "user", "content": "tell me price of polygon please", "channel_id": "agent:queen",
  "metadata": {"model": "claude-3-5-haiku-latest", "name": "default"}}'
'''

subagents_config = [
    {
        "name": "finder",
        "instruction": "You are an agent with access to the internet; you need to search about the latest prices of Bitcoin and other major cryptocurrencies and report back.",
        "servers": ["fetch", "brave"],
        "model": "haiku"
    },
    {
        "name": "reporter",
        "instruction": "You are an agent that takes the raw pricing data provided by the finder agent and produces a concise, human-readable summary highlighting current prices, 24-hour changes, and key market insights.",
        "servers": [],  
        "model": "haiku"
    }
]

# Sample JSON config for MCP
sample_json_config = {
    "mcp": {
        "servers": {
            "fetch": {
                "name": "fetch",
                "description": "A server for fetching links",
                "transport": "stdio",
                "command": "uvx",
                "args": ["mcp-server-fetch"],
                "tool_calls": [
                    {
                        "name": "fetch",
                        "seek_confirm": True,
                        "time_to_confirm": 120000,
                        "default": "reject"
                    }
                ]
            },
            "brave": {
                "name": "brave",
                "description": "Brave search server",
                "transport": "stdio",
                "command": "npx",
                "args": [
                    "-y",
                    "@modelcontextprotocol/server-brave-search"
                ],
                "env": {
                    "BRAVE_API_KEY": "BSANIwUPPxwC9wchogL5I6UNkWGffh3"
                }
            }
        }
    },
    "default_model": "haiku",
    "logger": {
        "level": "info",
        "type": "console"
    },
    "pubsub_enabled": True,
    "pubsub_config": {
        "use_redis": True,
        "channel_name": "queen",
        "redis": {
            "host": "localhost",
            "port": 6379,
            "db": 0,
            "channel_prefix": "agent:"
        }
    },
    "anthropic": {
        "api_key": os.environ.get("CLAUDE_API_KEY", "")
    }
}

# Create FastAgent instance
fast = FastAgent(
    name="queen",  # Changed name to match channel name used in publishing
    json_config=sample_json_config,
    parse_cli_args=False
)

# Dynamically create agents from JSON configuration using a for loop
def create_agents_from_config(config_list: List[Dict]) -> List[str]:
    """
    Create agents dynamically from JSON configuration.
    Returns a list of agent names for use in the orchestrator.
    """
    agent_names = []
    
    for agent_config in config_list:
        name = agent_config.get("name")
        instruction = agent_config.get("instruction", "")
        servers = agent_config.get("servers", [])
        model = agent_config.get("model", None)
        
        if not name:
            continue
            
        # Create agent decorator kwargs
        agent_kwargs = {
            "name": name,
            "instruction": instruction,
            "servers": servers
        }
        
        # Add model if specified
        if model:
            agent_kwargs["model"] = model
            
        # Create the agent using the decorator
        @fast.agent(**agent_kwargs)
        def agent_function():
            """Dynamically created agent function"""
            pass
            
        agent_names.append(name)
    
    return agent_names

# Create agents from configuration
created_agent_names = create_agents_from_config(subagents_config)

# Create orchestrator with the dynamically created agents
@fast.orchestrator(
    name="orchestrate", 
    agents=created_agent_names,  # Use the list of created agent names
    plan_type="full",
    model="haiku"
)
async def orchestrate_task():
    """Orchestrator function"""
    pass

async def main():
    """Test initializing FastAgent with JSON config in interactive mode."""
    
    # Create Redis client
    redis_client = aioredis.Redis(
        host="localhost",
        port=6379,
        db=0,
        decode_responses=True
    )
    
    # Register agents and keep it running
    async with fast.run() as agent:
        try:
            # Subscribe to the input channel
            pubsub = redis_client.pubsub()
            await pubsub.subscribe("agent:queen")
            
            # Initial task for the orchestrator
            initial_task = """
           Can you find the price of VANA token and if it is more than 50 percent of its lowest then give command to sell it off. tell me now sell it off or hold it.
            """
            
            await agent.orchestrate(initial_task)
            
            # Keep running and listen for Redis messages
            while True:
                # Process Redis messages directly
                message = await pubsub.get_message(ignore_subscribe_messages=True)
                if message and message.get('type') == 'message':
                    try:
                        # Process the message data
                        data = message.get('data')
                        if isinstance(data, bytes):
                            data = data.decode('utf-8')
                        
                        # Try to parse JSON
                        try:
                            data_obj = json.loads(data)
                            
                            # If this is a user message, extract content and send to orchestrator
                            if data_obj.get('type') == 'user' and 'content' in data_obj:
                                user_input = data_obj['content']
                                
                                # Send to orchestrator instead of individual agent
                                response = await agent.orchestrate(user_input)
                                
                        except json.JSONDecodeError:
                            # Try to process as plain text
                            response = await agent.orchestrate(data)
                            
                    except Exception:
                        pass
                
                # Small delay to prevent CPU spike
                await asyncio.sleep(0.05)
                
        finally:
            # Clean up Redis connection
            if 'pubsub' in locals():
                await pubsub.unsubscribe("agent:queen")
            await redis_client.close()

if __name__ == "__main__":
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        pass

Sample Listener

import redis
import time

def main():
    # Connect to Redis (adjust host/port/db as needed)
    r = redis.Redis(host='localhost', port=6379, db=0)

    # Create a PubSub object and subscribe to the channel
    pubsub = r.pubsub()
    channel_name = 'agent:queen'
    pubsub.subscribe(channel_name)
    print(f"Subscribed to channel: {channel_name}")

    # Loop forever, polling for new messages
    while True:
        message = pubsub.get_message()
        if message:
            # Print the raw message dict
            print(message)
        # Sleep briefly to avoid busy-waiting
        time.sleep(0.05)

if __name__ == '__main__':
    main()

Disclaimer

This repo is cloned from fast-agent.

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

bee_agent-0.5.2.tar.gz (271.5 kB view details)

Uploaded Source

Built Distribution

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

bee_agent-0.5.2-py3-none-any.whl (351.3 kB view details)

Uploaded Python 3

File details

Details for the file bee_agent-0.5.2.tar.gz.

File metadata

  • Download URL: bee_agent-0.5.2.tar.gz
  • Upload date:
  • Size: 271.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for bee_agent-0.5.2.tar.gz
Algorithm Hash digest
SHA256 9b21f1a6b1804cc3e0cbdfff18613bd571a31e9f186dd5349fadcbbe761961ab
MD5 c756af9c9a2fd54a6efaf6e3aab44a27
BLAKE2b-256 382c5e2325c8df29f247864076e87e9cb9372779d68f5382d7b7b01193e09c47

See more details on using hashes here.

File details

Details for the file bee_agent-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: bee_agent-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 351.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for bee_agent-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 57924c07c089fae97f84ab7f5208f65fff78cb5ab3711e7f3c90ef4a42025646
MD5 7547668c8d8344656eed9b7dfb303acf
BLAKE2b-256 f5702e44b325909f41b8b81680e4a0fef5b54124d67a1194d129c159ec0b2043

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