Example


const prompt = ChatPromptTemplate.fromMessages([
["ai", "You are a helpful assistant"],
["human", "{input}"],
new MessagesPlaceholder("agent_scratchpad"),
]);

const runnableAgent = RunnableSequence.from([
{
input: (i: { input: string; steps: ToolsAgentStep[] }) => i.input,
agent_scratchpad: (i: { input: string; steps: ToolsAgentStep[] }) =>
formatToOpenAIToolMessages(i.steps),
},
prompt,
new ChatOpenAI({
modelName: "gpt-3.5-turbo-1106",
temperature: 0,
}).bind({ tools: tools.map(formatToOpenAITool) }),
new OpenAIToolsAgentOutputParser(),
]).withConfig({ runName: "OpenAIToolsAgent" });

const result = await runnableAgent.invoke({
input:
"What is the sum of the current temperature in San Francisco, New York, and Tokyo?",
});

Hierarchy

  • AgentMultiActionOutputParser
    • OpenAIToolsAgentOutputParser

Constructors

  • Parameters

    • Optional kwargs: SerializedFields
    • Rest ..._args: never[]

    Returns OpenAIToolsAgentOutputParser

Methods

  • Returns string

  • Parameters

    • text: string

    Returns Promise<AgentFinish | AgentAction[]>

  • Parses the output message into a ToolsAgentAction[] or AgentFinish object.

    Parameters

    • message: BaseMessage

      The BaseMessage to parse.

    Returns AgentFinish | ToolsAgentAction[]

    A ToolsAgentAction[] or AgentFinish object.

  • Parameters

    • generations: ChatGeneration[]

    Returns Promise<AgentFinish | ToolsAgentAction[]>

Generated using TypeDoc