Python: Add HOL Guard middleware sample - #7840
Python: Add HOL Guard middleware sample#7840samsul hoque mondal (deathsamsul) wants to merge 3 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) |
83d87c7 to
86fb436
Compare
|
HOL Guard maintainer clarification on the open contract question:
So for this sample I’d either keep Current parser source for the explicit policy command: https://github.com/hashgraph-online/hol-guard/blob/release/3.0/src/codex_plugin_scanner/guard/cli/commands_parser_policy.py |
…approval framing, default demo to fail-closed
59c8f9d to
cd51443
Compare
|
Closing per the message on the issue. |
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