Python: Add HOL Guard middleware sample - #7840
Python: Add HOL Guard middleware sample#7840samsul hoque mondal (deathsamsul) wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a Python FunctionMiddleware sample intended to guard tool execution with HOL Guard.
Changes:
- Adds HOL Guard evaluation with fail-closed middleware behavior.
- Adds an offline demonstration fallback.
- Adds allow, deny, and unavailable-path tests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
python/samples/02-agents/middleware/hol_guard_middleware.py |
Implements the middleware and runnable sample. |
python/tests/samples/agents/test_hol_guard_middleware.py |
Tests guard decisions and tool execution behavior. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| # dependencies = [ | ||
| # "agent-framework-foundry", | ||
| # ] |
| payload = json.loads(stdout) | ||
| decision = GuardDecision(payload.get("decision", "deny")) | ||
| return decision, payload.get("reason", payload.get("summary", "")) |
| hol_guard_middleware = _load_hol_guard_module() | ||
| GuardDecision = hol_guard_middleware.GuardDecision | ||
| HOLGuardMiddleware = hol_guard_middleware.HOLGuardMiddleware | ||
| evaluate_with_hol_guard = hol_guard_middleware.evaluate_with_hol_guard |
| from pydantic import BaseModel, Field | ||
|
|
||
| """ | ||
| Official HOL Guard FunctionMiddleware example for protected tool calls (issue #7833). |
| stdout=asyncio.subprocess.PIPE, | ||
| stderr=asyncio.subprocess.PIPE, | ||
| ) | ||
| stdout, stderr = await asyncio.wait_for(proc.communicate(), timeout=timeout_seconds) |
|
samsul hoque mondal (@deathsamsul) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
83d87c7 to
86fb436
Compare
Motivation & Context
This PR adds a HOL Guard
FunctionMiddlewaresample for protecting tool calls.It provides a deterministic enforcement point before tool execution and fails closed when HOL Guard is unavailable or returns a non-allow decision.
This addresses the requirements described in issue #7833.
Description & Review Guide
What are the major changes?
HOLGuardMiddlewaresample.call_next().allow.What is the impact of these changes?
What do you want reviewers to focus on?
Related Issue
Fixes #7833
Contribution Checklist