artur
03/26/2026, 4:16 AMMarvin
03/26/2026, 4:16 AMMarvin
03/26/2026, 4:17 AM# 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.