Example


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) => formatToOpenAIFunction(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,
});

Hierarchy

Constructors

Methods

  • Returns string

  • Parameters

    • text: string

    Returns Promise<AgentAction | AgentFinish>

  • Parses the output message into a FunctionsAgentAction or AgentFinish object.

    Parameters

    • message: BaseMessage

      The BaseMessage to parse.

    Returns AgentFinish | FunctionsAgentAction

    A FunctionsAgentAction or AgentFinish object.

  • Parameters

    • generations: ChatGeneration[]

    Returns Promise<AgentFinish | FunctionsAgentAction>

Generated using TypeDoc