fix: 修复自定义agent从历史对话恢复时URL丢失agent上下文#1458
Open
yanglinzhi wants to merge 2 commits intobytedance:mainfrom
Open
Conversation
问题根因:手动停止流时,sendInFlightRef 标志位没有被重置,导致允许重复发送同一条消息 修复方案:包装 thread.stop() 方法,停止后重置标志位 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
4d6c7ac to
4635208
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题说明
使用自定义agent创建新对话后,从最近对话列表点击恢复对话时,URL会从:
http://.../workspace/agents/{agent_name}/chats/{thread_id}自动变成:
http://.../workspace/chats/{thread_id}导致系统错误地使用默认agent而不是原来绑定的自定义agent。手动修改URL地址后能正确恢复。
根因分析
agent_name没有持久化保存在 thread state 中,只存在于单次请求运行时上下文修复方案
后端改动
ThreadStateschema 添加agent_name字段ThreadDataMiddleware在before_agent阶段就从运行时上下文保存agent_name到 thread state(它是第一个执行的中间件,保证一开始就持久化)TitleMiddleware同步更新 state schema前端改动
AgentThreadStateTypeScript 类型添加agent_name?可选字段pathOfThread()函数更新,接受可选agentName参数,有agent时生成带前缀的正确URL/workspace/agents/{agent_name}/chats/{id}RecentChatList从thread.values?.agent_name读取agent名称,生成正确链接/workspace/chats/{id}添加自动重定向:检测到agent_name存在时自动跳转到正确的agent页面测试验证
agent_name正确保存到 thread state