Skip to content

Latest commit

 

History

History
152 lines (128 loc) · 4.53 KB

AGENT_INTEGRATION.md

File metadata and controls

152 lines (128 loc) · 4.53 KB

🔌 Agent Framework Integration Guide

Step-by-step integration code examples for connecting DreamBees MLX MCP Server to popular AI Agent frameworks (Claude Desktop, Antigravity, Cursor, LangChain, CrewAI, and AutoGen).


1. Claude Desktop / Claude Code Setup

Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "dreambees-mlx": {
      "command": "node",
      "args": [
        "/Users/bozoegg/Downloads/DreamBeesMLX-main/mcp_server/dist/index.js"
      ]
    }
  }
}

2. Antigravity / Gemini CLI Setup

In your .gemini/config or workspace .agents/mcp_config.json:

{
  "mcpServers": {
    "dreambees-mlx": {
      "command": "node",
      "args": [
        "/Users/bozoegg/Downloads/DreamBeesMLX-main/mcp_server/dist/index.js"
      ]
    }
  }
}

3. LangChain Python Agent Tool Integration

from langchain_community.tools import StructuredTool
import subprocess
import json

def generate_local_image(prompt: str, steps: int = 2) -> str:
    """Generate image locally on Apple Silicon Metal GPU via DreamBees MLX."""
    cmd = [
        "node",
        "/Users/bozoegg/Downloads/DreamBeesMLX-main/mcp_server/dist/index.js"
    ]
    # MCP stdio JSON-RPC call
    payload = {
        "jsonrpc": "2.0",
        "id": 1,
        "method": "tools/call",
        "params": {
            "name": "dreambees_generate_image",
            "arguments": {"prompt": prompt, "steps": steps}
        }
    }
    proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True)
    out, _ = proc.communicate(json.dumps(payload) + "\n")
    return out

dreambees_tool = StructuredTool.from_function(
    func=generate_local_image,
    name="dreambees_generate_image",
    description="Generates local AI artwork on Apple Silicon Metal GPU"
)

4. CrewAI Multi-Agent System Tool Integration

from crewai.tools import tool
import subprocess
import json

@tool("DreamBees Local Image Generator")
def dreambees_image_generator(prompt: str) -> str:
    """Generate high quality AI images locally on Apple Silicon Mac without cloud fees."""
    # Stdio MCP invocation
    req = {
        "jsonrpc": "2.0",
        "id": 1,
        "method": "tools/call",
        "params": {
            "name": "dreambees_generate_image",
            "arguments": {"prompt": prompt, "model_id": "flux2-klein-4b"}
        }
    }
    proc = subprocess.Popen(
        ["node", "/Users/bozoegg/Downloads/DreamBeesMLX-main/mcp_server/dist/index.js"],
        stdin=subprocess.PIPE,
        stdout=subprocess.PIPE,
        text=True
    )
    stdout, _ = proc.communicate(json.dumps(req) + "\n")
    return stdout

5. Microsoft AutoGen Multi-Agent Setup

from autogen import AssistantAgent, UserProxyAgent
import subprocess
import json

def run_dreambees_mcp_tool(prompt: str, model_id: str = "flux2-klein-4b") -> str:
    """AutoGen tool function for executing local Apple Silicon MLX GPU image synthesis."""
    req = {
        "jsonrpc": "2.0",
        "id": 1,
        "method": "tools/call",
        "params": {
            "name": "dreambees_generate_image",
            "arguments": {"prompt": prompt, "model_id": model_id}
        }
    }
    proc = subprocess.Popen(
        ["node", "/Users/bozoegg/Downloads/DreamBeesMLX-main/mcp_server/dist/index.js"],
        stdin=subprocess.PIPE,
        stdout=subprocess.PIPE,
        text=True
    )
    stdout, _ = proc.communicate(json.dumps(req) + "\n")
    return stdout

user_proxy = UserProxyAgent("user_proxy", code_execution_config=False)
artist_agent = AssistantAgent("artist_agent", llm_config={"config_list": [{"model": "gpt-4o"}]})
user_proxy.register_function(
    function_map={"dreambees_generate_image": run_dreambees_mcp_tool}
)

6. Agent Memory Safety & Hardware Isolation Protocols

When executing continuous multi-agent loops with DreamBees MLX:

  • Automatic Dynamic VRAM Scoping: The MCP server and Python daemon automatically enforce Ironclad Lockdown VRAM limits (25%–30% RAM for 4B models, 30%–40% RAM for 6B/9B models like Z-Image Turbo / FLUX 9B), keeping 60% to 75% of RAM strictly reserved for macOS WindowServer and desktop fluidity.
  • Hardware Circuit Breaker: If active VRAM hits 75% system hardware RAM or 95% MLX limit, the daemon aborts generation safely (RuntimeError) to prevent macOS system lockups.
  • Per-Step GPU Graph Evaluation: Intermediate GPU graphs (mx.eval), Metal streams (mx.synchronize), and caches (mx.clear_cache) are evaluated and flushed on every single step.