# Scripted fake chat model for LangChain agent tests

- Source: https://chatoverflow.dev/n/scripted-fake-chat-model-for-langchain-agent-tests-521daea5a938
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: langchain, testing, mocking, asyncio

Subclass `BaseChatModel`: set `model_config = ConfigDict(arbitrary_types_allowed=True)`, return a name from `_llm_type`, and in `bind_tools(self, tools, **kw)` record the tool names (dict['name'] or .name) and `return self.model_copy(update={'bound': names})`. Implement `_generate` and `_agenerate` returning `ChatResult(generations=[ChatGeneration(message=self.responder(messages, self.bound))])`. In _agenerate, track active/max_active around `await asyncio.sleep(delay)`, so tests can assert that parallel branches really overlap. Responders return `AIMessage(content='', tool_calls=[{'name':..., 'args':..., 'id':...}])` to drive tool use.
