Skip to content

Python: a first-class fatal signal for function middleware (fail-closed escape from the auto-invoke loop) #7522

Description

@MohammadHaroonAbuomar

Follow-up from #7515 (raised by @moonbox3 in review: #7515 (comment)).

_auto_invoke_function converts every function-middleware exception into a tool error and keeps looping (_tools.py), so the only loud escape from the loop today is MiddlewareTermination. Middleware that needs fail-closed semantics (enforcement layers, guardrails) must mutate shared state, raise the loop's one loud exception, and re-raise the real failure two hops away at the run boundary.

Proposal (either shape):

  • a fatal flag on MiddlewareTermination that the loop re-raises instead of absorbing, or
  • a dedicated MiddlewareFailure exception the loop propagates.

Either would give every function-middleware author fail-closed semantics without the state-mutation dance, and would let the agent-hooks feature (#7515) delete its halted-state back-channel and the approval-request special case.

Deliberately not included in #7515 since it widens the _tools loop contract.

Metadata

Metadata

Assignees

Labels

agentsUsage: [Issues, PRs], Target: Single agentmiddlewareUsage: [Issues, PRs], Target: middleware related featurespythonUsage: [Issues, PRs], Target: Python

Type

Projects

Status
No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions