From e744e9c4ef4cf6ca9199c0d78990f049b3defcaf Mon Sep 17 00:00:00 2001 From: Dong_master <2213070223@qq.com> Date: Tue, 12 Aug 2025 11:25:37 +0800 Subject: [PATCH] fix: in the localagent.py yield MessageChunk add agr tool_calls,and After calling the "tool_calls", the first returned body data will be concatenated. --- pkg/provider/modelmgr/requesters/modelscopechatcmpl.py | 1 + pkg/provider/runners/localagent.py | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/pkg/provider/modelmgr/requesters/modelscopechatcmpl.py b/pkg/provider/modelmgr/requesters/modelscopechatcmpl.py index d45c5d9e..3a3bb5b0 100644 --- a/pkg/provider/modelmgr/requesters/modelscopechatcmpl.py +++ b/pkg/provider/modelmgr/requesters/modelscopechatcmpl.py @@ -248,6 +248,7 @@ class ModelScopeChatCompletions(requester.ProviderAPIRequester): if hasattr(chunk, 'choices') and chunk.choices: choice = chunk.choices[0] delta = choice.delta.model_dump() if hasattr(choice, 'delta') else {} + print(delta) finish_reason = getattr(choice, 'finish_reason', None) else: delta = {} diff --git a/pkg/provider/runners/localagent.py b/pkg/provider/runners/localagent.py index d8732eac..49e3d46d 100644 --- a/pkg/provider/runners/localagent.py +++ b/pkg/provider/runners/localagent.py @@ -155,6 +155,7 @@ class LocalAgentRunner(runner.RequestRunner): yield llm_entities.MessageChunk( role=last_role, content=accumulated_content, # 输出所有累积内容 + tool_calls=list(tool_calls_map.values()) if (tool_calls_map and msg.is_final) else None, is_final=msg.is_final, ) @@ -166,6 +167,7 @@ class LocalAgentRunner(runner.RequestRunner): ) pending_tool_calls = final_msg.tool_calls + first_content = final_msg.content req_messages.append(final_msg) @@ -222,6 +224,10 @@ class LocalAgentRunner(runner.RequestRunner): if msg.role: last_role = msg.role + # 第一次请求工具调用时的内容 + if msg_idx == 1: + accumulated_content =first_content if first_content is not None else accumulated_content + # 累积内容 if msg.content: accumulated_content += msg.content