← Back to PRs

#9800: feat(hooks): allow webhook mappings to route to specific agents via a…

by bogdanClawdy open 2026-02-05 18:04 View on GitHub →
gateway stale
…gentId Add agentId support to webhook hook mappings, enabling multi-agent webhook routing. The agentId can be set either statically in the mapping config or dynamically via transform return values. Changes: - Add agentId to HookMappingConfig type and Zod validation schema - Add agentId to HookMappingResolved, HookAction, and HookTransformResult types - Thread agentId through normalizeHookMapping, buildActionFromMapping, mergeAction, dispatchAgentHook, and into runCronIsolatedAgentTurn - Support template rendering in agentId (e.g. '{{payload.inbox}}') - Transform agentId overrides mapping-level agentId Closes #9130 ## 🤖 AI-Assisted This PR was authored with AI assistance (Claude/OpenClaw). - **Degree of testing:** Fully tested — 6 new unit tests, full suite (5207 tests) passing, build + lint clean - **Understanding:** The author understands all changes — agentId is threaded as an optional string through the existing hooks mapping pipeline, ultimately passed to runCronIsolatedAgentTurn which already supports the agentId parameter <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR adds `agentId` support to webhook hook mappings so a mapping (or its transform) can route an incoming hook to a specific agent. The change extends the hooks config types + Zod schema, threads `agentId` through mapping normalization/action building/merging, and passes it through the gateway HTTP hook handler into `runCronIsolatedAgentTurn`. Tests were added to cover mapping-level, transform-level, and template-rendered `agentId` behaviors. Within the codebase, this integrates with the existing hooks mapping pipeline (`src/gateway/hooks-mapping.ts`) and the gateway’s hooks HTTP server (`src/gateway/server-http.ts` / `src/gateway/server/hooks.ts`) by ultimately selecting an agent in the cron isolated agent runner. <h3>Confidence Score: 4/5</h3> - This PR is generally safe to merge, but there are a couple of behavior gaps around agentId handling that should be resolved to match the intended feature surface. - The changes are small and well-threaded with tests for mapping/transform/template routing. The main remaining concerns are (1) `agentId` isn’t actually accepted by the direct `/hooks/agent` endpoint despite being threaded into the dispatcher, and (2) transforms can’t intentionally clear a mapping-provided agentId due to nullish-coalescing merge semantics. - src/gateway/server-http.ts, src/gateway/hooks-mapping.ts <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs