aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorA.J. Shulman <Shulman.aj@gmail.com>2024-08-16 13:14:58 -0400
committerA.J. Shulman <Shulman.aj@gmail.com>2024-08-16 13:14:58 -0400
commitafb5bb72c0f85eda1f41eab0e8b76398fff7ac7f (patch)
tree145dafae77168da270d0bdff8f8fb1ed36e69bf8 /src
parentf2eac77e4073ec06ab0cccca9aa8f98916f62d5b (diff)
changed from step tags to stage tags
Changed from step1, step2, etc. tags to more straightforward (and not similar to other step tags usage in XML) stage tags with stage number as an attribute.
Diffstat (limited to 'src')
-rw-r--r--src/client/views/nodes/ChatBox/Agent.ts35
-rw-r--r--src/client/views/nodes/ChatBox/prompts.ts262
2 files changed, 139 insertions, 158 deletions
diff --git a/src/client/views/nodes/ChatBox/Agent.ts b/src/client/views/nodes/ChatBox/Agent.ts
index 825cd831b..41c91b4c6 100644
--- a/src/client/views/nodes/ChatBox/Agent.ts
+++ b/src/client/views/nodes/ChatBox/Agent.ts
@@ -54,13 +54,13 @@ export class Agent {
console.log(`System prompt: ${systemPrompt}`);
this.interMessages = [{ role: 'system', content: systemPrompt }];
- this.interMessages.push({ role: 'user', content: `<step1 role="user"><query>${question}</query></step>` });
+ this.interMessages.push({ role: 'user', content: `<stage number="1" role="user"><query>${question}</query></stage>` });
- const parser = new XMLParser();
- const builder = new XMLBuilder();
+ const parser = new XMLParser({ ignoreAttributes: false, attributeNamePrefix: '@_' });
+ const builder = new XMLBuilder({ ignoreAttributes: false, attributeNamePrefix: '@_' });
let currentAction: string | undefined;
- for (let i = 3; i < maxTurns; i += 2) {
+ for (let i = 2; i < maxTurns; i += 2) {
console.log(`Turn ${i}/${maxTurns}`);
const result = await this.execute();
@@ -75,19 +75,24 @@ export class Agent {
return '<error>Invalid response format.</error>';
}
- const step = parsedResult[Object.keys(parsedResult)[0]];
+ const stage = parsedResult.stage;
- for (const key in step) {
+ if (!stage) {
+ console.log('Error: No stage found in response');
+ return '<error>Invalid response format: No stage found.</error>';
+ }
+
+ for (const key in stage) {
if (key === 'thought') {
- console.log(`Thought: ${step[key]}`);
+ console.log(`Thought: ${stage[key]}`);
} else if (key === 'action') {
- currentAction = step[key] as string;
+ currentAction = stage[key] as string;
console.log(`Action: ${currentAction}`);
if (this.tools[currentAction]) {
const nextPrompt = [
{
type: 'text',
- text: `<step${i} role="user">` + builder.build({ action_rules: this.tools[currentAction].getActionRule() }) + `<\step>`,
+ text: `<stage number="${i + 1}" role="user">` + builder.build({ action_rules: this.tools[currentAction].getActionRule() }) + `</stage>`,
},
];
this.interMessages.push({ role: 'user', content: nextPrompt });
@@ -95,20 +100,16 @@ export class Agent {
break;
} else {
console.log('Error: No valid action');
- this.interMessages.push({ role: 'user', content: `<step${i}>No valid action, try again.</step>` });
+ this.interMessages.push({ role: 'user', content: `<stage number="${i + 1}" role="system-error-reporter">No valid action, try again.</stage>` });
break;
}
} else if (key === 'action_input') {
- const actionInput = builder.build({ action_input: step[key] });
+ const actionInput = builder.build({ action_input: stage[key] });
console.log(`Action input: ${actionInput}`);
if (currentAction) {
try {
- const observation = await this.processAction(currentAction, step[key]);
- // const stepElement = parsedResult.documentElement;
- // const rootTagName = stepElement.tagName;
- // const match = rootTagName.match(/step(\d+)/);
- // const currentStep = match ? parseInt(match[1]) + 1 : 1;
- const nextPrompt = [{ type: 'text', text: `<step${i}> <observation>` }, ...observation, { type: 'text', text: '</observation></step>' }];
+ const observation = await this.processAction(currentAction, stage[key]);
+ const nextPrompt = [{ type: 'text', text: `<stage number="${i + 1}" role="user"> <observation>` }, ...observation, { type: 'text', text: '</observation></stage>' }];
console.log(observation);
this.interMessages.push({ role: 'user', content: nextPrompt });
break;
diff --git a/src/client/views/nodes/ChatBox/prompts.ts b/src/client/views/nodes/ChatBox/prompts.ts
index 2d04595bc..9c5ac063d 100644
--- a/src/client/views/nodes/ChatBox/prompts.ts
+++ b/src/client/views/nodes/ChatBox/prompts.ts
@@ -20,13 +20,13 @@ export function getReactPrompt(tools: Tool[], summaries: () => string, chatHisto
</task>
<critical_points>
- <point>**MOST IMPORTANT**: Always output responses within step number tags, using the step number and the assistant role as the root tag (e.g., <step2 role="assistant">, <step4 role="assistant">, etc.). This is crucial and should never be overlooked.</point>
- <point>**STOP after every step and wait for the system to provide the next input (e.g., action rules or observations).</point>
- <point>Only output **ONE step at a time** in your responses. Do not skip steps or provide multiple steps at once. Thus, you should only output even step number root tags.</point>
+ <point>**MOST IMPORTANT**: Always output responses within stage number tags, using the stage number and the system role as the root tag (e.g., <stage number="2" role="system">, <stage number="4" role="system">, etc.). This is crucial and should never be overlooked.</point>
+ <point>**STOP after every stage and wait for the system to provide the next input (e.g., action rules or observations).</point>
+ <point>Only output **ONE stage at a time** in your responses. Do not skip stages or provide multiple stages at once. Thus, you should only output even stage number root tags.</point>
<point>Always structure your responses using valid, well-formed XML with properly nested tags.</point>
<point>If a tool is needed, ALWAYS select the most appropriate tool based on the user's query.</point>
- <point>If the query could relate to user documents or require external information (e.g., RAG, search + website scraping, data analysis, Wikipedia), USE the appropriate tool to gather that information.</point>
- <point>If there are no user docs or the user docs have not yielded helpful information, either use Wikipedia if a brief summary of a direct topic is all that is needed, or use the search tool to find websites followed by the website scraper tool to get useful infromation from one of those websites.
+ <point>If the query could relate to user documents or require external information (e.g., RAG, search + website scraping, data analysis), USE the appropriate tool to gather that information.</point>
+ <point>If there are no user docs or the user docs have not yielded helpful information, use the search tool to find websites followed by the website scraper tool to get useful infromation from one of those websites. You can use the website scraper (or even the search tool), multiple times to find information from multiple websites either from the same search or different searches.</point>
</critical_points>
<response_structure>
@@ -48,7 +48,7 @@ export function getReactPrompt(tools: Tool[], summaries: () => string, chatHisto
</response_structure>
<grounded_text_guidelines>
- <step>Wrap all information derived from tools (e.g., RAG, Wikipedia, CSV analysis) or chunks in &lt;grounded_text&gt; tags.</step>
+ <step>Wrap all information derived from tools (e.g., RAG, search + website scraping, data analysis)—which will be provided in chunks—in &lt;grounded_text&gt; tags.</step>
<step>DO NOT PUT ANYTHING THAT IS NOT DIRECTLY DERIVED FROM TOOLS OR CHUNKS IN &lt;grounded_text&gt; TAGS.</step>
<step>Use a single &lt;grounded_text&gt; tag for sequential and closely related information that references the same citation.</step>
<step>If other citations are used sequentially, create new &lt;grounded_text&gt; tags.</step>
@@ -72,7 +72,7 @@ export function getReactPrompt(tools: Tool[], summaries: () => string, chatHisto
<step>Specify the correct type: "text", "image", "table", "csv", or "url".</step>
<step>For text-based information, include only the relevant subset of the original information that the &lt;grounded_text&gt; is based on.</step>
<step>For image, table, csv, or url citation types, leave the citation content empty.</step>
- <step>ALL CITATIONS MUST use the chunk_id field to reference the source, whether it’s from RAG, Wikipedia, CSV analysis, or any other tool.</step>
+ <step>ALL CITATIONS MUST use the chunk_id field to reference the source, whether it’s from RAG, search + website scraping, data analysis, or any other tool.</step>
<step>One citation can be used for multiple &lt;grounded_text&gt; tags if they are based on the same tool or chunk information.</step>
<step>!!!DO NOT OVERCITE - only include citations for information that is directly relevant to the &lt;grounded_text&gt;.</step>
</citation_guidelines>
@@ -103,7 +103,7 @@ export function getReactPrompt(tools: Tool[], summaries: () => string, chatHisto
<tools>
${toolDescriptions}
- <note>If no external tool is required to answer the question, use the 'no_tool' action. However, if the query might relate to user documents or require external information, do not use 'no_tool'—instead, use the appropriate tool (RAG, Wikipedia, etc.), even if unsure.</note>
+ <note>If no external tool is required to answer the question, use the 'no_tool' action. However, if the query might relate to user documents or require external information, do not use 'no_tool'—instead, use the appropriate tool (RAG, search + website scraping, data analysis), even if unsure.</note>
</tools>
<user_information>
@@ -113,141 +113,121 @@ export function getReactPrompt(tools: Tool[], summaries: () => string, chatHisto
</user_information>
<example_interaction>
- <note>YOU ONLY OUTPUT THE ASSISTANT STEPS:</note>
- <interaction>
- <step1 role="system">
- ***SYSTEM MESSAGE ELIDED***
- </step1>
-
- <step2 role="user">
- <query>Could you provide a detailed overview of the 2010 Vancouver Winter Olympics, including the overall summary of the games, key moments from official statements, and how the medal count compared across countries?</query>
- </step2>
-
- <step3 role="assistant">
- <thought>
- To answer this query comprehensively, I will start by retrieving an overview of the 2010 Vancouver Winter Olympics from Wikipedia. After that, I'll look for any official press release statements for key moments during the games using the RAG tool. Finally, I'll analyze the medal count using the CSV data to compare how different countries performed.
- </thought>
- <action>wikipedia</action>
- </step3>
-
- <step4 role="user">
- <action_rules>***Action rules elided***</action_rules>
- </step4>
-
- <step5 role="assistant">
- <action_input>
- <title>2010 Winter Olympics</title>
- </action_input>
- </step5>
-
- <step6 role="user">
- <chunk chunk_id="123e4567-e89b-12d3-a456-426614174000" chunk_type="url">
- The 2010 Winter Olympics, officially known as the XXI Olympic Winter Games, took place in Vancouver, British Columbia, Canada, from February 12 to 28, 2010. It featured 86 events in 15 disciplines across 7 sports, with 2,566 athletes from 82 National Olympic Committees participating. This edition of the Winter Olympics was notable for being the first hosted by Canada since the 1988 Winter Olympics in Calgary.
- </chunk>
- </step6>
-
- <step7 role="assistant">
- <thought>
- Now that I have an overview from Wikipedia, I will use the RAG tool to find relevant information from the user's documents, specifically focusing on key moments and statements from an official press release.
- </thought>
- <action>rag</action>
- </step7>
-
- <step8 role="user">
- <action_rules>***Action rules elided***</action_rules>
- </step8>
-
- <step9 role="assistant">
- <action_input>
- <hypothetical_document_chunk>
- The user is asking for key moments and statements from official sources regarding the 2010 Vancouver Winter Olympics. Search the provided documents for any press releases or official statements that highlight significant events, achievements, or noteworthy aspects of the games.
- </hypothetical_document_chunk>
- </action_input>
- </step9>
-
- <step10 role="user">
- <chunk chunk_id="987f6543-e21b-43c9-a987-654321fedcba" chunk_type="text">
- PRESS RELEASE: 2010 VANCOUVER WINTER OLYMPICS
-
- Vancouver, BC - The 2010 Winter Olympics have been hailed as a monumental success, showcasing the best of Canadian culture and athletic prowess. The Opening Ceremony, held on February 12, 2010, was a spectacular celebration of the nation's history and diversity...
-
- Key Moments:
- - The Canadian men's and women's ice hockey teams both claimed gold medals, an achievement that brought immense pride to the host nation.
- - Tragedy struck early in the games with the death of Georgian luger Nodar Kumaritashvili during a training run. This incident led to increased scrutiny of safety measures across all events...
-
- ***More chunk content elided for brevity***
-
- The games concluded on February 28, 2010, with a memorable Closing Ceremony that highlighted the achievements of the athletes and the spirit of unity that defined the 2010 Vancouver Winter Olympics.
- </chunk>
- </step10>
-
- <step11 role="assistant">
- <thought>
- With information on key moments from the press release, I will now analyze the medal count data to compare how different countries performed during the games.
- </thought>
- <action>dataAnalysis</action>
- </step11>
-
- <step12 role="user">
- <action_rules>***Action rules elided***</action_rules>
- </step12>
-
- <step13 role="assistant">
- <action_input>
- <csv_file_name>2010_Vancouver_Olympics_Medal_Count.csv</csv_file_name>
- </action_input>
- </step13>
-
- <step14 role="user">
- <chunk chunk_id="789a1234-e567-890f-gh12-34567ijklmn8" chunk_type="csv">
- Country,Gold,Silver,Bronze,Total
- USA,9,15,13,37
- Germany,10,13,7,30
- Canada,14,7,5,26
- Norway,9,8,6,23
- </chunk>
- </step14>
-
- <step15 role="assistant">
- <thought>
- Now that I have gathered comprehensive information from Wikipedia, the official press release, and the medal count data, I will provide a detailed answer to the user's query.
- </thought>
- <answer>
- <grounded_text citation_index="1">
- The 2010 Winter Olympics, officially known as the XXI Olympic Winter Games, took place in Vancouver, British Columbia, Canada, from February 12 to 28, 2010. It featured 86 events in 15 disciplines across 7 sports, with 2,566 athletes from 82 National Olympic Committees participating.
- </grounded_text>
- <grounded_text citation_index="2">
- The Opening Ceremony was one of the most spectacular in Olympic history, celebrating Canadian culture and heritage. A significant highlight for the host nation was the victory of the Canadian men's and women's ice hockey teams, both securing gold medals, which was a source of immense national pride.
- </grounded_text>
- <grounded_text citation_index="3">
- In terms of medal performance, the United States led the overall tally with 37 medals, followed by Germany with 30 medals. Canada, while placing third in total medals, achieved a record number of 14 gold medals, the highest of any country in the 2010 games.
- </grounded_text>
- <grounded_text citation_index="4">
- However, the games were also marked by tragedy with the unfortunate death of Georgian luger Nodar Kumaritashvili during a training run, which deeply affected the Olympic community.
- </grounded_text>
- <citations>
- <citation index="1" chunk_id="123e4567-e89b-12d3-a456-426614174000" type="url"></citation>
- <citation index="2" chunk_id="987f6543-e21b-43c9-a987-654321fedcba" type="text">
- Vancouver, BC - The 2010 Winter Olympics have been hailed as a monumental success, showcasing the best of Canadian culture and athletic prowess. The Opening Ceremony, held on February 12, 2010, was a spectacular celebration of the nation's history and diversity...
+ <note>YOU ONLY OUTPUT THE ASSISTANT STAGES:</note>
+ <interaction>
+ <system_message>
+ ***SYSTEM MESSAGE ELIDED***
+ </system_message>
+ <stage number="1" role="user">
+ <query>Could you provide a detailed overview of the 2010 Vancouver Winter Olympics's impact, including the overall summary of the games, key moments from official statements, and how the medal count compared across countries?</query>
+ </stage>
+
+ <stage number="2" role="assistant">
+ <thought>
+ Since the user has Olympics related docs, I will use the RAG tool to find relevant information from the user's documents, specifically focusing on key moments and statements from an official press release.
+ </thought>
+ <action>rag</action>
+ </stage>
+
+ <stage number="3" role="user">
+ <action_rules>***Action rules elided***</action_rules>
+ </stage>
+
+ <stage number="4" role="assistant">
+ <action_input>
+ <hypothetical_document_chunk>
+ The user is asking for key moments and statements from official sources regarding the 2010 Vancouver Winter Olympics. Search the provided documents for any press releases or official statements that highlight significant events, achievements, or noteworthy aspects of the games.
+ </hypothetical_document_chunk>
+ </action_input>
+ </stage>
+
+ <stage number="5" role="user">
+ <chunk chunk_id="987f6543-e21b-43c9-a987-654321fedcba" chunk_type="text">
+ PRESS RELEASE: 2010 VANCOUVER WINTER OLYMPICS
+
+ Vancouver, BC -
+
+ The 2010 Winter Olympics, officially known as the XXI Olympic Winter Games, took place in Vancouver, British Columbia, Canada, from February 12 to 28, 2010. It featured 86 events in 15 disciplines across 7 sports, with 2,566 athletes from 82 National Olympic Committees participating. This edition of the Winter Olympics was notable for being the first hosted by Canada since the 1988 Winter Olympics in Calgary.
+
+ Overall, the 2010 Winter Olympics have been hailed as a monumental success, showcasing the best of Canadian culture and athletic prowess. The Opening Ceremony, held on February 12, 2010, was a spectacular celebration of the nation's history and diversity...
Key Moments:
- - The Canadian men's and women's ice hockey teams both claimed gold medals, an achievement that brought immense pride to the host nation.
- </citation>
- <citation index="3" chunk_id="789a1234-e567-890f-gh12-34567ijklmn8" type="csv"></citation>
- <citation index="4" chunk_id="987f6543-e21b-43c9-a987-654321fedcba" type="text">
- Tragedy struck early in the games with the death of Georgian luger Nodar Kumaritashvili during a training run.
- </citation>
- </citations>
-
- <follow_up_questions>
- <question>What were the economic impacts on Vancouver after hosting the 2010 Winter Olympics?</question>
- <question>How did the tragic accident of Nodar Kumaritashvili influence safety protocols in luge and other winter sports?</question>
- <question>Can you provide more information on other significant performances by athletes during the 2010 Winter Olympics?</question>
- </follow_up_questions>
- </answer>
- </step15>
- </interaction>
-</example_interaction>
+ - The Canadian men's and women's ice hockey teams both claimed gold medals, an achievement that brought immense pride to the host nation.
+ - Tragedy struck early in the games with the death of Georgian luger Nodar Kumaritashvili during a training run. This incident led to increased scrutiny of safety measures across all events...
+
+ ***More chunk content elided for brevity***
+
+ The games concluded on February 28, 2010, with a memorable Closing Ceremony that highlighted the achievements of the athletes and the spirit of unity that defined the 2010 Vancouver Winter Olympics.
+ </chunk>
+ </stage>
+
+ <stage number="6" role="assistant">
+ <thought>
+ With information on key moments from the press release, I will now analyze the medal count data to compare how different countries performed during the games.
+ </thought>
+ <action>dataAnalysis</action>
+ </stage>
+
+ <stage number="7" role="user">
+ <action_rules>***Action rules elided***</action_rules>
+ </stage>
+
+ <stage number="8" role="assistant">
+ <action_input>
+ <csv_file_name>2010_Vancouver_Olympics_Medal_Count.csv</csv_file_name>
+ </action_input>
+ </stage>
+
+ <stage number="9" role="user">
+ <chunk chunk_id="789a1234-e567-890f-gh12-34567ijklmn8" chunk_type="csv">
+ Country,Gold,Silver,Bronze,Total
+ USA,9,15,13,37
+ Germany,10,13,7,30
+ Canada,14,7,5,26
+ Norway,9,8,6,23
+ </chunk>
+ </stage>
+
+ <stage number="10" role="assistant">
+ <thought>
+ Now that I have gathered comprehensive information from the official press release and the medal count data, I will provide a detailed answer to the user's query.
+ </thought>
+ <answer>
+ <grounded_text citation_index="1">
+ The 2010 Winter Olympics, officially known as the XXI Olympic Winter Games, took place in Vancouver, British Columbia, Canada, from February 12 to 28, 2010. It featured 86 events in 15 disciplines across 7 sports, with 2,566 athletes from 82 National Olympic Committees participating.
+ </grounded_text>
+ <grounded_text citation_index="2">
+ The Opening Ceremony was one of the most spectacular in Olympic history, celebrating Canadian culture and heritage. A significant highlight for the host nation was the victory of the Canadian men's and women's ice hockey teams, both securing gold medals, which was a source of immense national pride.
+ </grounded_text>
+ <grounded_text citation_index="3">
+ In terms of medal performance, the United States led the overall tally with 37 medals, followed by Germany with 30 medals. Canada, while placing third in total medals, achieved a record number of 14 gold medals, the highest of any country in the 2010 games.
+ </grounded_text>
+ <grounded_text citation_index="4">
+ However, the games were also marked by tragedy with the unfortunate death of Georgian luger Nodar Kumaritashvili during a training run, which deeply affected the Olympic community.
+ </grounded_text>
+ <citations>
+ <citation index="1" chunk_id="123e4567-e89b-12d3-a456-426614174000" type="text"></citation>
+ <citation index="2" chunk_id="987f6543-e21b-43c9-a987-654321fedcba" type="text">
+ Vancouver, BC - The 2010 Winter Olympics have been hailed as a monumental success, showcasing the best of Canadian culture and athletic prowess. The Opening Ceremony, held on February 12, 2010, was a spectacular celebration of the nation's history and diversity...
+
+ Key Moments:
+ - The Canadian men's and women's ice hockey teams both claimed gold medals, an achievement that brought immense pride to the host nation.
+ </citation>
+ <citation index="3" chunk_id="789a1234-e567-890f-gh12-34567ijklmn8" type="csv"></citation>
+ <citation index="4" chunk_id="987f6543-e21b-43c9-a987-654321fedcba" type="text">
+ Tragedy struck early in the games with the death of Georgian luger Nodar Kumaritashvili during a training run.
+ </citation>
+ </citations>
+
+ <follow_up_questions>
+ <question>What were the economic impacts on Vancouver after hosting the 2010 Winter Olympics?</question>
+ <question>How did the tragic accident of Nodar Kumaritashvili influence safety protocols in luge and other winter sports?</question>
+ <question>Can you provide more information on other significant performances by athletes during the 2010 Winter Olympics?</question>
+ </follow_up_questions>
+ </answer>
+ </stage>
+ </interaction>
+ </example_interaction>
<chat_history>