Skip to content

Commit 18a0a6b

Browse files
committed
Format and headers
Signed-off-by: Ricardo Zanini <[email protected]>
1 parent c106744 commit 18a0a6b

File tree

22 files changed

+462
-390
lines changed

22 files changed

+462
-390
lines changed

experimental/agentic/src/main/java/io/serverlessworkflow/impl/expressions/agentic/AgenticModelCollection.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,10 @@
1515
*/
1616
package io.serverlessworkflow.impl.expressions.agentic;
1717

18-
import com.fasterxml.jackson.core.type.TypeReference;
19-
import com.fasterxml.jackson.databind.ObjectMapper;
2018
import dev.langchain4j.agentic.scope.AgenticScope;
2119
import dev.langchain4j.agentic.scope.ResultWithAgenticScope;
22-
import io.cloudevents.CloudEvent;
23-
import io.cloudevents.CloudEventData;
2420
import io.serverlessworkflow.impl.WorkflowModel;
2521
import io.serverlessworkflow.impl.expressions.func.JavaModelCollection;
26-
import java.io.IOException;
2722
import java.util.Collections;
2823
import java.util.Map;
2924
import java.util.Optional;

experimental/agentic/src/main/java/io/serverlessworkflow/impl/expressions/agentic/AgenticModelFactory.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class AgenticModelFactory implements WorkflowModelFactory {
3030
static final String DEFAULT_AGENTIC_SCOPE_STATE_KEY = "input";
3131
private final AgenticScopeRegistryAssessor scopeRegistryAssessor =
3232
new AgenticScopeRegistryAssessor();
33-
private final AgenticScopeCloudEventsHandler scopeCloudEventsHandler = new AgenticScopeCloudEventsHandler();
33+
private final AgenticScopeCloudEventsHandler scopeCloudEventsHandler =
34+
new AgenticScopeCloudEventsHandler();
3435

3536
@SuppressWarnings("unchecked")
3637
private AgenticModel newAgenticModel(Object state) {
@@ -67,7 +68,8 @@ public WorkflowModel combine(Map<String, WorkflowModel> workflowVariables) {
6768

6869
@Override
6970
public WorkflowModelCollection createCollection() {
70-
return new AgenticModelCollection(this.scopeRegistryAssessor.getAgenticScope(), scopeCloudEventsHandler);
71+
return new AgenticModelCollection(
72+
this.scopeRegistryAssessor.getAgenticScope(), scopeCloudEventsHandler);
7173
}
7274

7375
@Override
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,70 @@
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+
*/
116
package io.serverlessworkflow.impl.expressions.agentic;
217

3-
import java.io.IOException;
4-
import java.util.Map;
5-
618
import com.fasterxml.jackson.core.type.TypeReference;
719
import com.fasterxml.jackson.databind.ObjectMapper;
820
import dev.langchain4j.agentic.scope.AgenticScope;
921
import io.cloudevents.CloudEvent;
1022
import io.cloudevents.CloudEventData;
23+
import java.io.IOException;
24+
import java.util.Map;
1125

1226
public final class AgenticScopeCloudEventsHandler {
1327

14-
private final ObjectMapper mapper = new ObjectMapper();
28+
private final ObjectMapper mapper = new ObjectMapper();
1529

16-
AgenticScopeCloudEventsHandler() {}
30+
AgenticScopeCloudEventsHandler() {}
1731

18-
public void writeState(final AgenticScope scope, final CloudEvent cloudEvent) {
19-
if (cloudEvent != null) {
20-
writeState(scope, cloudEvent.getData());
21-
}
32+
public void writeState(final AgenticScope scope, final CloudEvent cloudEvent) {
33+
if (cloudEvent != null) {
34+
writeState(scope, cloudEvent.getData());
2235
}
36+
}
2337

24-
public void writeState(final AgenticScope scope, final CloudEventData cloudEvent) {
25-
scope.writeStates(extractDataAsMap(cloudEvent));
26-
}
38+
public void writeState(final AgenticScope scope, final CloudEventData cloudEvent) {
39+
scope.writeStates(extractDataAsMap(cloudEvent));
40+
}
2741

28-
public boolean writeStateIfCloudEvent(final AgenticScope scope, final Object value) {
29-
if (value instanceof CloudEvent) {
30-
writeState(scope, (CloudEvent) value);
31-
return true;
32-
} else if (value instanceof CloudEventData) {
33-
writeState(scope, (CloudEventData) value);
34-
return true;
35-
}
36-
return false;
42+
public boolean writeStateIfCloudEvent(final AgenticScope scope, final Object value) {
43+
if (value instanceof CloudEvent) {
44+
writeState(scope, (CloudEvent) value);
45+
return true;
46+
} else if (value instanceof CloudEventData) {
47+
writeState(scope, (CloudEventData) value);
48+
return true;
3749
}
50+
return false;
51+
}
3852

39-
public Map<String, Object> extractDataAsMap(final CloudEventData ce) {
40-
try {
41-
if (ce != null) {
42-
return mapper.readValue(ce.toBytes(), new TypeReference<>() {
43-
});
44-
}
45-
} catch (IOException e) {
46-
throw new IllegalArgumentException("Unable to parse CloudEvent data as JSON", e);
47-
}
48-
return Map.of();
53+
public Map<String, Object> extractDataAsMap(final CloudEventData ce) {
54+
try {
55+
if (ce != null) {
56+
return mapper.readValue(ce.toBytes(), new TypeReference<>() {});
57+
}
58+
} catch (IOException e) {
59+
throw new IllegalArgumentException("Unable to parse CloudEvent data as JSON", e);
4960
}
61+
return Map.of();
62+
}
5063

51-
public Map<String, Object> extractDataAsMap(final CloudEvent ce) {
52-
if (ce != null) {
53-
return extractDataAsMap(ce.getData());
54-
}
55-
return Map.of();
64+
public Map<String, Object> extractDataAsMap(final CloudEvent ce) {
65+
if (ce != null) {
66+
return extractDataAsMap(ce.getData());
5667
}
68+
return Map.of();
69+
}
5770
}

experimental/agentic/src/main/java/io/serverlessworkflow/impl/expressions/agentic/langchain4j/AgenticScopeRegistryAssessor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import dev.langchain4j.agentic.scope.AgenticScope;
2020
import dev.langchain4j.agentic.scope.AgenticScopeRegistry;
2121
import dev.langchain4j.agentic.scope.DefaultAgenticScope;
22-
2322
import java.util.Map;
2423
import java.util.Objects;
2524
import java.util.UUID;

fluent/agentic/src/main/java/io/serverlessworkflow/fluent/agentic/AgentDoTaskBuilder.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@
1515
*/
1616
package io.serverlessworkflow.fluent.agentic;
1717

18-
import dev.langchain4j.agentic.Agent;
1918
import io.serverlessworkflow.fluent.agentic.spi.AgentDoFluent;
2019
import io.serverlessworkflow.fluent.func.FuncCallTaskBuilder;
2120
import io.serverlessworkflow.fluent.func.FuncEmitTaskBuilder;
2221
import io.serverlessworkflow.fluent.func.FuncForTaskBuilder;
2322
import io.serverlessworkflow.fluent.func.FuncForkTaskBuilder;
24-
import io.serverlessworkflow.fluent.func.FuncListenTaskBuilder;
2523
import io.serverlessworkflow.fluent.func.FuncSetTaskBuilder;
2624
import io.serverlessworkflow.fluent.func.FuncSwitchTaskBuilder;
2725
import io.serverlessworkflow.fluent.func.spi.ConditionalTaskBuilder;
Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,47 @@
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+
*/
116
package io.serverlessworkflow.fluent.agentic;
217

3-
import java.util.function.Predicate;
4-
518
import io.serverlessworkflow.api.types.AnyEventConsumptionStrategy;
619
import io.serverlessworkflow.api.types.ListenTask;
720
import io.serverlessworkflow.api.types.func.UntilPredicate;
821
import io.serverlessworkflow.fluent.spec.ListenTaskBuilder;
22+
import java.util.function.Predicate;
923

1024
public class AgentListenTaskBuilder extends ListenTaskBuilder<AgentTaskItemListBuilder> {
1125

12-
private UntilPredicate untilPredicate;
26+
private UntilPredicate untilPredicate;
1327

14-
public AgentListenTaskBuilder() {
15-
super(new AgentTaskItemListBuilder());
16-
}
28+
public AgentListenTaskBuilder() {
29+
super(new AgentTaskItemListBuilder());
30+
}
1731

18-
public <T> AgentListenTaskBuilder until(Predicate<T> predicate, Class<T> predClass) {
19-
untilPredicate = new UntilPredicate().withPredicate(predicate, predClass);
20-
return this;
21-
}
32+
public <T> AgentListenTaskBuilder until(Predicate<T> predicate, Class<T> predClass) {
33+
untilPredicate = new UntilPredicate().withPredicate(predicate, predClass);
34+
return this;
35+
}
2236

23-
@Override
24-
public ListenTask build() {
25-
ListenTask task = super.build();
26-
AnyEventConsumptionStrategy anyEvent =
27-
task.getListen().getTo().getAnyEventConsumptionStrategy();
28-
if (untilPredicate != null && anyEvent != null) {
29-
anyEvent.withUntil(untilPredicate);
30-
}
31-
return task;
37+
@Override
38+
public ListenTask build() {
39+
ListenTask task = super.build();
40+
AnyEventConsumptionStrategy anyEvent =
41+
task.getListen().getTo().getAnyEventConsumptionStrategy();
42+
if (untilPredicate != null && anyEvent != null) {
43+
anyEvent.withUntil(untilPredicate);
3244
}
33-
45+
return task;
46+
}
3447
}

fluent/agentic/src/main/java/io/serverlessworkflow/fluent/agentic/AgentTaskItemListBuilder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import io.serverlessworkflow.fluent.func.FuncEmitTaskBuilder;
2525
import io.serverlessworkflow.fluent.func.FuncForTaskBuilder;
2626
import io.serverlessworkflow.fluent.func.FuncForkTaskBuilder;
27-
import io.serverlessworkflow.fluent.func.FuncListenTaskBuilder;
2827
import io.serverlessworkflow.fluent.func.FuncSetTaskBuilder;
2928
import io.serverlessworkflow.fluent.func.FuncSwitchTaskBuilder;
3029
import io.serverlessworkflow.fluent.func.FuncTaskItemListBuilder;

fluent/agentic/src/main/java/io/serverlessworkflow/fluent/agentic/spi/AgentDoFluent.java

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
*/
1616
package io.serverlessworkflow.fluent.agentic.spi;
1717

18-
import java.util.UUID;
19-
import java.util.function.Consumer;
20-
2118
import io.serverlessworkflow.fluent.agentic.AgentListenTaskBuilder;
2219
import io.serverlessworkflow.fluent.agentic.LoopAgentsBuilder;
2320
import io.serverlessworkflow.fluent.func.FuncCallTaskBuilder;
@@ -33,43 +30,45 @@
3330
import io.serverlessworkflow.fluent.spec.spi.ListenFluent;
3431
import io.serverlessworkflow.fluent.spec.spi.SetFluent;
3532
import io.serverlessworkflow.fluent.spec.spi.SwitchFluent;
33+
import java.util.UUID;
34+
import java.util.function.Consumer;
3635

3736
public interface AgentDoFluent<SELF extends AgentDoFluent<SELF>>
38-
extends SetFluent<FuncSetTaskBuilder, SELF>,
37+
extends SetFluent<FuncSetTaskBuilder, SELF>,
3938
EmitFluent<FuncEmitTaskBuilder, SELF>,
4039
ForEachFluent<FuncForTaskBuilder, SELF>,
4140
SwitchFluent<FuncSwitchTaskBuilder, SELF>,
4241
ForkFluent<FuncForkTaskBuilder, SELF>,
4342
ListenFluent<AgentListenTaskBuilder, SELF>,
4443
CallFnFluent<FuncCallTaskBuilder, SELF> {
4544

46-
SELF agent(String name, Object agent);
45+
SELF agent(String name, Object agent);
4746

48-
default SELF agent(Object agent) {
49-
return agent(UUID.randomUUID().toString(), agent);
50-
}
47+
default SELF agent(Object agent) {
48+
return agent(UUID.randomUUID().toString(), agent);
49+
}
5150

52-
SELF sequence(String name, Object... agents);
51+
SELF sequence(String name, Object... agents);
5352

54-
default SELF sequence(Object... agents) {
55-
return sequence("seq-" + UUID.randomUUID(), agents);
56-
}
53+
default SELF sequence(Object... agents) {
54+
return sequence("seq-" + UUID.randomUUID(), agents);
55+
}
5756

58-
SELF loop(String name, Consumer<LoopAgentsBuilder> builder);
57+
SELF loop(String name, Consumer<LoopAgentsBuilder> builder);
5958

60-
default SELF loop(Consumer<LoopAgentsBuilder> builder) {
61-
return loop("loop-" + UUID.randomUUID(), builder);
62-
}
59+
default SELF loop(Consumer<LoopAgentsBuilder> builder) {
60+
return loop("loop-" + UUID.randomUUID(), builder);
61+
}
6362

64-
SELF loop(String name, LoopAgentsBuilder builder);
63+
SELF loop(String name, LoopAgentsBuilder builder);
6564

66-
default SELF loop(LoopAgentsBuilder builder) {
67-
return loop("loop-" + UUID.randomUUID(), builder);
68-
}
65+
default SELF loop(LoopAgentsBuilder builder) {
66+
return loop("loop-" + UUID.randomUUID(), builder);
67+
}
6968

70-
SELF parallel(String name, Object... agents);
69+
SELF parallel(String name, Object... agents);
7170

72-
default SELF parallel(Object... agents) {
73-
return parallel("par-" + UUID.randomUUID(), agents);
74-
}
71+
default SELF parallel(Object... agents) {
72+
return parallel("par-" + UUID.randomUUID(), agents);
73+
}
7574
}

fluent/agentic/src/test/java/io/serverlessworkflow/fluent/agentic/Agents.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import dev.langchain4j.agentic.Agent;
1919
import dev.langchain4j.agentic.internal.AgentSpecification;
20-
import dev.langchain4j.service.MemoryId;
2120
import dev.langchain4j.service.UserMessage;
2221
import dev.langchain4j.service.V;
2322
import java.util.List;
@@ -28,10 +27,10 @@ interface ChatBot {
2827
@UserMessage(
2928
"""
3029
You are a happy chat bot, reply to my message:
31-
{message}.
30+
{userInput}.
3231
""")
3332
@Agent
34-
String chat(@V("message") String message);
33+
String chat(@V("userInput") String userInput);
3534
}
3635

3736
interface MovieExpert {

0 commit comments

Comments
 (0)