Apply model and tool calls through an ordered middleware chain. Each layer may inspect, annotate, redact, or reject a call, but the final handler must see the composed result exactly once.Middleware-pipeline loop
Layer behavior around model/tool calls.
model_or_tool_call_boundaryRECORD STATUSCandidate · v0.1.0UML class view
The proposed contract drawn as participant roles, received calls, and numbered dependencies.
Object interactions
The same roles and calls as a class collaboration and a numbered message sequence.
Pointcut
Where the mechanism applies. All four dimensions belong to the proposed match, not just its vocabulary.
- Context
- A harness surrounds model or tool invocation with extensible behavior.
- Trigger
- A call enters or leaves the runtime boundary.
- Structure
- Ordered middleware entries with a continuation or short-circuit result.
- Effect
- Logging, policy, retry, or context behavior runs in declared order.
Protected contract
The obligation that clients, operators, and auditors should be able to rely on.
- Requires
- The boundary exposes a composable continuation contract.
- Ensures
- Middleware executes in deterministic order and the final result reaches the loop.
- Invariant
- A middleware does not silently bypass required downstream layers.
- Violation
- Short circuits and exceptions unwind deterministically with one terminal result.
Negative control
A hard-coded helper call is not a middleware pipeline.
Variation & lifecycle
The hot spot is admitted only where the protected semantics survive.
Permitted variation
Registration order, retry, redaction, tracing, and policy middleware.
Test obligation
Test order, short circuit, exception, and repeated side-effect calls.
Evolution question
Did provider-specific logic move into policy or middleware layers?
Prompt + code design
An illustrative prompt and a small design sketch for the proposed contract. Names and APIs are invented; this is not a repository excerpt.
def compose(layers, handler):
call = handler
for layer in reversed(layers):
call = layer(call)
return call
pipeline = compose(
[trace_calls, redact_secrets, enforce_budget, retry_transient],
invoke_model,
)
result = pipeline(request)Illustrative design sketch. Order is part of the contract; record the resolved chain with the result. This example is a teaching aid, not implementation evidence or a conformance claim.
Detection & matching
The frozen rule that retrieves this record, the canonical source exemplar, and the control that should stay unmatched.
- Join point
model_or_tool_call_boundary- Source locator
- Barbaste et al., §6.2, p. 14 (Mistral Vibe, “Middleware-Pipeline Loop”); Table 11, p. 52; source label
- Lexical cue
(?i)\bmiddleware\b|\badd_middleware\b|\bon_[a-z_]+\bFrozen expression, v0.1.0. A match is a retrieval cue, not a confirmed implementation.- Aliases
- None
- Canonical exemplar
- microsoft/agent-framework
python/packages/core/agent_framework/_middleware.py:860Support: python/packages/core/tests/core/test_middleware_context_result.py:46 - Negative control
- A hard-coded helper call is not a middleware pipeline.
Scope-anchored review. pohe-agent analyze <repo> --pattern P04 anchors the cue to its enclosing declaration and checks a separate operational signature for all four pointcut dimensions. Missing roles and negative-control risks remain visible; a structural match is not E2/E3. Calibration report ↗
Repository files
Up to five public files retrieved by the frozen cue and pinned to the audited commit. A match is a place to inspect, not a confirmed implementation.
python/packages/core/agent_framework/_middleware.py:860CANONICAL SOURCE02aaif-goose/goosecrates/goose/src/acp/provider.rs:1227RETRIEVAL CUE03agno-agi/agnolibs/agno/agno/db/singlestore/singlestore.py:567RETRIEVAL CUE04Aider-AI/aideraider/analytics.py:105RETRIEVAL CUE05anomalyco/opencodepackages/ai/example/tutorial.ts:225RETRIEVAL CUEEvidence & provenance
Each layer answers a different question. Do not substitute retrieval for review.
Source-located exemplar
A concrete source anchor is available for this proposed record. It is one exemplar, not evidence that all repositories—or every contract field—conform.
Review boundary: this candidate and its specification come from an AI-assisted study. Independent human validation remains open.
94.4% of repository families in the frozen panel have at least one current cue, historical cue, or canonical source layer. This is not confirmed prevalence.
Current lexical-cue repositories: 38 / 4171e56792f5dbpython/packages/core/agent_framework/_middleware.py:860python/packages/core/tests/core/test_middleware_context_result.py:46Typed agent middleware pipeline.
Exploratory retrieval cue Regex / v0.1.0
(?i)\bmiddleware\b|\badd_middleware\b|\bon_[a-z_]+\bThis expression is a discovery instrument only. A match is a retrieval cue—not a confirmed implementation, pointcut match, or contract proof.