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

gpt-4-turbo-2024-04-09 tools agent error #5078

Closed
5 tasks done
Hk-Gosuto opened this issue Apr 12, 2024 · 8 comments
Closed
5 tasks done

gpt-4-turbo-2024-04-09 tools agent error #5078

Hk-Gosuto opened this issue Apr 12, 2024 · 8 comments
Assignees
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@Hk-Gosuto
Copy link

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain.js documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain.js rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

import { PromptTemplate } from "@langchain/core/prompts";
import { AgentExecutor } from "langchain/agents";
import { ChatOpenAI } from "@langchain/openai";
import { SerpAPI } from "@langchain/community/tools/serpapi";
import { createOpenAIFunctionsAgent } from "langchain/agents";

const search = new SerpAPI();
const tools = [search];

const prompt =
  PromptTemplate.fromTemplate(`Turn the following user input into a search query for a search engine:

{input}`);

const llm = new ChatOpenAI({
  model: "gpt-4-turbo-2024-04-09",
  temperature: 0,
});

const agent = await createOpenAIFunctionsAgent({
  llm,
  tools,
  prompt,
});

const agentExecutor = new AgentExecutor({
  agent,
  tools,
});

const result = await agentExecutor.invoke({
  input: "Who is the current prime minister of Malaysia?",
});

console.log(result);

Error Message and Stack Trace (if applicable)

{
message: '{\n' +
' "error": {\n' +
"message": "Unknown parameter: 'messages[1].tool_calls[0].index'.",\n +
' "type": "invalid_request_error",\n' +
' "param": "messages[1].tool_calls[0].index",\n' +
' "code": "unknown_parameter"\n' +
' }\n' +
'}',
code: 400
}

Description

It should be the same error as this one. langchain-ai/langchain#20264

System Info

  • "@langchain/core": "0.1.57"
  • "langchain": "0.1.33"
Copy link

dosubot bot commented Apr 12, 2024

The error message you're encountering, "Unknown parameter: 'messages[1].tool_calls[0].index'", suggests there's a mismatch between the parameters being passed to SerpAPI and what it expects. This could be due to how SerpAPI is integrated within your AgentExecutor setup or a discrepancy in the expected parameters.

To address this issue, you should:

  1. Review SerpAPI Integration: Ensure the parameters passed align with SerpAPI's expectations.
  2. Debug and Log Parameters: Add logging to capture the exact parameters being passed to SerpAPI.
  3. Examine Recent Changes: If this issue started after updates to your codebase or dependencies, review those changes.
  4. Manual Parameter Handling: Consider manually structuring the parameters for SerpAPI as a temporary workaround.

Regarding the structure and parameters for the invoke method of the AgentExecutor class, it seems there might be a misunderstanding since the provided code snippet does not showcase an invoke method directly. The functionality you're referring to might be part of internal logic, typically handled by methods like _call, which processes inputs and executes defined steps, returning a Promise with the execution output.

If these steps do not resolve your issue, further investigation with detailed error logs and how your implementation interacts with SerpAPI would be necessary.

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

@dosubot dosubot bot added the auto:bug Related to a bug, vulnerability, unexpected error with an existing feature label Apr 12, 2024
@jgui1129
Copy link

jgui1129 commented Apr 12, 2024

It seems that the fix in langchain was approved and has been merged: langchain-ai/langchain#20271. Waiting now for it to adapt in langchainjs. Thank you.

@jacoblee93
Copy link
Collaborator

Thanks, will have a look!

@jacoblee93
Copy link
Collaborator

jacoblee93 commented Apr 15, 2024

Hmm I'm actually not able to repro - did OpenAI maybe patch on their end?

https://smith.langchain.com/public/4c7bc175-c9a5-4f2d-bd67-1ecabc03fc6d/r

Here's my code:

const tools = [new TavilySearchResults({ maxResults: 1 })];

const prompt = await pull<ChatPromptTemplate>("hwchase17/openai-tools-agent");
const llm = new ChatOpenAI({
  model: "gpt-4-turbo-2024-04-09",
  temperature: 0,
});
const agent = await createOpenAIToolsAgent({
  llm,
  tools,
  prompt,
});
const agentExecutor = new AgentExecutor({
  agent,
  tools,
});
const input = "Who is the current prime minister of Malaysia?";
const result = await agentExecutor.invoke({
  input,
});

Could someone else verify?

@jacoblee93 jacoblee93 self-assigned this Apr 15, 2024
@jgui1129
Copy link

Hi @jacoblee93 thank you for looking into it. It seems that it resolved itself after the changes in
@langchain/openai": "^0.0.28

Tested also with
@langchain/community": "0.0.48"

@Hk-Gosuto
Copy link
Author

Upgrade @langchain/openai to 0.0.28 works fine, thanks.

@jacoblee93
Copy link
Collaborator

I don't think we changed anything but glad it's working!

@os1ma
Copy link

os1ma commented Apr 22, 2024

Hmm I'm actually not able to repro - did OpenAI maybe patch on their end?

Yes. I checked and it seems to have been patched on the OpenAI side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

4 participants