Skip to content

feat: Add execution plugin hooks around AgentExecutor - #839

Merged
bartek-gralewicz merged 3 commits into
mainfrom
bgralewicz/execution_hooks
Nov 20, 2026
Merged

bartek-gralewicz merged 3 commits into
mainfrom
bgralewicz/execution_hooks

Conversation

@bartek-gralewicz

Copy link
Copy Markdown
Collaborator

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.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

🧪 Code Coverage

⬇️ Download Full Report

Base PR Delta
src/server/request_handler/default_request_handler.ts 86.9% 86.93% 🟢 +0.03%
src/server/agent_execution/plugin_agent_executor.ts (new) — 100% —
Total 85.04% 85.12% 🟢 +0.08%

Generated by coverage-comment.yml

@bartek-gralewicz
bartek-gralewicz merged commit 9d5d38f into main Nov 20, 2026
21 checks passed
@bartek-gralewicz
bartek-gralewicz deleted the bgralewicz/execution_hooks branch November 20, 2026 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants