Skip to content

Commit 68da930

Browse files
authored
[app-builder] provide sync entry for store app (#348)
* [app-builder] add AppSyncInvokerService * [app-builder] apply AppSyncInvokerService to invoke the store app * [app-builder] apply ToolExecuteService to the agent * [app-builder] apply ToolExecuteService to the loop node plugin * [app-builder] apply ToolExecuteService to the parallel node plugin * [app-builder] improve store app timeout config name * [app-builder] improve app identifier naming * [app-builder] polish code
1 parent b5c3b78 commit 68da930

File tree

13 files changed

+543
-85
lines changed

13 files changed

+543
-85
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved.
3+
* This file is a part of the ModelEngine Project.
4+
* Licensed under the MIT License. See License.txt in the project root for license information.
5+
*--------------------------------------------------------------------------------------------*/
6+
7+
package modelengine.fit.jober.aipp.dto;
8+
9+
import lombok.AllArgsConstructor;
10+
import lombok.Data;
11+
12+
/**
13+
* 应用标识信息。
14+
*
15+
* @author 宋永坦
16+
* @since 2025-07-24
17+
*/
18+
@Data
19+
@AllArgsConstructor
20+
public class AppIdentifier {
21+
private String tenantId;
22+
private String aippId;
23+
private String version;
24+
}

app-builder/jane/plugins/aipp-plugin/src/main/java/modelengine/fit/jober/aipp/fel/FelComponentConfig.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
import modelengine.fel.core.chat.Prompt;
1111
import modelengine.fel.engine.operators.patterns.AbstractAgent;
1212
import modelengine.fel.tool.mcp.client.McpClientFactory;
13-
import modelengine.fit.jade.tool.SyncToolCall;
13+
import modelengine.fel.tool.service.ToolExecuteService;
1414
import modelengine.fit.jober.aipp.constants.AippConst;
1515
import modelengine.fitframework.annotation.Bean;
1616
import modelengine.fitframework.annotation.Component;
1717
import modelengine.fitframework.annotation.Fit;
1818

1919
/**
20-
* FelComponentConfig
20+
* {@link AbstractAgent} 的实例提供器。
2121
*
2222
* @author 易文渊
2323
* @since 2024-04-23
@@ -27,14 +27,14 @@ public class FelComponentConfig {
2727
/**
2828
* 注入 WaterFlow 场景的 Agent。
2929
*
30-
* @param syncToolCall 表示同步工具调用服务的 {@link SyncToolCall}。
30+
* @param toolExecuteService 表示工具调用服务的 {@link ToolExecuteService}。
3131
* @param chatModel 表示模型流式服务的 {@link ChatModel}。
3232
* @param mcpClientFactory 表示大模型上下文客户端工厂的 {@link McpClientFactory}。
3333
* @return 返回 WaterFlow 场景的 Agent 服务的 {@link AbstractAgent}{@code <}{@link Prompt}{@code ,
3434
* }{@link Prompt}{@code >}。
3535
*/
3636
@Bean(AippConst.WATER_FLOW_AGENT_BEAN)
37-
public AbstractAgent getWaterFlowAgent(@Fit SyncToolCall syncToolCall, ChatModel chatModel, McpClientFactory mcpClientFactory) {
38-
return new WaterFlowAgent(syncToolCall, chatModel, mcpClientFactory);
37+
public AbstractAgent getWaterFlowAgent(@Fit ToolExecuteService toolExecuteService, ChatModel chatModel, McpClientFactory mcpClientFactory) {
38+
return new WaterFlowAgent(toolExecuteService, chatModel, mcpClientFactory);
3939
}
4040
}

app-builder/jane/plugins/aipp-plugin/src/main/java/modelengine/fit/jober/aipp/fel/WaterFlowAgent.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import modelengine.fel.engine.operators.patterns.AbstractAgent;
2525
import modelengine.fel.tool.mcp.client.McpClient;
2626
import modelengine.fel.tool.mcp.client.McpClientFactory;
27-
import modelengine.fit.jade.tool.SyncToolCall;
27+
import modelengine.fel.tool.service.ToolExecuteService;
2828
import modelengine.fit.jober.aipp.common.exception.AippErrCode;
2929
import modelengine.fit.jober.aipp.common.exception.AippException;
3030
import modelengine.fit.jober.aipp.constants.AippConst;
@@ -53,20 +53,20 @@ public class WaterFlowAgent extends AbstractAgent {
5353
private static final String GOTO_NODE_ID = "ahead_llm_node";
5454

5555
private final String agentMsgKey;
56-
private final SyncToolCall syncToolCall;
56+
private final ToolExecuteService toolExecuteService;
5757
private final McpClientFactory mcpClientFactory;
5858

5959
/**
6060
* {@link WaterFlowAgent} 的构造方法。
6161
*
62-
* @param syncToolCall 表示工具调用服务的 {@link SyncToolCall}。
62+
* @param toolExecuteService 表示工具调用服务的 {@link ToolExecuteService}。
6363
* @param chatStreamModel 表示流式对话大模型的 {@link ChatModel}。
6464
* @param mcpClientFactory 表示大模型上下文客户端工厂的 {@link McpClientFactory}。
6565
*/
66-
public WaterFlowAgent(@Fit SyncToolCall syncToolCall, ChatModel chatStreamModel,
66+
public WaterFlowAgent(@Fit ToolExecuteService toolExecuteService, ChatModel chatStreamModel,
6767
McpClientFactory mcpClientFactory) {
6868
super(new ChatFlowModel(chatStreamModel, null));
69-
this.syncToolCall = Validation.notNull(syncToolCall, "The tool sync tool call cannot be null.");
69+
this.toolExecuteService = Validation.notNull(toolExecuteService, "The tool execute service cannot be null.");
7070
this.mcpClientFactory = Validation.notNull(mcpClientFactory, "The mcp client factory cannot be null.");
7171
this.agentMsgKey = AGENT_MSG_KEY;
7272
}
@@ -145,7 +145,7 @@ private ChatMessage callTool(ToolCall toolCall, Map<String, ToolInfo> toolsMap,
145145
throw new AippException(AippErrCode.CALL_MCP_SERVER_FAILED, exception.getMessage());
146146
}
147147
}
148-
return new ToolMessage(toolCall.id(), this.syncToolCall.call(toolRealName, toolCall.arguments(), toolContext));
148+
return new ToolMessage(toolCall.id(), this.toolExecuteService.execute(toolRealName, toolCall.arguments()));
149149
}
150150

151151
private ChatMessages getAgentMsg(ChatMessage input, StateContext ctx) {

app-builder/jane/plugins/aipp-plugin/src/main/java/modelengine/fit/jober/aipp/fitable/WaterFlowInvoke.java

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,49 +9,67 @@
99
import modelengine.fit.jane.common.entity.OperationContext;
1010
import modelengine.fit.jober.WaterFlowService;
1111
import modelengine.fit.jober.aipp.constants.AippConst;
12-
import modelengine.fit.jober.aipp.genericable.AippRunTimeService;
12+
import modelengine.fit.jober.aipp.dto.AppIdentifier;
13+
import modelengine.fit.jober.aipp.service.AppSyncInvokerService;
1314
import modelengine.fitframework.annotation.Component;
1415
import modelengine.fitframework.annotation.Fit;
1516
import modelengine.fitframework.annotation.Fitable;
17+
import modelengine.fitframework.annotation.Value;
18+
import modelengine.fitframework.inspection.Validation;
19+
import modelengine.fitframework.serialization.ObjectSerializer;
1620
import modelengine.fitframework.util.MapBuilder;
1721
import modelengine.fitframework.util.ObjectUtils;
1822
import modelengine.fitframework.util.StringUtils;
1923

2024
import java.util.Map;
25+
import java.util.concurrent.TimeUnit;
2126

2227
/**
23-
* 工具流接口实现
28+
* 注册到 store 中应用调用的入口实现.
2429
*
2530
* @author 李鑫
2631
* @since 2024/4/24
2732
*/
2833
@Component
2934
public class WaterFlowInvoke implements WaterFlowService {
30-
private final AippRunTimeService aippRunTimeService;
35+
private final AppSyncInvokerService appSyncInvokerService;
36+
private final ObjectSerializer objectSerializer;
37+
private final long timeout;
3138

32-
public WaterFlowInvoke(@Fit AippRunTimeService aippRunTimeService) {
33-
this.aippRunTimeService = aippRunTimeService;
39+
/**
40+
* 基于应用同步执行服务的构造方法。
41+
*
42+
* @param appSyncInvokerService 表示应用同步执行服务的 {@link AppSyncInvokerService}。
43+
* @param objectSerializer 表示序列化器的 {@link ObjectSerializer}。
44+
* @param timeout 表示执行超时时间(单位秒)的 {@code long}。
45+
*/
46+
public WaterFlowInvoke(@Fit AppSyncInvokerService appSyncInvokerService,
47+
@Fit(alias = "json") ObjectSerializer objectSerializer,
48+
@Value("${app-engine.app.store.timeout:300}") long timeout) {
49+
this.appSyncInvokerService = appSyncInvokerService;
50+
this.objectSerializer = objectSerializer;
51+
this.timeout = TimeUnit.SECONDS.toMillis(Validation.greaterThan(timeout, 0, "The timeout should > 0."));
3452
}
3553

3654
@Override
3755
@Fitable(id = "water.flow.invoke")
3856
public String invoke(String tenantId, String aippId, String version, Map<String, Object> inputParams) {
39-
Map<String, Object> initContext = this.buildInitContext(inputParams);
40-
return this.aippRunTimeService.createAippInstance(aippId, version, initContext,
41-
this.buildOperationContext(tenantId, initContext));
57+
return this.objectSerializer.serialize(this.appSyncInvokerService.invoke(new AppIdentifier(tenantId,
58+
aippId,
59+
version),
60+
this.buildInitContext(inputParams),
61+
this.timeout,
62+
this.buildOperationContext(tenantId, inputParams)));
4263
}
4364

44-
private OperationContext buildOperationContext(String tenantId, Map<String, Object> initContext) {
45-
Map<String, Object> businessData = (Map<String, Object>) initContext.get(AippConst.BS_INIT_CONTEXT_KEY);
46-
String userId = ObjectUtils.cast(businessData.getOrDefault(AippConst.CONTEXT_USER_ID, StringUtils.EMPTY));
65+
private OperationContext buildOperationContext(String tenantId, Map<String, Object> inputParams) {
66+
String userId = ObjectUtils.cast(inputParams.getOrDefault(AippConst.CONTEXT_USER_ID, StringUtils.EMPTY));
4767
OperationContext context = new OperationContext();
4868
context.setTenantId(tenantId);
4969
context.setOperator(userId);
50-
context.setGlobalUserId(null);
51-
context.setAccount("dmx000000");
52-
context.setEmployeeNumber(null);
53-
context.setName("大模型");
54-
context.setOperatorIp("0:0:0:0:0:0:0:1");
70+
context.setAccount(userId);
71+
context.setName(userId);
72+
context.setOperatorIp(StringUtils.EMPTY);
5573
context.setSourcePlatform(StringUtils.EMPTY);
5674
context.setLanguage(StringUtils.EMPTY);
5775
return context;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package modelengine.fit.jober.aipp.service;
2+
3+
import modelengine.fit.jane.common.entity.OperationContext;
4+
import modelengine.fit.jober.aipp.dto.AppIdentifier;
5+
6+
import java.util.Map;
7+
8+
/**
9+
* 表示应用同步执行服务。
10+
*
11+
* @author 宋永坦
12+
* @since 2025-07-24
13+
*/
14+
public interface AppSyncInvokerService {
15+
/**
16+
* 执行应用并获取结果。
17+
*
18+
* @param appIdentifier 表示应用标识的 {@link AppIdentifier}。
19+
* @param initContext 表示应用启动参数的 {@link Map}{@code <}{@link String}{@code , }{@link Object}{@code >}。
20+
* @param timeout 表示超时时间(单位秒)的 {@code long}。
21+
* @param operationContext 表示操作上下文的 {@link OperationContext}。
22+
* @return 表示应用返回结果。
23+
*/
24+
Object invoke(AppIdentifier appIdentifier, Map<String, Object> initContext, long timeout,
25+
OperationContext operationContext);
26+
}

0 commit comments

Comments
 (0)