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 @@ -24,6 +24,7 @@
import io.serverlessworkflow.impl.expressions.agentic.langchain4j.AgenticScopeRegistryAssessor;
import java.time.OffsetDateTime;
import java.util.Map;
import java.util.stream.Collectors;

class AgenticModelFactory implements WorkflowModelFactory {

Expand Down Expand Up @@ -60,10 +61,11 @@ public WorkflowModel fromAny(WorkflowModel prev, Object obj) {

@Override
public WorkflowModel combine(Map<String, WorkflowModel> workflowVariables) {
// TODO: create a new agenticScope object in the AgenticScopeRegistryAssessor per branch
// TODO: Since we share the same agenticScope object, both branches are updating the same
// instance, so for now we return the first key.
return workflowVariables.values().iterator().next();
Map<String, Object> combinedState =
workflowVariables.entrySet().stream()
.map(e -> Map.entry(e.getKey(), e.getValue().asJavaObject()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
return newAgenticModel(combinedState);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ public void testParallel() throws ExecutionException, InterruptedException {
Map<String, String> topic = new HashMap<>();
topic.put("style", "sci-fi");

try (WorkflowApplication app = WorkflowApplication.builder().build()) {
Map<String, Object> result =
app.workflowDefinition(workflow).instance(topic).start().get().asMap().orElseThrow();

assertEquals("Fake conflict response", result.get("setting").toString());
assertEquals("Fake hero response", result.get("hero").toString());
assertEquals("Fake setting response", result.get("conflict").toString());
}

try (WorkflowApplication app = WorkflowApplication.builder().build()) {
AgenticScope result =
app.workflowDefinition(workflow)
Expand All @@ -183,9 +192,9 @@ public void testParallel() throws ExecutionException, InterruptedException {
.as(AgenticScope.class)
.orElseThrow();

assertEquals("Fake conflict response", result.readState("setting"));
assertEquals("Fake hero response", result.readState("hero"));
assertEquals("Fake setting response", result.readState("conflict"));
assertEquals("Fake conflict response", result.readState("setting").toString());
assertEquals("Fake hero response", result.readState("hero").toString());
assertEquals("Fake setting response", result.readState("conflict").toString());
}
}

Expand Down Expand Up @@ -223,6 +232,14 @@ public void testSeqAndThenParallel() throws ExecutionException, InterruptedExcep
Map<String, String> topic = new HashMap<>();
topic.put("fact", "alien");

try (WorkflowApplication app = WorkflowApplication.builder().build()) {
Map<String, Object> result =
app.workflowDefinition(workflow).instance(topic).start().get().asMap().orElseThrow();

assertEquals(cultureTraits, result.get("culture"));
assertEquals(technologyTraits, result.get("technology"));
}

try (WorkflowApplication app = WorkflowApplication.builder().build()) {
AgenticScope result =
app.workflowDefinition(workflow)
Expand Down