Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile time check if chat memory is required #86

Closed
andreas-eberle opened this issue Dec 4, 2023 · 4 comments · Fixed by #92
Closed

Compile time check if chat memory is required #86

andreas-eberle opened this issue Dec 4, 2023 · 4 comments · Fixed by #92

Comments

@andreas-eberle
Copy link
Contributor

I just tried the example from the guide and forgot about adding the chat memory / chat memory provider. The code compiles and quarkusDev is starting but when I try to use it, it fails with

Caused by: dev.langchain4j.exception.IllegalConfigurationException: Please set up chatMemory or chatMemoryProvider in order to use tools. A ChatMemory that can hold at least 3 messages is required for the tools to work properly. While the LLM can technically execute a tool without chat memory, if it only receives the result of the tool's execution without the initial message from the user, it won't interpret the result properly.
	at dev.langchain4j.exception.IllegalConfigurationException.illegalConfiguration(IllegalConfigurationException.java:12)
	at dev.langchain4j.service.AiServices.performBasicValidation(AiServices.java:325)

It would be great if the extension could detect this during build time to avoid having runtime issues.

@geoand
Copy link
Collaborator

geoand commented Dec 4, 2023

Which example are you talking about?

@andreas-eberle
Copy link
Contributor Author

Ah, sorry, the one from the quickstart guide: https://docs.quarkiverse.io/quarkus-langchain4j/dev/index.html. So I have

package io.quarkiverse.langchain4j.samples;

import dev.langchain4j.service.SystemMessage;
import dev.langchain4j.service.UserMessage;
import io.quarkiverse.langchain4j.RegisterAiService;

@RegisterAiService( 
        tools = EmailService.class 
)
public interface MyAiService {

    @SystemMessage("You are a professional poet") 
    @UserMessage("""
                Write a poem about {topic}. The poem should be {lines} lines long. Then send this poem by email. 
            """)
    String writeAPoem(String topic, int lines); 
}

and I added a dummy EmailService like here: https://docs.quarkiverse.io/quarkus-langchain4j/dev/agent-and-tools.html#_declaring_a_tool but it only logs the content.

@ApplicationScoped
public class EmailService {

    @Tool("send the provided content via email")
    public void sendAnEmail(String content) {
        Log.info("Sending an email: " + content);
    }

}

@geoand
Copy link
Collaborator

geoand commented Dec 4, 2023

Thanks. I'll look into it

@geoand
Copy link
Collaborator

geoand commented Dec 5, 2023

#92 fixes the issue

@geoand geoand closed this as completed in #92 Dec 5, 2023
geoand added a commit that referenced this issue Dec 5, 2023
Fail at build time when tools set and no memory provided
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants