Skip to content
Merged
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 @@ -15,11 +15,14 @@
*/
package io.serverlessworkflow.fluent.agentic.langchain4j;

import dev.langchain4j.agentic.agent.AgentRequest;
import dev.langchain4j.agentic.agent.AgentResponse;
import dev.langchain4j.agentic.internal.AgentExecutor;
import dev.langchain4j.agentic.scope.AgenticScope;
import dev.langchain4j.agentic.workflow.ConditionalAgentService;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;

public class ConditionalAgentServiceImpl<T>
Expand All @@ -45,6 +48,18 @@ public ConditionalAgentService<T> subAgents(List<AgentExecutor> agentExecutors)
return this.subAgents(agentExecutors.toArray());
}

@Override
public ConditionalAgentService<T> beforeAgentInvocation(Consumer<AgentRequest> consumer) {
throw new UnsupportedOperationException(
"Feature not implemented yet. See: https://github.com/serverlessworkflow/sdk-java/issues/836");
}

@Override
public ConditionalAgentService<T> afterAgentInvocation(Consumer<AgentResponse> consumer) {
throw new UnsupportedOperationException(
"Feature not implemented yet. See: https://github.com/serverlessworkflow/sdk-java/issues/836");
}

@Override
public ConditionalAgentService<T> subAgents(Predicate<AgenticScope> condition, Object... agents) {
this.workflowBuilder.tasks(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
*/
package io.serverlessworkflow.fluent.agentic.langchain4j;

import dev.langchain4j.agentic.agent.AgentRequest;
import dev.langchain4j.agentic.agent.AgentResponse;
import dev.langchain4j.agentic.internal.AgentExecutor;
import dev.langchain4j.agentic.scope.AgenticScope;
import dev.langchain4j.agentic.workflow.LoopAgentService;
import io.serverlessworkflow.fluent.agentic.LoopAgentsBuilder;
import java.util.List;
import java.util.function.BiPredicate;
import java.util.function.Consumer;
import java.util.function.Predicate;

public class LoopAgentServiceImpl<T> extends AbstractAgentService<T, LoopAgentService<T>>
Expand Down Expand Up @@ -47,6 +51,18 @@ public LoopAgentService<T> exitCondition(Predicate<AgenticScope> exitCondition)
return this;
}

@Override
public LoopAgentService<T> exitCondition(BiPredicate<AgenticScope, Integer> biPredicate) {
this.loopAgentsBuilder.exitCondition(biPredicate);
return this;
}

@Override
public LoopAgentService<T> testExitAtLoopEnd(boolean b) {
throw new UnsupportedOperationException(
"Feature not implemented yet. See: https://github.com/serverlessworkflow/sdk-java/issues/836");
}

@Override
public LoopAgentService<T> subAgents(Object... agents) {
this.loopAgentsBuilder.subAgents(agents);
Expand All @@ -60,4 +76,16 @@ public LoopAgentService<T> subAgents(List<AgentExecutor> agentExecutors) {
this.workflowBuilder.tasks(t -> t.loop(this.loopAgentsBuilder));
return this;
}

@Override
public LoopAgentService<T> beforeAgentInvocation(Consumer<AgentRequest> consumer) {
throw new UnsupportedOperationException(
"Feature not implemented yet. See: https://github.com/serverlessworkflow/sdk-java/issues/836");
}

@Override
public LoopAgentService<T> afterAgentInvocation(Consumer<AgentResponse> consumer) {
throw new UnsupportedOperationException(
"Feature not implemented yet. See: https://github.com/serverlessworkflow/sdk-java/issues/836");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
*/
package io.serverlessworkflow.fluent.agentic.langchain4j;

import dev.langchain4j.agentic.agent.AgentRequest;
import dev.langchain4j.agentic.agent.AgentResponse;
import dev.langchain4j.agentic.internal.AgentExecutor;
import dev.langchain4j.agentic.workflow.ParallelAgentService;
import io.serverlessworkflow.impl.ExecutorServiceHolder;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.function.Consumer;

public class ParallelAgentServiceImpl<T> extends AbstractAgentService<T, ParallelAgentService<T>>
implements ParallelAgentService<T> {
Expand All @@ -44,6 +47,18 @@ public ParallelAgentService<T> subAgents(List<AgentExecutor> agentExecutors) {
return this.subAgents(agentExecutors.toArray());
}

@Override
public ParallelAgentService<T> beforeAgentInvocation(Consumer<AgentRequest> consumer) {
throw new UnsupportedOperationException(
"Feature not implemented yet. See: https://github.com/serverlessworkflow/sdk-java/issues/836");
}

@Override
public ParallelAgentService<T> afterAgentInvocation(Consumer<AgentResponse> consumer) {
throw new UnsupportedOperationException(
"Feature not implemented yet. See: https://github.com/serverlessworkflow/sdk-java/issues/836");
}

@Override
public ParallelAgentService<T> executor(Executor executor) {
if (!(executor instanceof ExecutorService)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
*/
package io.serverlessworkflow.fluent.agentic.langchain4j;

import dev.langchain4j.agentic.agent.AgentRequest;
import dev.langchain4j.agentic.agent.AgentResponse;
import dev.langchain4j.agentic.internal.AgentExecutor;
import dev.langchain4j.agentic.workflow.SequentialAgentService;
import java.util.List;
import java.util.function.Consumer;

public class SequentialAgentServiceImpl<T>
extends AbstractAgentService<T, SequentialAgentService<T>>
Expand All @@ -42,4 +45,16 @@ public SequentialAgentService<T> subAgents(List<AgentExecutor> agentExecutors) {
this.subAgents(agentExecutors.toArray());
return this;
}

@Override
public SequentialAgentService<T> beforeAgentInvocation(Consumer<AgentRequest> consumer) {
throw new UnsupportedOperationException(
"Feature not implemented yet. See: https://github.com/serverlessworkflow/sdk-java/issues/836");
}

@Override
public SequentialAgentService<T> afterAgentInvocation(Consumer<AgentResponse> consumer) {
throw new UnsupportedOperationException(
"Feature not implemented yet. See: https://github.com/serverlessworkflow/sdk-java/issues/836");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,20 @@
import static dev.langchain4j.agentic.internal.AgentUtil.agentsToExecutors;

import dev.langchain4j.agentic.internal.AgentExecutor;
import dev.langchain4j.agentic.internal.AgentSpecification;
import dev.langchain4j.agentic.scope.AgenticScope;
import dev.langchain4j.agentic.scope.DefaultAgenticScope;
import io.serverlessworkflow.api.types.func.LoopPredicateIndex;
import java.util.List;
import java.util.function.BiPredicate;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;

public final class AgentAdapters {

private AgentAdapters() {}

public static List<AgentExecutor> toExecutors(Object... agents) {
return agentsToExecutors(Stream.of(agents).map(AgentSpecification.class::cast).toArray());
return agentsToExecutors(agents);
}

public static Function<DefaultAgenticScope, Object> toFunction(AgentExecutor exec) {
Expand All @@ -42,4 +41,9 @@ public static Function<DefaultAgenticScope, Object> toFunction(AgentExecutor exe
public static LoopPredicateIndex<AgenticScope, Object> toWhile(Predicate<AgenticScope> exit) {
return (model, item, idx) -> !exit.test(model);
}

public static LoopPredicateIndex<AgenticScope, Object> toWhile(
BiPredicate<AgenticScope, Integer> exit) {
return (model, item, idx) -> !exit.test(model, idx);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.serverlessworkflow.fluent.func.FuncTaskItemListBuilder;
import java.util.List;
import java.util.UUID;
import java.util.function.BiPredicate;
import java.util.function.ObjIntConsumer;
import java.util.function.Predicate;
import java.util.stream.IntStream;
Expand Down Expand Up @@ -65,6 +66,11 @@ public LoopAgentsBuilder exitCondition(Predicate<AgenticScope> exitCondition) {
return this;
}

public LoopAgentsBuilder exitCondition(BiPredicate<AgenticScope, Integer> exitCondition) {
this.forTask.withWhile(AgentAdapters.toWhile(exitCondition), AgenticScope.class);
return this;
}

public ForTaskFunction build() {
this.forTask.setDo(this.funcDelegate.build());
return this.forTask;
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<version.org.hibernate.validator>9.0.1.Final</version.org.hibernate.validator>
<version.org.glassfish.expressly>6.0.0</version.org.glassfish.expressly>
<!-- Experimental modules from langchain4j -->
<version.dev.langchain4j.beta>1.5.0-beta11</version.dev.langchain4j.beta>
<version.dev.langchain4j.beta>1.6.0-beta12</version.dev.langchain4j.beta>
<!-- Base langchain4j version -->
<version.dev.langchain4j>1.6.0</version.dev.langchain4j>

Expand Down