@@ -67,6 +67,9 @@ public Flux<String> buildStreamFlux(AgentSession session, ReActAgent agent, Chat
6767 prompt = Prompt .of ();
6868 }
6969
70+ //记录最新的选择
71+ session .attrs ().put ("_model_selected_tmp" , chatModel .getNameOrModel ());
72+
7073 return agent .prompt (prompt )
7174 .session (session )
7275 .options (o -> {
@@ -176,29 +179,6 @@ private String onReasonChunk(ReasonChunk reason) {
176179 return "" ;
177180 }
178181
179- private String onThoughtChunk (AgentSession session , ThoughtChunk thought ) {
180- if (weChatLink != null ) {
181- if (weChatLink .isBound (session .getSessionId ())) {
182- //回复微信
183- weChatLink .sendReply (session .getSessionId (), thought .getContent ());
184- }
185- }
186-
187-
188- if (thought .hasMeta (TaskSkill .TOOL_MULTITASK )) {
189- // 仅在多任务并行且有内容时输出
190- String content = thought .getAssistantMessage ().getResultContent ();
191- if (Assert .isNotEmpty (content )) {
192- //content = content + "`(" + thought.getTrace().getOptions().getChatModel().getNameOrModel() + ")`";
193-
194- return new ONode ().set ("type" , "text" )
195- .set ("text" , "\n " + content )
196- .toJson ();
197- }
198- }
199-
200- return "" ;
201- }
202182
203183 private String onActionEndChunk (ActionEndChunk action ) {
204184 if (Assert .isNotEmpty (action .getToolName ())) {
@@ -234,13 +214,51 @@ private String onActionEndChunk(ActionEndChunk action) {
234214 return "" ;
235215 }
236216
217+ private String onThoughtChunk (AgentSession session , ThoughtChunk thought ) {
218+ if (weChatLink != null ) {
219+ if (weChatLink .isBound (session .getSessionId ())) {
220+ //回复微信
221+ if (thought .isToolCalls ()) {
222+ //说明是过程
223+ weChatLink .sendReply (session .getSessionId (), thought .getContent ());
224+ } else {
225+ //说明是结果
226+ String modelSelectedTmp = (String ) session .attrs ().get ("_model_selected_tmp" );
227+
228+ if (thought .getTrace ().getOptions ().getChatModel ().getNameOrModel ().equals (modelSelectedTmp )) {
229+ //说明是发起代理
230+ StringBuilder traceInfo = getTraceInfo (thought .getTrace ());
231+ weChatLink .sendReply (session .getSessionId (), thought .getContent () + traceInfo );
232+ } else {
233+ weChatLink .sendReply (session .getSessionId (), thought .getContent ());
234+ }
235+ }
236+ }
237+ }
238+
239+
240+ if (thought .hasMeta (TaskSkill .TOOL_MULTITASK )) {
241+ // 仅在多任务并行且有内容时输出
242+ String content = thought .getAssistantMessage ().getResultContent ();
243+ if (Assert .isNotEmpty (content )) {
244+ //content = content + "`(" + thought.getTrace().getOptions().getChatModel().getNameOrModel() + ")`";
245+
246+ return new ONode ().set ("type" , "text" )
247+ .set ("text" , "\n " + content )
248+ .toJson ();
249+ }
250+ }
251+
252+ return "" ;
253+ }
254+
237255 private String onFinalChunk (AgentSession session , ReActChunk react ) {
238256 StringBuilder traceInfo = getTraceInfo (react .getTrace ());
239257
240- if (weChatLink != null ) {
258+ if (react . isAbnormal () && weChatLink != null ) {
241259 if (weChatLink .isBound (session .getSessionId ())) {
242260 //回复微信
243- weChatLink .sendReply (session .getSessionId (), traceInfo . toString () );
261+ weChatLink .sendReply (session .getSessionId (), react . getContent () + traceInfo );
244262 }
245263 }
246264
0 commit comments