Skip to content

Python: add task-scoped authority middleware sample - #10215

Open
aimable100 wants to merge 3 commits into
microsoft:mainfrom
aimable100:sample/task-scoped-authority-middleware
Open

aimable100 wants to merge 3 commits into
microsoft:mainfrom
aimable100:sample/task-scoped-authority-middleware

Conversation

@aimable100

Copy link
Copy Markdown

Motivation & Context

Adds the sample discussed in #9470: a coordinator hands a sub-agent authority for one task only, and a FunctionMiddleware enforces it on every tool call. The existing middleware samples cover blocking known attack patterns and asking a human; this one covers the case in between, where the sub-agent may act but only within the scope of the ticket it was given.

Maintainer direction is in #9470 (comment) ("this belongs in a sample using the existing FunctionMiddleware primitives").

Description & Review Guide

  • What are the major changes? A new single-file sample, python/samples/02-agents/middleware/task_scoped_authority_middleware.py, and one row in that folder's README. No package code changes.
  • What is the impact of these changes? Samples only. The sample declares tenuo (Apache-2.0) through PEP 723 inline metadata, so nothing is added to the dev environment.
  • What do you want reviewers to focus on? The denial path (context.result is set and call_next() is skipped, so the tool body never runs and the model sees the reason), and whether the file is the right size for this folder.

Checked with uv run poe syntax -S, uv run poe pyright -S and uv run poe test-typing -S; the new file is clean in each. Run end to end against a live model: the in-scope refund runs and the out-of-scope refund is denied before the tool body. I ran that with OpenAIChatClient swapped in, since I don't have a Foundry project to hand; the committed file uses FoundryChatClient like the neighbouring samples.

Related Issue

Fixes #9470

No other open PR exists for this issue.

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: implementation of the sample, the README row, and this PR description.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible (sample only; no package code or tests changed)
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Adds a FunctionMiddleware sample where a coordinator delegates a billing
ticket to a sub-agent with authority for one invoice and a refund ceiling.
Calls outside that scope are denied before the tool body runs.

Fixes microsoft#9470
@aimable100

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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.

🟡 Changes recommended

Negative refund amounts can execute successfully, and the shared FoundryChatClient leaves owned connections unclosed on both success and failure.

2 open issues
What changed in this PR

Adds a Python sample for #9470 showing how existing FunctionMiddleware primitives enforce task-scoped authority for a delegated billing agent. Changes are limited to samples and documentation; no framework package code changes.

Changes:

  • Uses Tenuo warrants to narrow delegated authority to one invoice and a refund ceiling.
  • Demonstrates returning authorization denials to the model without executing the tool.
  • Declares inline dependencies and adds the sample to the middleware index.
File Description
python/​samples/​02-agents/​middleware/​task_scoped_authority_middleware.py Adds the delegation, authorization middleware, and refund demonstration.
python/​samples/​02-agents/​middleware/​README.md Adds a link and description for the new sample.

Review effort: Balanced

This branch was previously deployed

1 inactive deployment
github-app-auth — 52e913bb Deployed Nov 10, 2026 by aimable100 via add_label #27449
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: Python sample: give a delegated sub-agent only the authority its task needs (FunctionMiddleware)

2 participants