Docs Quick Start Pricing Blog Get Started
Blog Building Multi-Agent Delegation

How to Build Multi-Agent Task Delegation with Delega

Step-by-step: coordinate work across multiple AI agents using delegation chains, webhooks, and MCP tools. Practical examples with curl and MCP.

The problem

You have multiple AI agents that need to coordinate. A research agent gathers data. A writer agent drafts content. An editor agent reviews it. Each agent needs to know what to work on, when to start, and where to put the result.

Without a coordination layer, you end up duct-taping this together with shared databases, polling loops, and custom state machines. Every new agent means more glue code.

Delega gives you a task API designed for exactly this: agents creating tasks for other agents, with delegation tracking, persistent context, and webhook notifications built in.

Architecture: the orchestrator pattern

The simplest multi-agent pattern is an orchestrator that breaks work into subtasks and delegates them to specialized agents:

Orchestrator Agent
  ├── creates task → Research Agent
  ├── creates task → Writer Agent (blocked until research completes)
  └── creates task → Editor Agent (blocked until writing completes)

Each agent has its own API key (dlg_ prefix), so every action is attributed. The orchestrator uses webhooks to know when each step finishes, then unblocks the next agent.

Step 1: Create your agents

Each agent gets its own identity and API key. You can create them via the API or through the dashboard.

# Create the orchestrator agent
curl -X POST https://api.delega.dev/v1/agents \
  -H "Authorization: Bearer YOUR_PROJECT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "orchestrator", "label": "Orchestrator Agent"}'

# Create specialized agents
curl -X POST https://api.delega.dev/v1/agents \
  -H "Authorization: Bearer YOUR_PROJECT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "research-agent", "label": "Research Agent"}'

curl -X POST https://api.delega.dev/v1/agents \
  -H "Authorization: Bearer YOUR_PROJECT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "writer-agent", "label": "Writer Agent"}'

curl -X POST https://api.delega.dev/v1/agents \
  -H "Authorization: Bearer YOUR_PROJECT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "editor-agent", "label": "Editor Agent"}'

Each response includes a dlg_ API key for that agent. Store these securely — each agent uses its own key for all API calls.

Step 2: Create tasks

The orchestrator creates tasks for the pipeline. Each task carries the context the assigned agent needs to do its work.

# Orchestrator creates a research task
curl -X POST https://api.delega.dev/v1/tasks \
  -H "X-Agent-Key: dlg_orchestrator_key" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "Research top 5 competitors in the AI task management space",
    "priority": 1,
    "metadata": {
      "pipeline": "blog-post-q1",
      "step": "research",
      "output_format": "markdown"
    }
  }'

Via MCP (inside Claude Code, Cursor, or any MCP client):

delega_create_task(
  content="Research top 5 competitors in the AI task management space",
  priority=1,
  metadata={"pipeline": "blog-post-q1", "step": "research"}
)

Step 3: Delegate tasks

Once a task exists, the orchestrator delegates it to the appropriate agent. Delegation records who assigned what to whom — this is queryable later.

# Delegate research task to research-agent
curl -X POST https://api.delega.dev/v1/tasks/TASK_ID/delegate \
  -H "X-Agent-Key: dlg_orchestrator_key" \
  -H "Content-Type: application/json" \
  -d '{"agent_id": "research-agent"}'

Via MCP:

delega_delegate_task(task_id="TASK_ID", agent_id="research-agent")

The research agent can now see this task when it queries for its assigned work:

# Research agent lists its tasks
curl https://api.delega.dev/v1/tasks?assigned_to=research-agent \
  -H "X-Agent-Key: dlg_research_key"

Step 4: Monitor via webhooks

Instead of polling, register a webhook so the orchestrator gets notified when tasks complete.

# Register a webhook for task completion events
curl -X POST https://api.delega.dev/v1/webhooks \
  -H "Authorization: Bearer YOUR_PROJECT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://your-server.com/hooks/delega",
    "events": ["task.completed", "task.failed"],
    "secret": "whsec_your_signing_secret"
  }'

When the research agent completes its task, Delega sends an HMAC-SHA256 signed POST to your webhook URL:

{
  "event": "task.completed",
  "task": {
    "id": "TASK_ID",
    "content": "Research top 5 competitors...",
    "completed_by": "research-agent",
    "metadata": {
      "pipeline": "blog-post-q1",
      "step": "research",
      "result": "## Competitor Analysis\n..."
    }
  }
}

Your orchestrator receives this, reads the result from the task metadata, and creates the next task in the pipeline.

Step 5: Complete tasks

When an agent finishes its work, it marks the task complete and attaches the result as metadata:

# Research agent completes its task with results
curl -X POST https://api.delega.dev/v1/tasks/TASK_ID/complete \
  -H "X-Agent-Key: dlg_research_key" \
  -H "Content-Type: application/json" \
  -d '{
    "metadata": {
      "result": "## Competitor Analysis\n1. Tool A — ...\n2. Tool B — ...",
      "sources": ["https://example.com/report1", "https://example.com/report2"]
    }
  }'

Via MCP:

delega_complete_task(task_id="TASK_ID")

Real-world pattern: Research → Writer → Editor

Here's the full pipeline. The orchestrator chains three agents together:

# 1. Orchestrator creates and delegates research task
RESEARCH_ID=$(curl -s -X POST https://api.delega.dev/v1/tasks \
  -H "X-Agent-Key: dlg_orchestrator_key" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "Research AI task management competitors",
    "priority": 1,
    "metadata": {"pipeline": "blog", "step": 1}
  }' | jq -r '.id')

curl -X POST "https://api.delega.dev/v1/tasks/$RESEARCH_ID/delegate" \
  -H "X-Agent-Key: dlg_orchestrator_key" \
  -H "Content-Type: application/json" \
  -d '{"agent_id": "research-agent"}'

# 2. When research completes (via webhook), orchestrator creates writing task
WRITER_ID=$(curl -s -X POST https://api.delega.dev/v1/tasks \
  -H "X-Agent-Key: dlg_orchestrator_key" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "Write blog post based on research findings",
    "priority": 1,
    "metadata": {
      "pipeline": "blog",
      "step": 2,
      "research_task_id": "'"$RESEARCH_ID"'"
    }
  }' | jq -r '.id')

curl -X POST "https://api.delega.dev/v1/tasks/$WRITER_ID/delegate" \
  -H "X-Agent-Key: dlg_orchestrator_key" \
  -H "Content-Type: application/json" \
  -d '{"agent_id": "writer-agent"}'

# 3. When writing completes, orchestrator creates editing task
EDITOR_ID=$(curl -s -X POST https://api.delega.dev/v1/tasks \
  -H "X-Agent-Key: dlg_orchestrator_key" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "Edit and proofread blog post draft",
    "priority": 1,
    "metadata": {
      "pipeline": "blog",
      "step": 3,
      "writer_task_id": "'"$WRITER_ID"'"
    }
  }' | jq -r '.id')

curl -X POST "https://api.delega.dev/v1/tasks/$EDITOR_ID/delegate" \
  -H "X-Agent-Key: dlg_orchestrator_key" \
  -H "Content-Type: application/json" \
  -d '{"agent_id": "editor-agent"}'

Delegation chains

As tasks get delegated through multiple agents, Delega records the full chain. Query the /chain endpoint to see the complete delegation history:

curl https://api.delega.dev/v1/tasks/TASK_ID/chain \
  -H "X-Agent-Key: dlg_orchestrator_key"

Response:

{
  "task_id": "TASK_ID",
  "chain": [
    {"from": "orchestrator", "to": "research-agent", "at": "2026-03-17T10:00:00Z"},
    {"from": "research-agent", "to": "data-agent", "at": "2026-03-17T10:05:00Z"},
    {"from": "data-agent", "to": "research-agent", "at": "2026-03-17T10:12:00Z"}
  ]
}

This is critical for debugging. When something goes wrong three agents deep, you can trace exactly how the task got there and who touched it along the way.

Via MCP:

delega_get_chain(task_id="TASK_ID")

Webhooks for real-time coordination

Webhooks are the glue that makes multi-agent pipelines reactive instead of polling-based. Supported events:

  • task.created — a new task was created
  • task.updated — task content or metadata changed
  • task.delegated — task was assigned to a different agent
  • task.completed — task was marked complete
  • task.failed — task was marked as failed

Every webhook payload is signed with HMAC-SHA256 using your webhook secret. Verify the X-Delega-Signature header before processing:

import hmac, hashlib

def verify_webhook(payload: bytes, signature: str, secret: str) -> bool:
    expected = hmac.new(
        secret.encode(), payload, hashlib.sha256
    ).hexdigest()
    return hmac.compare_digest(f"sha256={expected}", signature)

Putting it all together

The pattern is always the same:

  1. Create agents with individual identities
  2. Create tasks with context in metadata
  3. Delegate tasks to the right agent
  4. Monitor via webhooks (not polling)
  5. Complete tasks with results attached
  6. Query chains for debugging and audit trails

Whether you're using curl, the Python SDK, the CLI, or MCP tools inside an AI coding assistant — the primitives are the same. Delega handles the coordination so your agents can focus on the work.

Start building multi-agent workflows:

→ Quick start guide
→ Full API documentation
→ GitHub — star, fork, or self-host

← Back to blog