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

fix(agent): openai function agent infinite loop issue #134

Merged
merged 1 commit into from
Aug 20, 2023

Conversation

Derek-X-Wang
Copy link
Contributor

Description: The prompt of the default LLMChain(OpenAIFunctionsAgent.fromLLMAndTools) has a wrong order when no memory and causing infinite loop of function call.

Issue: infinite loop of function call with OpenAIFunctionsAgent

Tag maintainer: @davidmigloz

Background:
When using OpenAIFunctionsAgent.fromLLMAndTools and memory == null, createPrompt will create prompt with the following order:

System
AgentScratchPad
Human

Even when the agent finishes the task, GPT appears to trigger the function repeatedly because the last message is a Human message.

Example of promptValue that calling infinite loop:
Screenshot 2023-08-19 at 10 09 37 AM

Solution:
I change the default order of createPrompt when no memory to the following and the issue is gone.

System
Human
AgentScratchPad

The prompt of the default LLMChain has a wrong order when no memory and causing infinite loop of function call.
@davidmigloz davidmigloz added t:bug Something isn't working c:agents Agents. p:langchain_openai langchain_openai package. labels Aug 20, 2023
@davidmigloz davidmigloz self-requested a review August 20, 2023 07:58
@davidmigloz davidmigloz added this to the v0.0.8 milestone Aug 20, 2023
@davidmigloz
Copy link
Owner

Good catch! Thanks for the fix, lgtm 👍

@davidmigloz davidmigloz merged commit 8c9dcf2 into davidmigloz:main Aug 20, 2023
@Derek-X-Wang Derek-X-Wang deleted the derekxwang-patch branch August 20, 2023 08:06
KennethKnudsen97 pushed a commit to KennethKnudsen97/langchain_dart that referenced this pull request Sep 29, 2023
…avidmigloz#134)

The prompt built by the agent has a wrong order of messages when no memory is used which causes an infinite loop of function calls.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c:agents Agents. p:langchain_openai langchain_openai package. t:bug Something isn't working
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants