F1 · Builds middleware around modify_model_request, a hook that exists in no released langchain 1.x — the middleware is registered and never fires
The hook was gone by langchain 1.0.0 (2025-10-17), inside the subject's stated 2026-01 window. Not a duplicate of any v1 finding: langchain/v1 charged this subject for langgraph.prebuilt.create_react_agent and langchain.hub, and never touched the middleware hook set.
"I'm confident the hook-based middleware pattern and modify_model_request name are right in spirit; I'm less sure system_prompt is still the exact current field name."
class DateStampedInstructionsMiddleware(AgentMiddleware):
def modify_model_request(self, request: ModelRequest, state, runtime) -> ModelRequest:
base = request.system_prompt or ""
stamp = f"\n\nToday's date is {date.today().isoformat()}."
request.system_prompt = base + stamp
return requestclass DateStampedInstructionsMiddleware(AgentMiddleware):
def wrap_model_call(self, request, handler):
base = request.system_message.text if request.system_message else ""
stamp = f"\n\nToday's date is {date.today().isoformat()}."
return handler(
request.override(system_message=SystemMessage(content=base + stamp))
)Nothing raises. Python permits any method on a subclass, and create_agent only ever calls the hooks it knows about, so the middleware is constructed, passed in, listed in the agent's middleware, and never invoked. Every model call goes out without the date. The failure is invisible at construction, invisible at import, and only shows up as an agent that does not know what day it is.
The same snippet contains a second stale belief — it assigns request.system_prompt = ... in place, which 1.1.0 deprecated in favour of request.override(...). It is deliberately NOT charged as a separate finding: the assignment is unreachable, because the method it sits in is never called. Charging both would double-count one wrong answer, and the Index would rather under-count than pad. Recorded here so the second defect is on the record without being on the scoreboard.
- langchain 1.3.18 published wheel — langchain/agents/middleware/types.py (the shipped hook set; `modify_model_request` appears nowhere in the 1.0.0, 1.1.0, 1.2.0 or 1.3.18 wheels) published 2026-08-27
def before_agent(self, state: StateT, runtime: Runtime[ContextT]) -> dict[str, Any] | None: ... def before_model(self, state: StateT, runtime: Runtime[ContextT]) -> dict[str, Any] | None: ... def wrap_model_call( ... def after_model(self, state: StateT, runtime: Runtime[ContextT]) -> dict[str, Any] | None:
- LangChain v1 migration guide published 2025-10-17
The v1 middleware surface is the AgentMiddleware hook set used by create_agent; the alpha-era modify_model_request signature did not ship in the 1.0 release line.