<@ULVA73B9P> is there a way to integrate marvin or...
# ask-marvin
a
@Marvin is there a way to integrate marvin orchestration framework (https://askmarvin.ai/welcome) with claude code agent sdk?
m
thought for 64.3 seconds
Short answer: yes—there’s no official, one-click integration (that I’m aware of), but you can integrate the two cleanly at the “tool” or “API/webhook” boundary. Common patterns that work well: - Claude Code Agent as the orchestrator; Marvin as a callable tool - Wrap a Marvin workflow/run as a custom Claude tool (call Marvin over its HTTP API or Python client if available). - Give the tool a clear JSON schema and return structured results (and optionally a run_id for polling). - Marvin as the orchestrator; Claude Code Agent as a step - Invoke the Code Agent from Marvin via a local service (HTTP/gRPC), a Python call, or a queue. Pass tools/files/context in, return the agent’s structured outputs. - Event/webhook pattern - Trigger a Marvin run from a Claude tool, immediately return a run_id, and have the agent (or another worker) poll/subscribe for completion events. A minimal “Claude Agent calls Marvin” sketch (pseudocode; adjust to fit the exact SDKs):
Copy code
# PSEUDOCODE — illustrates the shape only

class MarvinRunTool(CodeAgentTool):
    name = "run_marvin_workflow"
    description = "Run a Marvin workflow by slug with parameters."
    input_schema = {
        "type": "object",
        "properties": {
            "slug": {"type": "string"},
            "params": {"type": "object"}
        },
        "required": ["slug"]
    }

    def __call__(self, input):
        # 1) kick off run in Marvin
        resp = <http://requests.post|requests.post>(
            f"{MARVIN_URL}/api/workflows/{input['slug']}/runs",
            json={"params": input.get("params", {})},
            headers={"Authorization": f"Bearer {MARVIN_TOKEN}"}
        )
        resp.raise_for_status()
        data = resp.json()

        # 2) optionally poll until completion (or return run_id and let agent handle follow-ups)
        run_id = data["id"]
        status = data.get("status")

        if status not in ("completed", "failed"):
            # simple polling loop; replace with webhook/subscription if available
            while status not in ("completed", "failed"):
                time.sleep(2)
                s = requests.get(
                    f"{MARVIN_URL}/api/runs/{run_id}",
                    headers={"Authorization": f"Bearer {MARVIN_TOKEN}"}
                ).json()
                status = s["status"]
                data = s

        return {
            "run_id": run_id,
            "status": status,
            "output": data.get("output"),
            "logs": data.get("logs")
        }

# Register this tool with your Claude Code Agent instance and include it in the tool list.
Implementation tips: - Long-running runs: either poll from the tool (simple) or return a run_id and have the agent schedule a follow-up tool call to check status (more scalable). If Marvin supports webhooks, prefer event-driven completion. - Idempotency: include a client-provided run key to make replays safe. - Streaming: if you need live logs, consider a separate “subscribe_to_run_logs” tool or a side channel (websockets/server-sent events). - Security: keep Marvin and Claude creds in your secret manager; don’t inline tokens. Questions to help me make this concrete for you: - Which side should be “in charge”? Do you want Claude to call Marvin workflows, or Marvin to invoke the Code Agent? - Are you working in Python, Node, or mixed? - Does Marvin expose a documented HTTP or Python API for starting runs and fetching results/logs? If yes, can you share the endpoint shapes? - Do you need streaming/intermediate steps in Claude, or is “fire-and-wait-for-result” fine? If you share the exact SDK entry points (for Marvin’s run/create/get APIs and your Claude Code Agent setup), I can turn this into a ready-to-run snippet.