Hi,

I have moved from 1.0.0-M8 to 1.0.0-RC1. A small app that successfully compiles and runs with GraalVM.

Something has happened after this issue with the non null assertions and the refactoring of MessageChatMemoryAdvisor

From 1.0.0-RC1, it fails at runtime in a native-image with

Caused by: java.lang.IllegalArgumentException: scheduler cannot be null
    at org.springframework.util.Assert.notNull(Assert.java:181)
    at org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor.<init>(MessageChatMemoryAdvisor.java:61)
    at org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor$Builder.build(MessageChatMemoryAdvisor.java:179)
    at com.mpalourdio.projects.mpalourd_ai.controller.OpenAiController.<init>(OpenAiController.kt:53)
    at com.mpalourdio.projects.mpalourd_ai.controller.OpenAiController__BeanDefinitions.lambda$getOpenAiControllerInstanceSupplier$0(OpenAiController__BeanDefinitions.java:25)
    at org.springframework.util.function.ThrowingBiFunction.apply(ThrowingBiFunction.java:68)
    at org.springframework.util.function.ThrowingBiFunction.apply(ThrowingBiFunction.java:54)
    at org.springframework.beans.factory.aot.BeanInstanceSupplier.lambda$get$2(BeanInstanceSupplier.java:225)
    at org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:58)
    at org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:46)
    at org.springframework.beans.factory.aot.BeanInstanceSupplier.invokeBeanSupplier(BeanInstanceSupplier.java:258)
    at org.springframework.beans.factory.aot.BeanInstanceSupplier.get(BeanInstanceSupplier.java:225)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.obtainInstanceFromSupplier(DefaultListableBeanFactory.java:1031)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainFromSupplier(AbstractAutowireCapableBeanFactory.java:1249)

Forcing the scheduler works, but it should not be necessary as it's already a default in MessageChatMemoryAdvisor#Builder . Here is the faulty code :

  private final val messageChatMemoryAdvisor = MessageChatMemoryAdvisor.builder(
        MessageWindowChatMemory.builder()
            .chatMemoryRepository(chatMemoryRepository)
            .build())
        // TODO: Should not be necessary to set this
        // But, it fails in native image with "Caused by: java.lang.IllegalArgumentException: scheduler cannot be null"
        .scheduler(MessageChatMemoryAdvisor.DEFAULT_SCHEDULER) <== already the default.
        .build()

I have used the tracing agent, but I just can't at all generate metadata that make the thing work :/ Nothing seems to handle this scheduler, so i am clueless.

Thanks !

Comment From: lyxfn

I also upgraded to RC1 yesterday. I did not explicitly set the scheduler when initializing MessageChatMemoryAdvisor and did not encounter this problem.

@Resource
private ChatMemory chatMemory;

this.chatClient = ChatClient.builder(chatModel)
                .defaultSystem(new ClassPathResource(SYSTEM_PROMPT_TEMPLATE_PATH))
                .defaultAdvisors(
                        MessageChatMemoryAdvisor.builder(chatMemory).build(),
                        ......
                )
                .defaultToolCallbacks(
                        initToolCallbacks()
                )
                .build();
@Configuration
public class ChatMemoryConfig {

    @Resource
    JdbcChatMemoryRepository chatMemoryRepository;

    ChatMemory chatMemory = MessageWindowChatMemory.builder()
            .chatMemoryRepository(chatMemoryRepository)
            .maxMessages(10)
            .build();
}

Comment From: mpalourdio

You must compile with graalvm and run the native image for it to fail.

Comment From: dev-jonghoonpark

Using the --initialize-at-run-time=org.springframework.ai.chat.client.advisor.api.BaseAdvisor option in the native-image build solves the problem.

From the user's perspective, it would be better if the option were not required. However, I haven't found a better solution yet.