快速结论:在 FastAPI 等异步 Web 服务中使用 Crew.akickoff(stream=True) 流式输出时,客户端断开连接不会自动取消内部 Agent/LLM 子任务,缺少 Support for Graceful Cancellation and Resource Cleanup via aclose()/cancel() on CrewStreamingOutput Streaming Objects 机制。优先升级到 crewAI 1.14.1+,并在遍历流式输出后显式调用 await streaming.aclose()。
适用环境:crewAI 1.14.1(该 Issue 已在此版本实现 aclose());Python 异步环境;FastAPI + StreamingResponse 场景(评论中提到);操作系统、CUDA、显卡型号未在 Issue 中确认。
最快修复方案:升级到 crewAI 1.14.1 或更高版本,在消费 CrewStreamingOutput 的 finally 块中调用 await streaming.aclose(),确保无论循环是否正常结束都能触发取消与清理。
注意事项:如果只 break 出 async for 循环但没有在 finally 中调用 aclose(),crew 仍可能在后台继续运行;若 LLM 提供商不支持强制中断,系统只能在最早的时机释放资源,无法保证立即停止。
问题场景
用户使用 crewAI 的异步流式接口 Crew.akickoff(inputs=..., stream=True) 获取 CrewStreamingOutput,并通过 FastAPI 的 StreamingResponse 把流式结果转发给浏览器或 HTTP 客户端。当客户端断开连接时,Python 的异步生成器协议会取消外层协程,但 CrewStreamingOutput 内部尚未完成的 Agent 子任务、LLM 调用和资源占用并不会随之取消,导致后台继续消耗 Token、计算资源和 GPU。
报错原文
Support for Graceful Cancellation and Resource Cleanup via aclose()/cancel() on CrewStreamingOutput Streaming Objects
原因分析
可能原因:CrewStreamingOutput 及其底层流式生成器(如 create_async_chunk_generator
参考来源
AI 工具推荐
想把多个 AI 模型放在一个入口?
GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。
推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。
这个方案解决了吗?
可以继续搜索完整报错,或查看同一工具的其他排查指南。
![[Question]: error when attaching file in chat ----AttributeError("'Request' object has no attribute 'file'")](https://www.chat-gpts.plus/wp-content/uploads/2026/08/11805-40332ec3-768x403.jpg)
![[Question]: No keyword or question was found in dataSet afer files loaded by customized ingestion pipeline](https://www.chat-gpts.plus/wp-content/uploads/2026/08/11474-a36958b1-768x403.jpg)
