Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make format_instructions an optional argument in chat agent #2931

Merged
merged 6 commits into from
Oct 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion langchain/src/agents/chat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export interface ChatCreatePromptArgs {
prefix?: string;
/** String to use directly as the human message template. */
humanMessageTemplate?: string;
/** Formattable string to use as the instructions template. */
formatInstructions?: string;
/** List of input variables the final prompt will expect. */
inputVariables?: string[];
}
Expand Down Expand Up @@ -117,17 +119,19 @@ export class ChatAgent extends Agent {
* @param args.suffix - String to put after the list of tools.
* @param args.prefix - String to put before the list of tools.
* @param args.humanMessageTemplate - String to use directly as the human message template
* @param args.formatInstructions - Formattable string to use as the instructions template
*/
static createPrompt(tools: Tool[], args?: ChatCreatePromptArgs) {
const {
prefix = PREFIX,
suffix = SUFFIX,
humanMessageTemplate = DEFAULT_HUMAN_MESSAGE_TEMPLATE,
formatInstructions = FORMAT_INSTRUCTIONS,
} = args ?? {};
const toolStrings = tools
.map((tool) => `${tool.name}: ${tool.description}`)
.join("\n");
const template = [prefix, toolStrings, FORMAT_INSTRUCTIONS, suffix].join(
const template = [prefix, toolStrings, formatInstructions, suffix].join(
"\n\n"
);
const messages = [
Expand Down