I was trying to follow the quickstart tutorial for agents for Langchain: https://js.langchain.com/docs/modules/agents/quick_start
I followed the process but faced unexpected errors. I did not know how to solve it and did not find any existing solution. Please advise.
import { TavilySearchResults } from "@langchain/community/tools/tavily_search";
import { ChatOpenAI } from "@langchain/openai";
import { pull } from "langchain/hub";
import { createOpenAIFunctionsAgent } from "langchain/agents";
import { AgentExecutor } from "langchain/agents";
import {
ChatPromptTemplate,
PromptTemplate,
SystemMessagePromptTemplate,
AIMessagePromptTemplate,
HumanMessagePromptTemplate,
} from "@langchain/core/prompts";
import {
AIMessage,
HumanMessage,
SystemMessage,
} from "@langchain/core/messages";
const searchTool = new TavilySearchResults();
const toolResult = await searchTool.invoke("what is the weather in SF?");
console.log(toolResult);
const tools = [searchTool];
const llm = new ChatOpenAI({
modelName: "gpt-3.5-turbo",
temperature: 0,
});
const prompt = await pull<ChatPromptTemplate>(
"hwchase17/openai-functions-agent"
);
console.log("Prompt Results")
console.log(prompt)
const agent = await createOpenAIFunctionsAgent({
llm: llm,
tools: tools,
prompt: prompt,
});
const agentExecutor = new AgentExecutor({
agent,
tools,
});
const result1 = await agentExecutor.invoke({
input: "hello!",
});
console.log(result1);
Prompt Results
false
file:///Users/bytedance/Desktop/AI/ai-terminal/node_modules/langchain/dist/agents/openai_functions/index.js:218
if (!prompt.inputVariables.includes("agent_scratchpad")) {
^
TypeError: Cannot read properties of undefined (reading 'includes')
at createOpenAIFunctionsAgent (file:///Users/bytedance/Desktop/AI/ai-terminal/node_modules/langchain/dist/agents/openai_functions/index.js:218:32)
at file:///Users/bytedance/Desktop/AI/ai-terminal/test.js:43:21
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Node.js v20.10.0
I tried debugging but didn't manage to find anything.
1 - Change the import
import { pull } from "langchain/hub";
to
import * as hub from "langchain/hub";
2 - Change the line
const prompt = pull<ChatPromptTemplate>("rlm/rag-prompt");
to
const prompt = await hub.pull("rlm/rag-prompt");
This fixed mine.
See: https://smith.langchain.com/hub/rlm/rag-prompt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With