Repository navigation
feat(ahp): deliver Agent Hooks Protocol events at native seams - #267
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Inbound prompt hooks are bypassed for media-only ACP prompts and A2A requests, and denied ACP attachments remain in history. Hook-provided empty compaction summaries discard usable context. Tool completion events omit supplied results and misreport pre-invocation failures as executed.
Contributor
There was a problem hiding this comment.
Inbound prompt hooks are still bypassed for media-only ACP prompts and A2A requests, and denied ACP attachments remain in history. Hook-provided empty or whitespace-only compaction summaries discard usable context. Tool completion events still omit hook-supplied results and misreport pre-invocation failures as executed.
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.
Summary
Delivers Agent Hooks Protocol events to hooks registered in
~/.agents/hooks.jsonand<root>/.agents/hooks.json, using theagenthooksprotocol0.4.1 SDK. Each event is emitted from a seam that already exists in Kit or agentkit. Every agentkit crate stays on its published version.Motivation
This replaces the approach in #266, which hand-built event JSON, wrapped every tool individually, and depended on an unmerged agentkit fork.
Technical details
Where each event is emitted
session.start,model.request.before,model.response.after,model.errorHookedAdapter, aModelAdapter/ModelSession/ModelTurndecorator aroundSelectableAdapteruser.message.inboundPromptHook, aLoopMutatoratAfterTurnEnded, where every turn's admitted prompt is already in the transcript. Removing a denied prompt ends the turn without a model calltool.before,tool.afterhooked_tools, oneTooldecorator applied to the compose child registry incompose_with_jobs_and_mcpcontext.compact.before,context.compact.afterKitCompactionBackend::summarizesession.endrun_persistent/run_interruptibleand the shared ACPclean_up_sessionThe SDK owns protocol behavior
Events are typed SDK inputs passed to the SDK's named
Hooksmethods. Outcomes come back as typed settled events. The SDK handles ordering, merging, timeouts, failure policy, content selection and transports.Once a hooks file exists, Kit dispatches every event and the SDK skips routes that do not subscribe to it. Each tool's compiled input schema is cached until its spec changes.
Tool input edits
Edited input is validated against the tool's own
input_schemathrough an SDKContract. An edit that the hook does not also allow goes back through the tool'sproposed_requestsand the active permission checker. This is the same pathBasicToolExecutoruses.Failures
A dispatch failure denies the gating events:
tool.before,user.message.inboundandmodel.request.before. Observation failures and compaction edit failures are logged and leave the operation unchanged.An invalid registration disables hooks with a stderr warning rather than blocking startup.
Scope
Kit projects transcript items as text message parts. Media, files and reasoning are omitted.
These events are not emitted yet:
turn.*model.switch.*config.change.*file.changedThey need hooks in the duplicated ACP v1/v2 config paths or inside individual tools, so they are left for follow-ups.