Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.fluent.agentic.configurer;
package io.serverlessworkflow.fluent.agentic.configurers;

import io.serverlessworkflow.fluent.agentic.AgentListenTaskBuilder;
import java.util.function.Consumer;

@FunctionalInterface
public interface ListenConfigurer extends Consumer<AgentListenTaskBuilder> {}
public interface AgentListenConfigurer extends Consumer<AgentListenTaskBuilder> {}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.fluent.agentic.configurer;
package io.serverlessworkflow.fluent.agentic.configurers;

import io.serverlessworkflow.fluent.agentic.AgentDoTaskBuilder;
import java.util.function.Consumer;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2020-Present The Serverless Workflow Specification Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.fluent.agentic.dsl;

import io.serverlessworkflow.fluent.agentic.AgentListenTaskBuilder;
import io.serverlessworkflow.fluent.agentic.configurers.AgentListenConfigurer;
import io.serverlessworkflow.fluent.func.dsl.BaseFuncListenSpec;
import io.serverlessworkflow.fluent.spec.AbstractListenTaskBuilder;

public final class AgentListenSpec
extends BaseFuncListenSpec<AgentListenSpec, AgentListenTaskBuilder>
implements AgentListenConfigurer {

public AgentListenSpec() {
super(AbstractListenTaskBuilder::to);
}

@Override
protected AgentListenSpec self() {
return this;
}

@Override
public void accept(AgentListenTaskBuilder agentListenTaskBuilder) {
acceptInto(agentListenTaskBuilder);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
import io.cloudevents.CloudEventData;
import io.serverlessworkflow.api.types.FlowDirectiveEnum;
import io.serverlessworkflow.fluent.agentic.AgentDoTaskBuilder;
import io.serverlessworkflow.fluent.agentic.configurer.AgentTaskConfigurer;
import io.serverlessworkflow.fluent.agentic.configurer.FuncPredicateEventConfigurer;
import io.serverlessworkflow.fluent.agentic.configurer.SwitchCaseConfigurer;
import io.serverlessworkflow.fluent.agentic.configurers.AgentTaskConfigurer;
import io.serverlessworkflow.fluent.func.FuncCallTaskBuilder;
import io.serverlessworkflow.fluent.func.FuncEmitTaskBuilder;
import io.serverlessworkflow.fluent.func.FuncSwitchTaskBuilder;
import io.serverlessworkflow.fluent.func.configurers.FuncPredicateEventConfigurer;
import io.serverlessworkflow.fluent.func.configurers.SwitchCaseConfigurer;
import io.serverlessworkflow.fluent.func.dsl.ReflectionUtils;
import io.serverlessworkflow.fluent.func.dsl.SwitchCaseSpec;
import io.serverlessworkflow.fluent.func.dsl.internal.CommonFuncOps;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
Expand All @@ -33,79 +36,75 @@

public final class AgenticDSL {

private static final CommonFuncOps OPS = new CommonFuncOps() {};

private AgenticDSL() {}

public static <T, V> Consumer<FuncCallTaskBuilder> fn(
Function<T, V> function, Class<T> argClass) {
return f -> f.function(function, argClass);
return OPS.fn(function, argClass);
}

public static <T, V> Consumer<FuncCallTaskBuilder> fn(Function<T, V> function) {
return f -> f.function(function);
return OPS.fn(function);
}

public static Consumer<FuncSwitchTaskBuilder> cases(SwitchCaseConfigurer... cases) {
return s -> {
for (SwitchCaseConfigurer c : cases) {
s.onPredicate(c);
}
};
return OPS.cases(cases);
}

public static <T> SwitchCaseSpec<T> on(Predicate<T> when, Class<T> whenClass) {
return new SwitchCaseSpec<T>().when(when, whenClass);
public static <T> SwitchCaseSpec<T> caseOf(Predicate<T> when, Class<T> whenClass) {
return OPS.caseOf(when, whenClass);
}

public static <T> SwitchCaseSpec<T> on(Predicate<T> when) {
return new SwitchCaseSpec<T>().when(when);
public static <T> SwitchCaseSpec<T> caseOf(Predicate<T> when) {
return OPS.caseOf(when);
}

public static SwitchCaseConfigurer onDefault(String task) {
return s -> s.then(task);
public static SwitchCaseConfigurer caseDefault(String task) {
return OPS.caseDefault(task);
}

public static SwitchCaseConfigurer onDefault(FlowDirectiveEnum directive) {
return s -> s.then(directive);
public static SwitchCaseConfigurer caseDefault(FlowDirectiveEnum directive) {
return OPS.caseDefault(directive);
}

public static ListenSpec to() {
return new ListenSpec();
public static AgentListenSpec to() {
return new AgentListenSpec();
}

public static ListenSpec toOne(String type) {
return new ListenSpec().one(e -> e.type(type));
public static AgentListenSpec toOne(String type) {
return new AgentListenSpec().one(e -> e.type(type));
}

public static ListenSpec toAll(String... types) {
public static AgentListenSpec toAll(String... types) {
FuncPredicateEventConfigurer[] events = new FuncPredicateEventConfigurer[types.length];
for (int i = 0; i < types.length; i++) {
events[i] = event(types[i]);
}
return new ListenSpec().all(events);
return new AgentListenSpec().all(events);
}

public static ListenSpec toAny(String... types) {
public static AgentListenSpec toAny(String... types) {
FuncPredicateEventConfigurer[] events = new FuncPredicateEventConfigurer[types.length];
for (int i = 0; i < types.length; i++) {
events[i] = event(types[i]);
}
return new ListenSpec().any(events);
return new AgentListenSpec().any(events);
}

public static FuncPredicateEventConfigurer event(String type) {
return e -> e.type(type);
return OPS.event(type);
}

// TODO: expand the `event` static ref with more attributes based on community feedback

public static <T> Consumer<FuncEmitTaskBuilder> event(
String type, Function<T, CloudEventData> function) {
return event -> event.event(e -> e.type(type).data(function));
return OPS.event(type, function);
}

public static <T> Consumer<FuncEmitTaskBuilder> event(
String type, Function<T, CloudEventData> function, Class<T> clazz) {
return event -> event.event(e -> e.type(type).data(function, clazz));
return OPS.event(type, function, clazz);
}

// -------- Agentic Workflow Patterns -------- //
Expand Down Expand Up @@ -148,7 +147,8 @@ public static <T, V> AgentTaskConfigurer function(Function<T, V> function, Class
}

public static <T, V> AgentTaskConfigurer function(Function<T, V> function) {
return list -> list.callFn(fn(function));
Class<T> clazz = ReflectionUtils.inferInputType(function);
return list -> list.callFn(fn(function, clazz));
}

public static AgentTaskConfigurer agent(Object agent) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import static io.serverlessworkflow.fluent.agentic.dsl.AgenticDSL.cases;
import static io.serverlessworkflow.fluent.agentic.dsl.AgenticDSL.event;
import static io.serverlessworkflow.fluent.agentic.dsl.AgenticDSL.fn;
import static io.serverlessworkflow.fluent.agentic.dsl.AgenticDSL.on;
import static io.serverlessworkflow.fluent.agentic.dsl.AgenticDSL.onDefault;
import static io.serverlessworkflow.fluent.agentic.dsl.AgenticDSL.toAny;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.fail;
Expand All @@ -30,6 +28,7 @@
import io.serverlessworkflow.api.types.EventFilter;
import io.serverlessworkflow.api.types.EventProperties;
import io.serverlessworkflow.api.types.Workflow;
import io.serverlessworkflow.fluent.agentic.dsl.AgenticDSL;
import io.serverlessworkflow.impl.WorkflowApplication;
import io.serverlessworkflow.impl.WorkflowStatus;
import io.serverlessworkflow.impl.jackson.JsonUtils;
Expand Down Expand Up @@ -68,11 +67,11 @@ void email_drafter_agent() {
.switchCase(
"needsHumanReview?",
cases(
on(
AgenticDSL.caseOf(
d -> !EmailPolicies.Decision.AUTO_SEND.equals(d.decision()),
PolicyDecision.class)
.then("requestReview"),
onDefault("emailFinished")))
AgenticDSL.caseDefault("emailFinished")))
.emit(
"requestReview",
event(
Expand Down
4 changes: 4 additions & 0 deletions experimental/fluent/func/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<groupId>io.serverlessworkflow</groupId>
<artifactId>serverlessworkflow-experimental-types</artifactId>
</dependency>
<dependency>
<groupId>io.serverlessworkflow</groupId>
<artifactId>serverlessworkflow-impl-json</artifactId>
</dependency>
<dependency>
<groupId>io.serverlessworkflow</groupId>
<artifactId>serverlessworkflow-fluent-spec</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
import io.serverlessworkflow.api.types.func.CallJava;
import io.serverlessworkflow.api.types.func.CallTaskJava;
import io.serverlessworkflow.fluent.func.spi.ConditionalTaskBuilder;
import io.serverlessworkflow.fluent.func.spi.FuncTransformations;
import io.serverlessworkflow.fluent.func.spi.FuncTaskTransformations;
import io.serverlessworkflow.fluent.spec.TaskBaseBuilder;
import java.util.function.Function;

public class FuncCallTaskBuilder extends TaskBaseBuilder<FuncCallTaskBuilder>
implements FuncTransformations<FuncCallTaskBuilder>,
implements FuncTaskTransformations<FuncCallTaskBuilder>,
ConditionalTaskBuilder<FuncCallTaskBuilder> {

private CallTaskJava callTaskJava;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

import io.serverlessworkflow.fluent.func.spi.ConditionalTaskBuilder;
import io.serverlessworkflow.fluent.func.spi.FuncDoFluent;
import io.serverlessworkflow.fluent.func.spi.FuncTransformations;
import io.serverlessworkflow.fluent.func.spi.FuncTaskTransformations;
import io.serverlessworkflow.fluent.spec.BaseDoTaskBuilder;
import java.util.function.Consumer;

public class FuncDoTaskBuilder extends BaseDoTaskBuilder<FuncDoTaskBuilder, FuncTaskItemListBuilder>
implements FuncTransformations<FuncDoTaskBuilder>,
implements FuncTaskTransformations<FuncDoTaskBuilder>,
ConditionalTaskBuilder<FuncDoTaskBuilder>,
FuncDoFluent<FuncDoTaskBuilder> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
package io.serverlessworkflow.fluent.func;

import io.serverlessworkflow.fluent.func.spi.ConditionalTaskBuilder;
import io.serverlessworkflow.fluent.func.spi.FuncTransformations;
import io.serverlessworkflow.fluent.func.spi.FuncTaskTransformations;
import io.serverlessworkflow.fluent.spec.AbstractEmitTaskBuilder;

public class FuncEmitTaskBuilder
extends AbstractEmitTaskBuilder<FuncEmitTaskBuilder, FuncEventPropertiesBuilder>
implements ConditionalTaskBuilder<FuncEmitTaskBuilder>,
FuncTransformations<FuncEmitTaskBuilder> {
FuncTaskTransformations<FuncEmitTaskBuilder> {
FuncEmitTaskBuilder() {
super();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import io.serverlessworkflow.api.types.func.LoopPredicate;
import io.serverlessworkflow.api.types.func.LoopPredicateIndex;
import io.serverlessworkflow.fluent.func.spi.ConditionalTaskBuilder;
import io.serverlessworkflow.fluent.func.spi.FuncTransformations;
import io.serverlessworkflow.fluent.func.spi.FuncTaskTransformations;
import io.serverlessworkflow.fluent.spec.TaskBaseBuilder;
import io.serverlessworkflow.fluent.spec.spi.ForEachTaskFluent;
import java.util.ArrayList;
Expand All @@ -36,7 +36,7 @@
import java.util.function.Function;

public class FuncForTaskBuilder extends TaskBaseBuilder<FuncForTaskBuilder>
implements FuncTransformations<FuncForTaskBuilder>,
implements FuncTaskTransformations<FuncForTaskBuilder>,
ConditionalTaskBuilder<FuncForTaskBuilder>,
ForEachTaskFluent<FuncForTaskBuilder, FuncTaskItemListBuilder> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import io.serverlessworkflow.api.types.func.CallJava;
import io.serverlessworkflow.api.types.func.CallTaskJava;
import io.serverlessworkflow.fluent.func.spi.ConditionalTaskBuilder;
import io.serverlessworkflow.fluent.func.spi.FuncTransformations;
import io.serverlessworkflow.fluent.func.spi.FuncTaskTransformations;
import io.serverlessworkflow.fluent.spec.TaskBaseBuilder;
import io.serverlessworkflow.fluent.spec.spi.ForkTaskFluent;
import java.util.ArrayList;
Expand All @@ -32,7 +32,7 @@
import java.util.function.Function;

public class FuncForkTaskBuilder extends TaskBaseBuilder<FuncForkTaskBuilder>
implements FuncTransformations<FuncForkTaskBuilder>,
implements FuncTaskTransformations<FuncForkTaskBuilder>,
ConditionalTaskBuilder<FuncForkTaskBuilder>,
ForkTaskFluent<FuncForkTaskBuilder, FuncTaskItemListBuilder> {

Expand Down
Loading