feat(hooks): add trigger and channelId to plugin hook agent context (#28623)

* feat(hooks): add trigger and channelId to plugin hook agent context

Adds `trigger` and `channelId` fields to `PluginHookAgentContext` so
plugins can determine what initiated the agent run and which channel
it originated from, without session-key parsing or Redis bridging.

trigger values: "user", "heartbeat", "cron", "memory"
channelId values: "telegram", "discord", "whatsapp", etc.

Both fields are threaded through run.ts and attempt.ts hookCtx so all
hook phases receive them (before_model_resolve, before_prompt_build,
before_agent_start, llm_input, llm_output, agent_end).

channelId falls back from messageChannel to messageProvider when the
former is not set. followup-runner passes originatingChannel so queued
followup runs also carry channel context.

* docs(changelog): note hook context parity fix for #28623

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
This commit is contained in:
David Rudduck
2026-03-03 11:39:20 +10:00
committed by GitHub
parent ee646dae82
commit 11e1363d2d
10 changed files with 18 additions and 0 deletions

View File

@@ -263,6 +263,8 @@ export async function runEmbeddedPiAgent(
sessionId: params.sessionId,
workspaceDir: resolvedWorkspace,
messageProvider: params.messageProvider ?? undefined,
trigger: params.trigger,
channelId: params.messageChannel ?? params.messageProvider ?? undefined,
};
if (hookRunner?.hasHooks("before_model_resolve")) {
try {
@@ -715,6 +717,7 @@ export async function runEmbeddedPiAgent(
const attempt = await runEmbeddedAttempt({
sessionId: params.sessionId,
sessionKey: params.sessionKey,
trigger: params.trigger,
messageChannel: params.messageChannel,
messageProvider: params.messageProvider,
agentAccountId: params.agentAccountId,

View File

@@ -1356,6 +1356,8 @@ export async function runEmbeddedAttempt(
sessionId: params.sessionId,
workspaceDir: params.workspaceDir,
messageProvider: params.messageProvider ?? undefined,
trigger: params.trigger,
channelId: params.messageChannel ?? params.messageProvider ?? undefined,
};
const hookResult = await resolvePromptBuildHookResult({
prompt: params.prompt,

View File

@@ -26,6 +26,8 @@ export type RunEmbeddedPiAgentParams = {
messageChannel?: string;
messageProvider?: string;
agentAccountId?: string;
/** What initiated this agent run: "user", "heartbeat", "cron", or "memory". */
trigger?: string;
/** Delivery target (e.g. telegram:group:123:topic:456) for topic/thread routing. */
messageTo?: string;
/** Thread/topic identifier for routing replies to the originating thread. */