Python: agent-framework-agent-hooks — middleware adapter for the AGENT-HOOKS-0.1 control contract - #1
Draft
MohammadHaroonAbuomar wants to merge 5 commits into
Draft
Conversation
Survey of how the eight interception points of the agent-hooks control contract (github.com/responsibleai/agent-hooks) land on the Python middleware pipeline: agent/chat/function middleware cover six points cleanly; the run brackets are synthesized with a session-per-run scope; streaming post-action points and session-scoped brackets are the two seams that would need upstream support. Signed-off-by: MohammadHaroonAbuomar <40180927+MohammadHaroonAbuomar@users.noreply.github.com>
agent-framework-agent-hooks implements AGENT-HOOKS-0.1 on the middleware pipeline: the middleware trio emits the eight interception points (session-per-run scope), block verdicts terminate via MiddlewareTermination with the post-action result discarded, transforms write back through the context so execution uses the approved value, and composition/approval/identity/record semantics come from the published agent-hooks-sdk package. Tests cover allow/deny/transform flows and no-op behavior outside a bracketed run. Signed-off-by: MohammadHaroonAbuomar <40180927+MohammadHaroonAbuomar@users.noreply.github.com>
Adopts the deny constructor introduced in 0.1.0a4 in place of wire dicts; transform and allow verdicts use the typed constructors. Signed-off-by: MohammadHaroonAbuomar <40180927+MohammadHaroonAbuomar@users.noreply.github.com>
Signed-off-by: MohammadHaroonAbuomar <40180927+MohammadHaroonAbuomar@users.noreply.github.com>
MohammadHaroonAbuomar
left a comment
Owner
Author
There was a problem hiding this comment.
Review pass (self-review before sharing). Findings; fixes follow on the branch.
- post_tool_call is skipped when the tool raises.
AgentHooksFunctionMiddleware.processemits the post point only on the success path; a raisingcall_nextpropagates withoutpost_tool_call(is_error: true). The contract brackets every completed invocation, success or error. - Raw
context.resultflows into the post_tool_call value. A non-JSON-serializable tool result would fail inside the emitter's marshalling, terminating the run with a crash-shaped error rather than a typed record; project the value defensively the way_arguments_to_dictdoes for arguments.
MohammadHaroonAbuomar
force-pushed
the
feature/agent-hooks-contract
branch
from
July 30, 2026 04:33
6104483 to
479b412
Compare
A raising tool invocation still emits post_tool_call with tool_result.is_error before the exception propagates, and tool results are projected to JSON-safe values before marshalling so an exotic result type cannot crash the record path. Covered by a new test. Signed-off-by: MohammadHaroonAbuomar <40180927+MohammadHaroonAbuomar@users.noreply.github.com>
MohammadHaroonAbuomar
force-pushed
the
feature/agent-hooks-contract
branch
from
July 30, 2026 04:33
479b412 to
00ea9f5
Compare
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.
Problem
Controls for agentic workloads (policy engines, approval flows, information-flow checks, audit pipelines) are rebuilt per framework, and each framework answers differently whether a control can stop an action, what happens when a control crashes, and what evidence exists afterwards. AGENT-HOOKS-0.1 (https://github.com/responsibleai/agent-hooks) is a framework-neutral control contract: eight interception points, a three-verdict model (allow / deny with optional human-approval lift / transform), normative fail-closed host obligations, and a conformance kit that makes "supported" checkable (https://responsibleai.github.io/agent-hooks/).
What this adds
A self-contained workspace package,
agent-framework-agent-hooks, following the layout of the existing integration packages. One factory wires the contract into the middleware pipeline:Middleware mapping (full analysis in MAPPING.md)
AgentMiddlewareinput/output(plus synthesizedagent_startup/agent_shutdownper run)ChatMiddlewarepre_model_call/post_model_callFunctionMiddlewarepre_tool_call/post_tool_call(transform writes back into executed arguments)All three tiers have native control semantics (
call_next,MiddlewareTermination, result override), so blocking and transforming compose with the framework rather than fighting it. Deny anywhere raisesMiddlewareTermination; adapter errors terminate the run (fail closed), never fall through.Limitations (deliberate, documented in MAPPING.md)
agent_startup/agent_shutdownbracket one agent run (a session-scoped seam is the concrete upstream ask).stream_result_hooksintegration (natural follow-up).post_model_calltool-call extraction is best-effort across client result shapes.Test evidence
5/5 pytest green against published
agent-hooks-sdk 0.1.0a4: run-point sequencing, deny-blocks-tool with post-point suppression and session-trail closure, transform write-back proving execution sees the approved value, and no-op behavior outside a bracketed run. Ruff clean under the repository configuration.Conformance
The contract ships a 47-vector conformance kit and a public claims registry; the reference policy runtime (https://github.com/responsibleai/agent-control-spec) passes 46/47 as an interceptor-side consumer. An Agent Framework host conformance claim would follow once the streaming and session seams land.