agsamantha/node_modules/langchain/dist/agents/openai_tools/output_parser.d.ts
2024-10-02 15:15:21 -05:00

49 lines
1.9 KiB
TypeScript

import { AgentAction, AgentFinish } from "@langchain/core/agents";
import { BaseMessage } from "@langchain/core/messages";
import { ChatGeneration } from "@langchain/core/outputs";
import { AgentMultiActionOutputParser } from "../types.js";
import { ToolsAgentAction, ToolsAgentStep } from "../tool_calling/output_parser.js";
export type { ToolsAgentAction, ToolsAgentStep };
/**
* @example
* ```typescript
* 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((tool) => convertToOpenAITool(tool)) }),
* 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?",
* });
* ```
*/
export declare class OpenAIToolsAgentOutputParser extends AgentMultiActionOutputParser {
lc_namespace: string[];
static lc_name(): string;
parse(text: string): Promise<AgentAction[] | AgentFinish>;
parseResult(generations: ChatGeneration[]): Promise<AgentFinish | ToolsAgentAction[]>;
/**
* Parses the output message into a ToolsAgentAction[] or AgentFinish
* object.
* @param message The BaseMessage to parse.
* @returns A ToolsAgentAction[] or AgentFinish object.
*/
parseAIMessage(message: BaseMessage): ToolsAgentAction[] | AgentFinish;
getFormatInstructions(): string;
}