Skip to content

Python: Packages: add agent-framework-atr (ATR validation middleware provider) - #7062

Closed
Adam Lin (eeee2345) wants to merge 1 commit into
microsoft:mainfrom
eeee2345:feat/atr-package
Closed

Python: Packages: add agent-framework-atr (ATR validation middleware provider)#7062
Adam Lin (eeee2345) wants to merge 1 commit into
microsoft:mainfrom
eeee2345:feat/atr-package

Conversation

@eeee2345

Copy link
Copy Markdown
Contributor

Motivation & Context

PR #6528 (merged) added a sample showing deterministic validation at the tool-execution boundary (#5366), delegating detection to the open-source Agent Threat Rules (ATR) ruleset via the pyatr engine. Today it is only a sample.

This promotes that pattern to a first-class installable package, agent-framework-atr, mirroring the agent-framework-purview security-middleware package, so it gets pip-installable distribution, IDE autocompletion, and docs. See #7061 for the proposal and open questions.

Description & Review Guide

  • What are the major changes?

    • New package python/packages/atr/ (agent_framework_atr):
      • ATRFunctionMiddleware (FunctionMiddleware): blocks a tool call whose validated arguments match an ATR rule, before call_next() — so the tool never runs (the Add deterministic validation at execution boundary for agent actions #5366 pattern).
      • ATRAgentMiddleware (AgentMiddleware): scans inbound user messages and blocks the run on a match.
      • ATRDetector: a shared wrapper over the local pyatr engine; deterministic, no model call in the enforcement path. Both middleware support audit_only (shadow) mode and a min_severity threshold.
    • Package structure mirrors agent-framework-purview (pyproject with flit build, poe tasks, classifiers), plus README, LICENSE, and unit tests.
    • Wired into the uv workspace: agent-framework-atr added to [tool.uv.sources] and to core's [all] extra; uv.lock updated. Depends on agent-framework-core + pyatr (MIT, pure-Python, only needs pyyaml which core already ships).
  • What is the impact of these changes?

  • What do you want reviewers to focus on?

    • The namespace / naming decision (see Python: Package the ATR validation middleware (#6528 sample) as an installable agent-framework-atr provider #7061).
    • Tooling note: ruff (format + lint) and the package unit tests pass locally (8 tests, 97% coverage) and the package builds with flit. The package-checks pyright step reports the same agent_framework-symbol-unknown diagnostics that agent-framework-purview also produces locally when pyright reads the framework's lazy re-exports; that job is advisory (continue-on-error). Glad to adjust if you invoke pyright differently.

Related Issue

Fixes #7061

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change.

…provider)

Packages the deterministic ATR validation middleware from the microsoft#6528 sample
(python/samples/02-agents/middleware/atr_validation_middleware.py) as an
installable agent-framework-atr package, mirroring the agent-framework-purview
package structure.

- ATRFunctionMiddleware blocks tool calls whose validated arguments match an
  ATR rule, at the tool-execution boundary (before call_next), per microsoft#5366.
- ATRAgentMiddleware scans inbound user messages and blocks the run on a match.
- ATRDetector is a shared wrapper over the local pyatr engine; detection is
  deterministic with no model call in the enforcement path.

Wires the package into the uv workspace (tool.uv.sources + core [all] extra)
and updates the lockfile. Adds README, LICENSE, and unit tests.

Signed-off-by: eeee2345 <eeee2345@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 10, 2026 21:21
@giles17 Giles Odigwe (giles17) added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python labels Jul 10, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new optional Python workspace package, agent-framework-atr, which integrates the local deterministic pyatr engine into Agent Framework middleware to block (or audit) ATR-matching user input and tool arguments.

Changes:

  • Introduces the new agent_framework_atr package with ATRDetector, ATRFunctionMiddleware, and ATRAgentMiddleware.
  • Adds unit tests, README, and package metadata (flit/uv/ruff/pyright/mypy configuration).
  • Wires the package into the Python workspace and core’s [all] extra, updating uv.lock.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
python/uv.lock Adds workspace + lock entries for agent-framework-atr and pyatr.
python/pyproject.toml Registers agent-framework-atr as a workspace member dependency.
python/packages/core/pyproject.toml Adds agent-framework-atr to core’s all optional extra.
python/packages/atr/tests/atr/test_middleware.py Adds unit tests covering block/allow and audit-only behavior.
python/packages/atr/README.md Documents intended usage patterns and configuration for ATR middleware.
python/packages/atr/pyproject.toml Defines the new distribution metadata and tooling configuration.
python/packages/atr/LICENSE Adds MIT license file for the new package.
python/packages/atr/agent_framework_atr/_middleware.py Implements agent + function middleware that call the detector and terminate on matches.
python/packages/atr/agent_framework_atr/_engine.py Implements ATRDetector wrapper around pyatr and returns a structured detection.
python/packages/atr/agent_framework_atr/init.py Exposes the public API surface via __all__.

Comment on lines +23 to +25
"Framework :: Pydantic :: 2",
"Typing :: Typed",
]
Comment on lines +59 to +66
def __init__(self, *, rules_dir: str | None = None, min_severity: str = "informational") -> None:
engine: Any = pyatr.ATREngine()
if rules_dir is None:
engine.load_default_rules()
else:
engine.load_rules_from_directory(rules_dir)
self._engine: Any = engine
self._min_rank: int = _SEVERITY_ORDER.get(min_severity.lower(), 0)
@moonbox3

Copy link
Copy Markdown
Contributor

I don't think this warrants a completely new package that we have to manage / support.

@eeee2345

Copy link
Copy Markdown
Contributor Author

Thanks Evan Mattson (@moonbox3) — that's fair, and I appreciate you weighing in. The deterministic ATR check is already available as the merged sample (#6528), so there's no need to add a separately maintained package on your side. I'll close this PR and the tracking issue (#7061). Thanks for the consideration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Package the ATR validation middleware (#6528 sample) as an installable agent-framework-atr provider

4 participants