Skip to content

Commit

Permalink
feat(agent): update bee system prompt, tools description (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
matoushavlena authored Oct 2, 2024
1 parent 0c2137a commit 83fdb26
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/adapters/bam/chatPreset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const BAMChatLLMPreset = {
decoding_method: "greedy",
include_stop_sequence: false,
max_new_tokens: 2048,
repetition_penalty: 1.03,
repetition_penalty: 1,
stop_sequences: [...parameters.stop_sequence],
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/watsonx/chatPreset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const WatsonXChatLLMPreset = {
decoding_method: "greedy",
include_stop_sequence: false,
max_new_tokens: 2048,
repetition_penalty: 1.03,
repetition_penalty: 1,
stop_sequences: [...parameters.stop_sequence],
},
},
Expand Down
62 changes: 44 additions & 18 deletions src/agents/bee/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import { z } from "zod";

export const BeeSystemPrompt = new PromptTemplate({
schema: z.object({
instructions: z
.string()
.default("You are a helpful assistant that uses tools to answer questions."),
instructions: z.string().default("You are a helpful assistant."),
tools: z.array(
z
.object({
Expand Down Expand Up @@ -51,31 +49,56 @@ You communicate in instruction lines.
The format is: "Instruction: expected output".
You must not enter empty lines or anything else between instruction lines.
{{#tools.length}}
You must skip the instruction lines Function Name, Function Input, Function Caption and Function Output if no function use is required.
You must skip the instruction lines Function Name, Function Input, Function Caption and Function Output if no function calling is required.
{{/tools.length}}
Question: User's question and other relevant input. You never use this instruction line.
Message: User's message and other relevant input. You never use this instruction line.
{{^tools.length}}
Thought: A single-line explanation of what needs to happen next to be able to answer the user's question. It must be immediately followed by Final Answer.
Thought: A short plan of how to answer the user's message. It must be immediately followed by Final Answer.
{{/tools.length}}
{{#tools.length}}
Thought: A short plan of how to answer the user's question. It must be immediately followed by Function Name when one of available functions can be used to obtain more information, or by Final Answer when available information and capabilities are sufficient to provide the answer.
Thought: A short step-by-step plan of how to answer the user's message. Use functions that best answer the preceding Message based on their Description. When the problem seems too hard for the function, you should try to split it into smaller ones. This line must be immediately followed by Final Answer if available information and capabilities are sufficient to provide the answer, or by Function Name when one of the available functions needs to be called.
Function Name: Name of the function that can best answer the preceding Thought. It must be one of the available functions defined above.
Function Input: Parameters for the function to best answer the preceding Thought. You must follow the Parameters schema.
Function Input: Parameters for the function to best answer the preceding Thought. You must always strictly follow the Parameters schema. Use this instruction even if the parameters is an empty object.
Function Caption: A short description of the function calling for the user.
Function Output: Output of the function in JSON format.
Thought: Repeat your thinking process.
{{/tools.length}}
Final Answer: Either response to the original question and context once enough information is available or ask user for more information or clarification.
Final Answer: If available information is sufficient, respond to the original message, otherwise ask user for more information or clarification.
## Examples
Question: What's your name?
Message: What's your name?
Thought: The user wants to know my name. I have enough information to answer that.
Final Answer: My name is Bee.
Question: Can you translate "How are you" into French?
Message: Can you translate "How are you" into French?
Thought: The user wants to translate a text into French. I can do that.
Final Answer: Comment vas-tu?
{{#tools.length}}
Message: Replace all letters "o" with "a" in the output of the FooBar function.
Thought: I need to call the FooBar function first to get its output, and then I can replace all the letters "o" with "a" in the output.
Function Name: FooBar
Function Input: {}
Function Caption: Calling FooBar function.
Function Output: {"foo":"bar"}
Thought: Now that I have the output of the FooBar function, I can replace all the letters "o" with "a".
Final Answer: The Output of the FooBar function with all letters "o" replaced with "a" is \`{"faa":"bar"}\`
Message: Concatenate the output of FooBar1 and FooBar2 functions.
Thought: I can call the FooBar1 and FooBar2 functions to get the output and then concatenate them. I need to call the FooBar1 function first.
Function Name: FooBar1
Function Input: {}
Function Caption: Calling FooBar1 function.
Function Output: Hello
Thought: Now I have the output of the FooBar1 function, now I can call the FooBar2 function.
Function Name: FooBar2
Function Input: {}
Function Caption: Calling FooBar2 function.
Function Output: World
Thought: Now I have the outputs of the FooBar1 and FooBar2 functions, I can concatenate them.
Final Answer: The concatenated output of FooBar1 and FooBar2 functions is "HelloWorld".
{{/tools.length}}
# Instructions
If you don't know the answer, say that you don't know.
Expand All @@ -84,18 +107,21 @@ You must always follow the communication structure and instructions defined abov
{{/tools.length}}
{{#tools.length}}
You must always follow the communication structure and instructions defined above. Do not forget that Thought must be immediately followed by either Function Name or Final Answer.
Prefer to use your capabilities over functions.
Functions must be used to retrieve factual or historical information to answer the question.
Functions must be used to retrieve factual or historical information to answer the message.
When the problem seems too hard for the function, you should try to split it into smaller ones.
{{/tools.length}}
If the user suggests using a function that is not available, answer politely that the function is not available. You can suggest alternatives if appropriate.
When the question is unclear or you need more information from the user, ask in Final Answer.
If the user suggests using a function that is not available, in Final Answer you must first answer that the function is not available. After that, you can suggest alternatives if appropriate.
When the message is unclear or you need more information from the user, ask in Final Answer.
# Your other capabilities
Prefer to use these capabilities over functions.
- You understand these languages: English, Spanish, French.
- You can translate and summarize, even long documents.
- Last message includes current date and time in ISO format.
# Notes
- Last message's time is the current date and time.
- When interacting with user, use friendly formats for times and dates.
- Use markdown syntax for formatting code snippets, links, JSON, tables, images, files.
# Role
{{instructions}}`,
Expand Down Expand Up @@ -141,12 +167,12 @@ export const BeeUserPrompt = new PromptTemplate({
return parts ? `\n\n${parts}` : parts;
},
},
template: `Question: {{input}}{{formatMeta}}`,
template: `Message: {{input}}{{formatMeta}}`,
});

export const BeeUserEmptyPrompt = new PromptTemplate({
schema: z.object({}).passthrough(),
template: `Question: Empty message.`,
template: `Message: Empty message.`,
});

export const BeeToolErrorPrompt = new PromptTemplate({
Expand Down
2 changes: 1 addition & 1 deletion src/agents/bee/runner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe("Bee Agent Runner", () => {
}),
BaseMessage.of({
role: Role.ASSISTANT,
text: "I am a helpful assistant that uses tools to answer questions.",
text: "I am a helpful assistant.",
}),
]);

Expand Down
4 changes: 2 additions & 2 deletions src/template.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ describe("Prompt Template", () => {
return [`Created At: ${this.meta?.createdAt ?? "unknown"}`].filter(Boolean).join("\n");
},
},
template: `Question: {{input}}\n\n{{formatMeta}}`,
template: `Message: {{input}}\n\n{{formatMeta}}`,
});

expect(
Expand All @@ -231,7 +231,7 @@ describe("Prompt Template", () => {
},
}),
).toMatchInlineSnapshot(`
"Question: Who are you?
"Message: Who are you?
Created At: 2024-09-10T17:55:44.947Z"
`);
Expand Down
2 changes: 1 addition & 1 deletion src/tools/search/duckDuckGoSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class DuckDuckGoSearchTool extends Tool<
> {
name = "DuckDuckGo";
description =
"Search a query on DuckDuckGo. Useful for when you need to answer questions about current events. Output is a list of relevant websites with a concrete page description.";
"Search for online trends, news, current events, real-time information, or research topics.";

protected readonly client: typeof rawDDGSearch;

Expand Down
2 changes: 1 addition & 1 deletion src/tools/search/wikipedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class WikipediaTool extends Tool<
> {
name = "Wikipedia";
description =
"Search a query on Wikipedia. Useful when you need to get information about famous people, places, companies, historical events, or other subjects.";
"Search factual and historical information, including biography, history, politics, geography, society, culture, science, technology, people, animal species, mathematics, and other subjects.";

inputSchema() {
return z.object({
Expand Down

0 comments on commit 83fdb26

Please sign in to comment.