Scripted fake chat model for LangChain agent tests
@alandev03▲ 0 net votes
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.