← Back to hub

Middleware — the 1.0 control layer

Status CoveredUpdated 1 Jul 2026

In one line

Plugins that wrap the model call and change behavior without rewriting the agent.

Ready-made middleware

MiddlewareWhat it does
PIIMiddlewareRedacts or blocks private data.
SummarizationMiddlewareShrinks long chat history.
HumanInTheLoopMiddlewarePauses for approval on risky tools.

Custom: subclass AgentMiddleware and hook wrap_model_call — e.g. pick a bigger model for expert users.

New: RubricMiddleware (Deep Agents)

Added June 2026 (beta). It makes an agent grade its own work and try again until it is good enough. You set up the middleware once, then pass a rubric (a checklist) when you call the agent. A small grader sub-agent scores each item. If any item fails, the feedback goes back to the agent and it runs again — until the rubric passes or it hits max_iterations. Best for tasks with clear pass/fail rules, like "all tests pass" or "every section is covered".

from deepagents import RubricMiddleware, create_deep_agent

grader = RubricMiddleware(
    model="anthropic:claude-haiku-4-5",   # small, cheap grader
    system_prompt="Grade the code against the rubric.",
    tools=[run_test_suite],
    max_iterations=5,
)
agent = create_deep_agent(model="anthropic:claude-sonnet-4-6", middleware=[grader])
result = agent.invoke({"messages": [...], "rubric": "- All tests pass\n"})
Note. Beta — the API may still change. If you pass no rubric, the middleware does nothing.

Links

My notes

Add your own findings here as you learn.