Skip to content

.Net: Microsoft.SemanticKernel.AgentHooks — host adapter for the AGENT-HOOKS-0.1 control contract - #14244

Draft
MohammadHaroonAbuomar wants to merge 6 commits into
microsoft:mainfrom
MohammadHaroonAbuomar:feature/agent-hooks-contract
Draft

.Net: Microsoft.SemanticKernel.AgentHooks — host adapter for the AGENT-HOOKS-0.1 control contract#14244
MohammadHaroonAbuomar wants to merge 6 commits into
microsoft:mainfrom
MohammadHaroonAbuomar:feature/agent-hooks-contract

Conversation

@MohammadHaroonAbuomar

Copy link
Copy Markdown

Problem

Controls for agentic workloads (policy engines, approval flows, information-flow checks, audit pipelines) are rebuilt per framework today, and each framework answers differently whether a control can actually 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 around the agent loop, a three-verdict model (allow / deny with optional human-approval lift / transform), normative fail-closed host obligations, and a conformance test kit that makes "supported" a checkable claim (https://responsibleai.github.io/agent-hooks/).

What this adds

A self-contained extension, Microsoft.SemanticKernel.AgentHooks, that makes a Semantic Kernel host emit interception points from the existing filter pipeline and honour interceptor verdicts. AddAgentHooks(options) registers one filter implementing all three filter interfaces; interceptors resolve from DI.

Filter mapping

Semantic Kernel seam Interception point
IFunctionInvocationFilter pre_tool_call / post_tool_call (transform writes back into KernelArguments / substitutes FunctionResult)
IPromptRenderFilter pre_model_call over the rendered prompt (transform rewrites RenderedPrompt)
IAutoFunctionInvocationFilter post_model_call once per model response carrying function calls
first interception per Kernel agent_startup (lazy, with the plugin function catalog)

A block verdict throws AgentHooksInterceptionBlockedException (a KernelException) without calling next, so enforcement fails closed through normal filter semantics.

Limitations (deliberate, documented in the class remarks)

  • input, output, and agent_shutdown have no Kernel-level seam; they exist conceptually at the Agents layer and are left to a follow-up.
  • pre_model_call sees the rendered prompt as a single message, not typed chat history.
  • One agent-hooks session per Kernel instance.

Test evidence

SemanticKernel.Extensions.AgentHooks.UnitTests: 5/5 passing — deny blocks invocation; transform rewrites arguments and result; approval-lifted deny proceeds; unresolved escalation blocks; records carry the composition profile. The ResponsibleAI.AgentHooks 0.1.0-alpha.4 package bundles its native library per RID, so tests run with no local native build.

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. A Semantic Kernel host conformance claim would follow once the remaining seams land.

Adapter that makes a Semantic Kernel host emit AGENT-HOOKS-0.1
interception points (https://github.com/responsibleai/agent-hooks) and
honour interceptor verdicts. Function invocations are bracketed as
pre_tool_call/post_tool_call with transform write-back to kernel
arguments and function results; prompt rendering emits pre_model_call
with rendered-prompt substitution; auto function invocation emits
post_model_call once per model response. Interceptors resolve from the
service collection; composition profile, enforcement mode, approval
resolver, and record sink are configurable via AddAgentHooks options.
Block verdicts surface as AgentHooksInterceptionBlockedException, so
enforcement fails closed through the filter pipeline.
Covers deny blocking function invocation, transform rewriting
arguments and results, liftable-deny approval flow with and without a
resolver, and record emission with the composition profile attached.
…pha.4

The package now bundles its native library per runtime identifier, so
the extension's tests run against the package assets with no local
native build.

Signed-off-by: MohammadHaroonAbuomar <40180927+MohammadHaroonAbuomar@users.noreply.github.com>
…post_tool_call on tool error

A denied agent_startup now blocks every subsequent emission for the
kernel session, and a tool invocation that throws still emits
post_tool_call with is_error before the exception propagates. Both
paths covered by new unit tests.

Signed-off-by: MohammadHaroonAbuomar <40180927+MohammadHaroonAbuomar@users.noreply.github.com>
A stable package version cannot carry the prerelease ResponsibleAI.AgentHooks
dependency (NU5104); the extension ships with VersionSuffix alpha, matching
the other early-stage packages in the repository.

Signed-off-by: MohammadHaroonAbuomar <40180927+MohammadHaroonAbuomar@users.noreply.github.com>
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.

1 participant