Skip to content

Commit 97b96a4

Browse files
committed
use langchain4g agentic api for agents
1 parent b3da32d commit 97b96a4

File tree

18 files changed

+146
-955
lines changed

18 files changed

+146
-955
lines changed

experimental/ai/impl/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919
<groupId>io.serverlessworkflow</groupId>
2020
<artifactId>serverlessworkflow-impl-core</artifactId>
2121
</dependency>
22-
<dependency>
23-
<groupId>io.serverlessworkflow</groupId>
24-
<artifactId>serverlessworkflow-experimental-types</artifactId>
25-
</dependency>
2622
<dependency>
2723
<groupId>io.serverlessworkflow</groupId>
2824
<artifactId>serverlessworkflow-experimental-ai-types</artifactId>

experimental/ai/impl/src/main/java/io/serverlessworkflow/impl/executors/ai/AIChatModelCallExecutor.java

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616

1717
package io.serverlessworkflow.impl.executors.ai;
1818

19-
import io.serverlessworkflow.ai.api.types.CallAILangChainChatModel;
19+
import io.serverlessworkflow.ai.api.types.CallAgentAI;
2020
import io.serverlessworkflow.api.types.TaskBase;
21-
import io.serverlessworkflow.api.types.ai.AbstractCallAIChatModelTask;
22-
import io.serverlessworkflow.api.types.ai.CallAIChatModel;
2321
import io.serverlessworkflow.impl.TaskContext;
2422
import io.serverlessworkflow.impl.WorkflowApplication;
2523
import io.serverlessworkflow.impl.WorkflowContext;
@@ -29,33 +27,26 @@
2927
import io.serverlessworkflow.impl.resources.ResourceLoader;
3028
import java.util.concurrent.CompletableFuture;
3129

32-
public class AIChatModelCallExecutor implements CallableTask<AbstractCallAIChatModelTask> {
30+
public class AIChatModelCallExecutor implements CallableTask<CallAgentAI> {
3331

3432
@Override
35-
public void init(
36-
AbstractCallAIChatModelTask task, WorkflowApplication application, ResourceLoader loader) {}
33+
public void init(CallAgentAI task, WorkflowApplication application, ResourceLoader loader) {}
3734

3835
@Override
3936
public CompletableFuture<WorkflowModel> apply(
4037
WorkflowContext workflowContext, TaskContext taskContext, WorkflowModel input) {
4138
WorkflowModelFactory modelFactory = workflowContext.definition().application().modelFactory();
42-
if (taskContext.task() instanceof CallAILangChainChatModel callAILangChainChatModel) {
39+
if (taskContext.task() instanceof CallAgentAI agenticAI) {
4340
return CompletableFuture.completedFuture(
44-
modelFactory.fromAny(
45-
new CallAILangChainChatModelExecutor()
46-
.apply(callAILangChainChatModel, input.asJavaObject())));
47-
} else if (taskContext.task() instanceof CallAIChatModel callAIChatModel) {
48-
return CompletableFuture.completedFuture(
49-
modelFactory.fromAny(
50-
new CallAIChatModelExecutor().apply(callAIChatModel, input.asJavaObject())));
41+
modelFactory.fromAny(new CallAgentAIExecutor().execute(agenticAI, input.asJavaObject())));
5142
}
5243
throw new IllegalArgumentException(
53-
"AIChatModelCallExecutor can only process CallAIChatModel tasks, but received: "
44+
"AIChatModelCallExecutor can only process CallAgentAI tasks, but received: "
5445
+ taskContext.task().getClass().getName());
5546
}
5647

5748
@Override
5849
public boolean accept(Class<? extends TaskBase> clazz) {
59-
return AbstractCallAIChatModelTask.class.isAssignableFrom(clazz);
50+
return CallAgentAI.class.isAssignableFrom(clazz);
6051
}
6152
}

experimental/ai/impl/src/main/java/io/serverlessworkflow/impl/executors/ai/AbstractCallAIChatModelExecutor.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

experimental/ai/impl/src/main/java/io/serverlessworkflow/impl/executors/ai/CallAIChatModelExecutor.java

Lines changed: 0 additions & 145 deletions
This file was deleted.

experimental/ai/impl/src/main/java/io/serverlessworkflow/impl/executors/ai/CallAILangChainChatModelExecutor.java

Lines changed: 0 additions & 86 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.serverlessworkflow.impl.executors.ai;
18+
19+
import dev.langchain4j.agentic.Cognisphere;
20+
import dev.langchain4j.agentic.internal.AgentExecutor;
21+
import dev.langchain4j.agentic.internal.AgentUtil;
22+
import io.serverlessworkflow.ai.api.types.CallAgentAI;
23+
import java.util.Map;
24+
25+
public class CallAgentAIExecutor {
26+
27+
private static final Cognisphere cognisphere = new Cognisphere();
28+
29+
public Object execute(CallAgentAI callAgentAI, Object input) {
30+
AgentExecutor agentExecutor = AgentUtil.agentToExecutor(callAgentAI.getAgentInstance());
31+
32+
Map<String, Object> output = (Map<String, Object>) input;
33+
34+
cognisphere.writeStates(output);
35+
36+
Object result = agentExecutor.invoke(cognisphere);
37+
38+
output.put(callAgentAI.getAgentInstance().outputName(), result);
39+
return output;
40+
}
41+
}

experimental/ai/impl/src/main/java/io/serverlessworkflow/impl/services/ChatModelService.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)