fix: agent call stop sign

This commit is contained in:
archer
2025-09-02 13:16:16 +08:00
parent 876cfb8673
commit 13c6e54f85
2 changed files with 23 additions and 14 deletions

View File

@@ -72,17 +72,6 @@ export const runAgentCall = async ({
let requestMessages = messages;
console.log(
JSON.stringify(
{
messages: requestMessages,
tools: subApps
},
null,
2
)
);
let inputTokens: number = 0;
let outputTokens: number = 0;
const subAppUsages: ChatNodeUsageType[] = [];
@@ -95,6 +84,7 @@ export const runAgentCall = async ({
// TODO: Context agent compression
// console.log(JSON.stringify(requestMessages, null, 2));
// Request LLM
let {
reasoningText: reasoningContent,
@@ -153,13 +143,16 @@ export const runAgentCall = async ({
messages: requestMessages.slice(requestMessagesLength),
getToolInfo
})[0] as AIChatItemType;
assistantResponses.push(...currentAssistantResponses.value);
if (currentAssistantResponses) {
assistantResponses.push(...currentAssistantResponses.value);
}
// Usage concat
inputTokens += usage.inputTokens;
outputTokens += usage.outputTokens;
if (isEndSign) {
if (isEndSign || toolCalls.length === 0) {
break;
}
}

View File

@@ -38,6 +38,7 @@ import json5 from 'json5';
import type { ChatCompletionTool } from '@fastgpt/global/core/ai/type';
import type { ToolNodeItemType } from './type';
import { textAdaptGptResponse } from '@fastgpt/global/core/workflow/runtime/utils';
import { sliceStrStartEnd } from '@fastgpt/global/common/string/tools';
export type DispatchAgentModuleProps = ModuleDispatchProps<{
[NodeInputKeyEnum.history]?: ChatItemType[];
@@ -193,10 +194,25 @@ export const dispatchRunAgent = async (props: DispatchAgentModuleProps): Promise
isToolCall: true
});
dispatchFlowResponse.push(...flowResponses);
const response = formatToolResponse(toolResponses);
workflowStreamResponse?.({
event: SseResponseEventEnum.toolResponse,
data: {
tool: {
id: call.id,
toolName: '',
toolAvatar: '',
params: '',
response: sliceStrStartEnd(response, 5000, 5000)
}
}
});
// TODO: 推送账单
return {
response: formatToolResponse(toolResponses),
response,
usages: flowUsages,
isEnd: false
};