Repository navigation
Python: docs(python): demonstrate per-tool execution deadlines - #9787
Open
Suhas Aggarwal (suhasagg) wants to merge 2 commits into
Open
Suhas Aggarwal (suhasagg) wants to merge 2 commits into
Suhas Aggarwal (suhasagg) wants to merge 2 commits into
Conversation
Suhas Aggarwal (suhasagg)
requested review from
SergeyMenshykh and
Eduard van Valkenburg (eavanvalkenburg)
as code owners
October 28, 2026 08:08
Suhas Aggarwal (suhasagg)
temporarily deployed
to
github-app-auth
October 28, 2026 08:08 — with
GitHub Actions
Inactive
Suhas Aggarwal (suhasagg)
temporarily deployed
to
github-app-auth
October 28, 2026 08:09 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Deadline cleanup can swallow caller cancellation and suppress downstream MiddlewareFailure, converting a fatal error into a recoverable timeout for read-only tools instead of aborting the concurrent batch.
2 open issues
What changed in this PR
Adds a Python sample for #9235 demonstrating per-tool asynchronous deadlines through existing FunctionMiddleware, without introducing a new core API.
Changes:
- Adds configurable deadlines with recoverable read-only timeouts and fatal side-effecting timeouts.
- Adds offline tests covering execution, cancellation, cleanup, and concurrent-batch behavior.
- Documents usage and limitations, including cooperative cancellation and uncertain remote outcomes.
| File | Description |
|---|---|
python/samples/02-agents/middleware/test_per_tool_execution_deadlines.py |
Adds focused middleware tests and Agent-level batch cancellation coverage. |
python/samples/02-agents/middleware/README.md |
Documents commands, timeout behavior, and operational limitations. |
python/samples/02-agents/middleware/per_tool_execution_deadlines.py |
Implements deadline policies, middleware, and an offline demonstration. |
Review effort: Balanced
Suhas Aggarwal (suhasagg)
deployed
to
github-app-auth
October 28, 2026 10:28 — with
GitHub Actions
Active
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Motivation & Context
Developers using Microsoft Agent Framework may need different execution deadlines for different tools, particularly when an agent invokes multiple tools concurrently.
A single global timeout does not adequately represent tool-specific latency requirements or the different failure semantics of read-only and side-effecting operations.
This PR addresses #9235 by providing a focused Python sample demonstrating per-tool asynchronous execution deadlines using the existing
FunctionMiddlewareextension point and standardasyncioAPIs.The implementation follows the maintainer's guidance to avoid introducing a new core timeout API.
Description & Review Guide
What are the major changes?
New sample:
per_tool_execution_deadlines.pyFunctionMiddlewareextension point.asyncioAPIs.TimeoutErrorraised by the tool itself.Explicit timeout failure semantics
MiddlewareFailure, since the operation's outcome may be uncertain and side effects may already have occurred.Cancellation and cleanup guidance
Focused offline tests and documentation
test_per_tool_execution_deadlines.pywith 20 tests.What is the impact of these changes?
What do you want reviewers to focus on?
TimeoutError.MiddlewareFailurefor uncertain side-effecting outcomes.Validation
Local validation completed successfully:
git diff --checkpassed.All tests are offline and do not require external model API credentials.
Related Issue
Fixes #9235
Implementation follows the maintainer's October 27 guidance to use existing middleware and
asyncioAPIs rather than changing the core framework.AI Assistance
AI assistance details:
AI assistance was used for implementation guidance, test development. The changes were reviewed and validated locally, including the focused test suite, existing framework regression coverage, and lint checks.
Contribution Checklist