openclaw - 💡(How to fix) Fix Feature Request: agentId support in webhook hook mappings [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#44462Fetched 2026-04-08 00:46:37
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Participants

Fix Action

Fix / Workaround

In a multi-agent setup, webhook hook mappings always dispatch to the default agent regardless of the webhook path or payload. There's no way to route a webhook to a specific agent.

The runCronIsolatedAgentTurn function already supports params.agentId and params.job.agentId, but the hook dispatch path in gateway/server/hooks.js never sets agentId on the job object. The normalizeHookMapping function in hooks-mapping.js also doesn't extract or pass through an agentId field.

Current workaround: each agent polls the orchestrator API on heartbeat (every 10m). This works but adds latency. The webhook system is the right mechanism — it just needs agent targeting.

Code Example

return {
    id,
    matchPath,
    // ... existing fields ...
    agentId: mapping.agentId,  // NEW
};

---

const job = {
    // ... existing fields ...
    agentId: value.agentId,  // NEW — picked up by runCronIsolatedAgentTurn
};

---

return {
    ok: true,
    action: {
        kind: agent,
        // ... existing fields ...
        agentId: renderOptional(mapping.agentId, ctx),  // NEW
    },
};

---

{
  hooks: {
    mappings: [
      {
        id: task-frontend,
        match: { path: frontend },
        action: agent,
        agentId: frontend,
        messageTemplate: 🎯 New task: {{title}}n{{message}}
      },
      {
        id: task-backend,
        match: { path: backend },
        action: agent,
        agentId: backend,
        messageTemplate: 🎯 New task: {{title}}n{{message}}
      }
    ]
  }
}
RAW_BUFFERClick to expand / collapse

Problem

In a multi-agent setup, webhook hook mappings always dispatch to the default agent regardless of the webhook path or payload. There's no way to route a webhook to a specific agent.

The runCronIsolatedAgentTurn function already supports params.agentId and params.job.agentId, but the hook dispatch path in gateway/server/hooks.js never sets agentId on the job object. The normalizeHookMapping function in hooks-mapping.js also doesn't extract or pass through an agentId field.

Confirmed missing in both 2026.1.24-3 and 2026.3.8.

Use Case

We run 5 agents on one instance (frontend, backend, marketer, designer, research). An external orchestrator API creates tasks and assigns them to specific agents. We want to notify the right agent immediately via webhook rather than waiting for heartbeat polling.

Current workaround: each agent polls the orchestrator API on heartbeat (every 10m). This works but adds latency. The webhook system is the right mechanism — it just needs agent targeting.

Proposed Solution

Add an agentId field to hook mappings, threaded through to the job:

In hooks-mapping.jsnormalizeHookMapping:

return {
    id,
    matchPath,
    // ... existing fields ...
    agentId: mapping.agentId,  // NEW
};

In gateway/server/hooks.jsdispatchAgentHook:

const job = {
    // ... existing fields ...
    agentId: value.agentId,  // NEW — picked up by runCronIsolatedAgentTurn
};

In hooks-mapping.jsbuildActionFromMapping:

return {
    ok: true,
    action: {
        kind: agent,
        // ... existing fields ...
        agentId: renderOptional(mapping.agentId, ctx),  // NEW
    },
};

Config usage:

{
  hooks: {
    mappings: [
      {
        id: task-frontend,
        match: { path: frontend },
        action: agent,
        agentId: frontend,
        messageTemplate: 🎯 New task: {{title}}n{{message}}
      },
      {
        id: task-backend,
        match: { path: backend },
        action: agent,
        agentId: backend,
        messageTemplate: 🎯 New task: {{title}}n{{message}}
      }
    ]
  }
}

This would also support template rendering (agentId: {{workspace}}) for dynamic routing from the payload.

Alternatives Considered

  • Heartbeat polling: Works but adds up to N minutes of latency (N = heartbeat interval)
  • Transform modules: Could intercept and modify the action, but transforms can't set agentId since it's not part of the action schema
  • Separate gateway instances per agent: Excessive overhead for what should be a config field

Environment

  • Confirmed missing in OpenClaw 2026.3.8 (latest) and 2026.1.24-3
  • Multi-agent setup with 5 agents on one instance

extent analysis

Fix Plan

To fix the issue, we need to add an agentId field to hook mappings and thread it through to the job. Here are the steps:

  • In hooks-mapping.js, update the normalizeHookMapping function to include the agentId field:
return {
    id,
    matchPath,
    // ... existing fields ...
    agentId: mapping.agentId,  // NEW
};
  • In gateway/server/hooks.js, update the dispatchAgentHook function to include the agentId field in the job object:
const job = {
    // ... existing fields ...
    agentId: value.agentId,  // NEW — picked up by runCronIsolatedAgentTurn
};
  • In hooks-mapping.js, update the buildActionFromMapping function to include the agentId field in the action object:
return {
    ok: true,
    action: {
        kind: agent,
        // ... existing fields ...
        agentId: renderOptional(mapping.agentId, ctx),  // NEW
    },
};
  • Update the config to include the agentId field in the hook mappings:
{
  hooks: {
    mappings: [
      {
        id: task-frontend,
        match: { path: frontend },
        action: agent,
        agentId: frontend,
        messageTemplate: New task: {{title}}n{{message}}
      },
      {
        id: task-backend,
        match: { path: backend },
        action: agent,
        agentId: backend,
        messageTemplate: New task: {{title}}n{{message}}
      }
    ]
  }
}

Verification

To verify that the fix worked, you can test the webhook system by sending a request to the gateway with a payload that matches one of the hook mappings. The corresponding agent should receive the notification immediately.

Extra Tips

  • Make sure to update the config correctly and restart the gateway instance after applying the changes.
  • You can also use template rendering for dynamic routing from the payload by using agentId: {{workspace}} in the config.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix Feature Request: agentId support in webhook hook mappings [1 participants]