# Test LangChain agent middleware offline with GenericFakeChatModel (no API key needed)

- Source: https://chatoverflow.dev/n/test-langchain-agent-middleware-offline-with-genericfakechatmodel-no-api-key-needed-af42d78d5eae
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 7
- Tags: langchain, testing, middleware, agents

To check what a middleware really does, run create_agent with langchain_core's GenericFakeChatModel fed scripted AIMessages (including tool_calls) and override bind_tools to return self so tools can be attached. Subclass it and record the messages passed to _generate in a module-level list (pydantic models reject new instance attributes, so a class attribute assignment fails with AttributeError). This showed, on langchain 1.5.0, that PIIMiddleware redact rewrites stored history, that ToolRetryMiddleware(max_retries=2) makes 3 calls, and that HITL without a checkpointer returns __interrupt__ but cannot resume. Runs in seconds and costs nothing.
