Skip to content

Exception on loop after agent call #824

Description

@treblereel
    var creativeWriter = AgentsUtils.newCreativeWriter();
    var scorer = AgentsUtils.newStyleScorer();
    var editor = AgentsUtils.newStyleEditor();

    Predicate<AgenticScope> until = s -> s.readState("score", 0).doubleValue() >= 0.8;

    Map<String, Object> input =
            Map.of(
                    "topic", "fantasy",
                    "style", "fantasy",
                    "audience", "young adults");

    Workflow wf = workflow("loopFlow").agent(creativeWriter)
            .loop(until, scorer, editor).build();

    Object result;
    try (WorkflowApplication app = WorkflowApplication.builder().build()) {
      result = app.workflowDefinition(wf).instance(input).start().get().asJavaObject();
    } catch (Exception e) {
      throw new RuntimeException("Workflow execution failed", e);
    }

    System.out.println(result);

What happened:

Caused by: java.lang.NullPointerException: Cannot invoke "java.util.Optional.isPresent()" because the return value of "io.serverlessworkflow.api.types.func.ForTaskFunction.getForClass()" is null
	at io.serverlessworkflow.impl.executors.func.JavaForExecutorBuilder.collectionFilterObject(JavaForExecutorBuilder.java:70)
	at io.serverlessworkflow.impl.executors.func.JavaForExecutorBuilder.buildCollectionFilter(JavaForExecutorBuilder.java:65)
	at io.serverlessworkflow.impl.executors.ForExecutor$ForExecutorBuilder.<init>(ForExecutor.java:47)
	at io.serverlessworkflow.impl.executors.func.JavaForExecutorBuilder.<init>(JavaForExecutorBuilder.java:37)
	at io.serverlessworkflow.impl.executors.func.JavaTaskExecutorFactory.getTaskExecutor(JavaTaskExecutorFactory.java:30)
	at io.serverlessworkflow.impl.executors.TaskExecutorHelper.createExecutorBuilderList(TaskExecutorHelper.java:93)
	at io.serverlessworkflow.impl.executors.TaskExecutorHelper.createExecutorList(TaskExecutorHelper.java:65)
	at io.serverlessworkflow.impl.WorkflowDefinition.<init>(WorkflowDefinition.java:59)
	at io.serverlessworkflow.impl.WorkflowDefinition.of(WorkflowDefinition.java:69)
	at io.serverlessworkflow.impl.WorkflowDefinition.of(WorkflowDefinition.java:64)
	at io.serverlessworkflow.impl.WorkflowApplication.lambda$workflowDefinition$0(WorkflowApplication.java:257)
	at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708)
	at io.serverlessworkflow.impl.WorkflowApplication.workflowDefinition(WorkflowApplication.java:256)
	at io.serverlessworkflow.fluent.agentic.langchain4j.WorkflowAgentsIT.loopTest(WorkflowAgentsIT.java:142)
	... 3 more

What you expected to happen:

No Exception, resulted String returned from the workflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions