问题
DeerFlowClient 缺少标准的资源释放接口,当同一进程中需要创建/销毁多个客户端实例时,会出现:
- 内存泄漏(agent 对象无法被 GC 回收)
- 线程泄漏(LangGraph 线程池未终止)
- 数据库连接泄漏(checkpointer 强引用未释放)
- 潜在死锁(多实例共享资源冲突)
这是通用客户端库的基础设计要求,对所有 checkpointer 类型(memory/SQLite/Postgres)都适用。
解决方案
新增无侵入的 close() 方法:
def close(self) -> None:
"""Release internal agent and all references to prepare for instance disposal.
Unlike reset_agent() which rebuilds the agent for continued use of the same
client instance, this method is intended for permanent cleanup when the
client will no longer be used.
This does NOT close the underlying checkpointer — lifecycle of that object
is managed externally. Breaking the checkpointer reference allows the
external context manager to safely exit and release all database connections
and locks.
After calling close(), this client instance must be discarded and not reused.
"""
self.reset_agent()
self._checkpointer = None
优势
✅ 100% 向后兼容,不影响任何现有代码
✅ 无破坏性变更,仅新增接口
✅ 支持所有 checkpointer 类型
✅ 为第三方开发者提供标准资源管理规范
测试验证
已通过:
问题
DeerFlowClient缺少标准的资源释放接口,当同一进程中需要创建/销毁多个客户端实例时,会出现:这是通用客户端库的基础设计要求,对所有 checkpointer 类型(memory/SQLite/Postgres)都适用。
解决方案
新增无侵入的
close()方法:优势
✅ 100% 向后兼容,不影响任何现有代码
✅ 无破坏性变更,仅新增接口
✅ 支持所有 checkpointer 类型
✅ 为第三方开发者提供标准资源管理规范
测试验证
已通过: