Repository navigation
feat: Add server plugin hooks in DefaultRequestHandler - #835
Merged
Merged
Conversation
🧪 Code Coverage
Generated by coverage-comment.yml |
JakubWorek
approved these changes
Nov 17, 2026
This was referenced Nov 18, 2026
bartek-gralewicz
added a commit
that referenced
this pull request
Nov 20, 2026
# Description Runs the execution hooks from `@a2a-js/sdk/plugins` (#826) around every `AgentExecutor.execute` call made by `DefaultRequestHandler`. They use the same `plugins` option as the server hooks (#835). ## Behavior - `beforeExecution` runs before the agent. If it throws, the agent does not run, plugins that already ran get `afterExecution` with the error, and the handler's usual failure path publishes a FAILED task. - The agent runs inside `aroundExecution`. The agent runs detached from the request, so this is where a plugin can scope it, for example to make the agent's outbound calls children of an OTel span. - `afterExecution` runs when the agent returns or throws, with the error if there is one. The error is rethrown, so the handler's existing failure handling is unchanged. - `onExecutionEvent` runs for each event published on the task's bus while the agent runs. The agent gets the original bus. Events the handler publishes after the agent throws (the synthetic FAILED task and status) are not reported. - `cancelTask` runs without hooks. - With no execution hooks registered, the handler uses the executor as given.
bartek-gralewicz
added a commit
that referenced
this pull request
Nov 20, 2026
# Description Calls `onTaskEvent` from `@a2a-js/sdk/plugins` (#826) after every successful task write made by `DefaultRequestHandler`. The hook uses the same `plugins` option as the server hooks (#835). ```ts const transitions: A2APlugin = { name: 'transitions', onTaskEvent: ({ taskId, fromState, toState }) => { if (fromState !== toState) console.log(taskId, fromState, '->', toState); }, }; ``` ## Behavior - `ResultManager` saves the task, then calls `onTaskEvent` with the task, the event that caused the write, and the state stored before it: - a `task` event reports the stored state, or `undefined` when it creates the task; - a `statusUpdate` reports the stored state; - an `artifactUpdate` reports the same state as `fromState` and `toState`. - Nothing is reported when no write happens (message events, updates to terminal tasks, events for unknown tasks) or when the store write throws. - The handler passes its plugins to every `ResultManager` it creates: `sendMessage`, `sendMessageStream`, and both cancel paths. That includes the direct CANCELED write when no agent is running. - A follow-up message to an existing task appends it to the history and saves it directly. That write is reported with no `event` and an unchanged state. - `onTaskEvent` runs after the per-task write lock is released, so a hook may write to the same task, for example to cancel it, without deadlocking. The states in each report are captured inside the lock, so they match that write. Reports from one request arrive in write order. Reports from concurrent requests on the same task may interleave. - Errors thrown by `onTaskEvent` are logged and ignored. `ResultManager` is public, so `plugins` is an optional third constructor argument and existing callers are unaffected. The fields match a2a-python's `TaskEventInfo`.
This was referenced Nov 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Wires the server hooks from
@a2a-js/sdk/plugins(#826) intoDefaultRequestHandler. Plugins are registered through a newpluginsoption.Example