const prompt = ChatPromptTemplate.fromMessages([ ["ai", "You are a helpful assistant"], ["human", "{input}"], new MessagesPlaceholder("agent_scratchpad"),]);const modelWithFunctions = new ChatOpenAI({ modelName: "gpt-4", temperature: 0,}).bind({ functions: tools.map((tool) => convertToOpenAIFunction(tool)),});const runnableAgent = RunnableSequence.from([ { input: (i) => i.input, agent_scratchpad: (i) => formatAgentSteps(i.steps), }, prompt, modelWithFunctions, new OpenAIFunctionsAgentOutputParser(),]);const result = await runnableAgent.invoke({ input: "What is the weather in New York?", steps: agentSteps,}); Copy
const prompt = ChatPromptTemplate.fromMessages([ ["ai", "You are a helpful assistant"], ["human", "{input}"], new MessagesPlaceholder("agent_scratchpad"),]);const modelWithFunctions = new ChatOpenAI({ modelName: "gpt-4", temperature: 0,}).bind({ functions: tools.map((tool) => convertToOpenAIFunction(tool)),});const runnableAgent = RunnableSequence.from([ { input: (i) => i.input, agent_scratchpad: (i) => formatAgentSteps(i.steps), }, prompt, modelWithFunctions, new OpenAIFunctionsAgentOutputParser(),]);const result = await runnableAgent.invoke({ input: "What is the weather in New York?", steps: agentSteps,});
Parses the output message into a FunctionsAgentAction or AgentFinish object.
The BaseMessage to parse.
A FunctionsAgentAction or AgentFinish object.
Example