Catalog/P family/P04
Proposed specificationSource-located exemplarH1

Middleware-pipeline loop

Layer behavior around model/tool calls.

JOIN POINTmodel_or_tool_call_boundaryRECORD STATUSCandidate · v0.1.0
UML class view for Middleware-pipeline loop, showing participant roles, received calls, and analytical dependencies
FIG. P04 / UML CLASS VIEW
Object interaction diagram for Middleware-pipeline loop, showing role collaboration and a numbered message sequence
FIG. P04 / OBJECT INTERACTIONS
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.
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.

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 SKETCH
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.
CODE DESIGN / PYTHON
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.

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-frameworkpython/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 ↗

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.

ANY-EVIDENCE FAMILY COVERAGE34/36

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 / 41
Exploratory retrieval cue Regex / v0.1.0
(?i)\bmiddleware\b|\badd_middleware\b|\bon_[a-z_]+\b

This expression is a discovery instrument only. A match is a retrieval cue—not a confirmed implementation, pointcut match, or contract proof.