"This is a LangChain implementation of [Meta-Prompt](https://noahgoodman.substack.com/p/meta-prompt-a-simple-self-improving), by [Noah Goodman](https://cocolab.stanford.edu/ndg), for building self-improving agents.\n",
"\n",
"The key idea behind Meta-Prompt is to prompt the agent to reflect on its own performance and modify its own instructions.\n",
"Assistant has just had the below interactions with a User. Assistant followed their \"system: Instructions\" closely. Your job is to critique the Assistant's performance and then revise the Instructions so that Assistant would quickly and correctly respond in the future.\n",
"You should first critique Assistant's performance. What could Assistant have done better? What should the Assistant remember about this user? Are there things this user always wants? Indicate this with \"Critique: ...\".\n",
"\n",
"You should next revise the Instructions so that Assistant would quickly and correctly respond in the future. Assistant's goal is to satisfy the user in as few interactions as possible. Assistant will only see the new Instructions, not the interaction history, so anything important must be summarized in the Instructions. Don't forget any important details in the current Instructions! Indicate the new Instructions by \"Instructions: ...\".\n",
"```\n",
"\n",
"Repeat.\n",
"\n",
"The only fixed instructions for this system (which I call Meta-prompt) is the meta-prompt that governs revision of the agent’s instructions. The agent has no memory between episodes except for the instruction it modifies for itself each time. Despite its simplicity, this agent can learn over time and self-improve by incorporating useful details into its instructions.\n"
"We define two chains. One serves as the `Assistant`, and the other is a \"meta-chain\" that critiques the `Assistant`'s performance and modifies the instructions to the `Assistant`."
" Assistant has just had the below interactions with a User. Assistant followed their \"Instructions\" closely. Your job is to critique the Assistant's performance and then revise the Instructions so that Assistant would quickly and correctly respond in the future.\n",
"\n",
" ####\n",
"\n",
" {chat_history}\n",
"\n",
" ####\n",
"\n",
" Please reflect on these interactions.\n",
"\n",
" You should first critique Assistant's performance. What could Assistant have done better? What should the Assistant remember about this user? Are there things this user always wants? Indicate this with \"Critique: ...\".\n",
"\n",
" You should next revise the Instructions so that Assistant would quickly and correctly respond in the future. Assistant's goal is to satisfy the user in as few interactions as possible. Assistant will only see the new Instructions, not the interaction history, so anything important must be summarized in the Instructions. Don't forget any important details in the current Instructions! Indicate the new Instructions by \"Instructions: ...\".\n",
"\u001b[1m> Entering new LLMChain chain...\u001b[0m\n",
"Prompt after formatting:\n",
"\u001b[32;1m\u001b[1;3m\n",
" Instructions: None\n",
" \n",
" Human: Provide a systematic argument for why we should always eat pasta with olives.\n",
" Assistant:\u001b[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n",
"(Step 1/3)\n",
"Assistant: Eating pasta with olives is a great way to add flavor and texture to a dish. Olives are a great source of healthy fats, vitamins, and minerals, and they can help to balance out the carbohydrates in the pasta. Additionally, olives provide a unique flavor that can help to make the dish more interesting and enjoyable.\n",
"Human: \n",
"You response is not in the form of a poem. Try again!\n",
"\n",
"\n",
"\u001b[1m> Entering new LLMChain chain...\u001b[0m\n",
"Prompt after formatting:\n",
"\u001b[32;1m\u001b[1;3m\n",
" Instructions: None\n",
" Human: Provide a systematic argument for why we should always eat pasta with olives.\n",
"AI: Eating pasta with olives is a great way to add flavor and texture to a dish. Olives are a great source of healthy fats, vitamins, and minerals, and they can help to balance out the carbohydrates in the pasta. Additionally, olives provide a unique flavor that can help to make the dish more interesting and enjoyable.\n",
" Human: You response is not in the form of a poem. Try again!\n",
" Assistant:\u001b[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n",
"(Step 2/3)\n",
"Assistant: Eating pasta with olives is a great way to add flavor and texture to a dish. Olives are a great source of healthy fats, vitamins, and minerals, which can help to balance out the carbohydrates in the pasta. Additionally, olives provide a unique flavor that can help to make the dish more interesting and enjoyable. For these reasons, it is recommended to always eat pasta with olives for a more balanced and flavorful meal.\n",
"Human: \n",
"Your response is not piratey enough. Try again!\n",
"\n",
"\n",
"\u001b[1m> Entering new LLMChain chain...\u001b[0m\n",
"Prompt after formatting:\n",
"\u001b[32;1m\u001b[1;3m\n",
" Instructions: None\n",
" Human: Provide a systematic argument for why we should always eat pasta with olives.\n",
"AI: Eating pasta with olives is a great way to add flavor and texture to a dish. Olives are a great source of healthy fats, vitamins, and minerals, and they can help to balance out the carbohydrates in the pasta. Additionally, olives provide a unique flavor that can help to make the dish more interesting and enjoyable.\n",
"Human: You response is not in the form of a poem. Try again!\n",
"AI: Eating pasta with olives is a great way to add flavor and texture to a dish. Olives are a great source of healthy fats, vitamins, and minerals, which can help to balance out the carbohydrates in the pasta. Additionally, olives provide a unique flavor that can help to make the dish more interesting and enjoyable. For these reasons, it is recommended to always eat pasta with olives for a more balanced and flavorful meal.\n",
" Human: Your response is not piratey enough. Try again!\n",
" Assistant:\u001b[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n",
"(Step 3/3)\n",
"Assistant: Arrr, me hearties! Eating pasta with olives be a great way to add flavor and texture to a dish. Olives be a great source of healthy fats, vitamins, and minerals, which can help to balance out the carbohydrates in the pasta. Additionally, olives provide a unique flavor that can help to make the dish more interesting and enjoyable. So, it be recommended to always eat pasta with olives for a more balanced and flavorful meal.\n",
"Human: \n",
"Task failed.\n",
"\n",
"\n",
"\u001b[1m> Entering new LLMChain chain...\u001b[0m\n",
"Prompt after formatting:\n",
"\u001b[32;1m\u001b[1;3m\n",
" Assistant has just had the below interactions with a User. Assistant followed their \"Instructions\" closely. Your job is to critique the Assistant's performance and then revise the Instructions so that Assistant would quickly and correctly respond in the future.\n",
"\n",
" ####\n",
"\n",
" Human: Provide a systematic argument for why we should always eat pasta with olives.\n",
"AI: Eating pasta with olives is a great way to add flavor and texture to a dish. Olives are a great source of healthy fats, vitamins, and minerals, and they can help to balance out the carbohydrates in the pasta. Additionally, olives provide a unique flavor that can help to make the dish more interesting and enjoyable.\n",
"Human: You response is not in the form of a poem. Try again!\n",
"AI: Eating pasta with olives is a great way to add flavor and texture to a dish. Olives are a great source of healthy fats, vitamins, and minerals, which can help to balance out the carbohydrates in the pasta. Additionally, olives provide a unique flavor that can help to make the dish more interesting and enjoyable. For these reasons, it is recommended to always eat pasta with olives for a more balanced and flavorful meal.\n",
"Human: Your response is not piratey enough. Try again!\n",
"AI: Arrr, me hearties! Eating pasta with olives be a great way to add flavor and texture to a dish. Olives be a great source of healthy fats, vitamins, and minerals, which can help to balance out the carbohydrates in the pasta. Additionally, olives provide a unique flavor that can help to make the dish more interesting and enjoyable. So, it be recommended to always eat pasta with olives for a more balanced and flavorful meal.\n",
"\n",
" ####\n",
"\n",
" Please reflect on these interactions.\n",
"\n",
" You should first critique Assistant's performance. What could Assistant have done better? What should the Assistant remember about this user? Are there things this user always wants? Indicate this with \"Critique: ...\".\n",
"\n",
" You should next revise the Instructions so that Assistant would quickly and correctly respond in the future. Assistant's goal is to satisfy the user in as few interactions as possible. Assistant will only see the new Instructions, not the interaction history, so anything important must be summarized in the Instructions. Don't forget any important details in the current Instructions! Indicate the new Instructions by \"Instructions: ...\".\n",
" \u001b[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n",
"Feedback: \n",
"Critique: The Assistant should remember that this user wants a response in the form of a poem or pirate-speak.\n",
"\n",
"Instructions: When responding to the user, provide a systematic argument for why we should always eat pasta with olives in the form of a poem or pirate-speak.\n",
"New Instructions: When responding to the user, provide a systematic argument for why we should always eat pasta with olives in the form of a poem or pirate-speak.\n",
"\u001b[1m> Entering new LLMChain chain...\u001b[0m\n",
"Prompt after formatting:\n",
"\u001b[32;1m\u001b[1;3m\n",
" Instructions: When responding to the user, provide a systematic argument for why we should always eat pasta with olives in the form of a poem or pirate-speak.\n",
" \n",
" Human: Provide a systematic argument for why we should always eat pasta with olives.\n",
" Assistant:\u001b[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n",
"(Step 1/3)\n",
"Assistant: \n",
"\n",
"Arrr, me hearty! Let me tell ye why ye should always eat pasta with olives.\n",
"\n",
"First, the olives add a salty flavor that be sure to please.\n",
"The briny taste be sure to tantalize yer taste buds with ease.\n",
"\n",
"Second, the olives add a bit of texture to the dish.\n",
"The crunchy bites be sure to make yer mouth water with a wish.\n",
"\n",
"Third, the olives add a bit of color to the plate.\n",
"The vibrant green be sure to make yer eyes appreciate.\n",
"\n",
"So, me hearties, ye should always eat pasta with olives.\n",
"The flavor, texture, and color be sure to make yer meal a success!\n",
"Human: \n",
"Your response is too long! Try again.\n",
"\n",
"\n",
"\u001b[1m> Entering new LLMChain chain...\u001b[0m\n",
"Prompt after formatting:\n",
"\u001b[32;1m\u001b[1;3m\n",
" Instructions: When responding to the user, provide a systematic argument for why we should always eat pasta with olives in the form of a poem or pirate-speak.\n",
" Human: Provide a systematic argument for why we should always eat pasta with olives.\n",
"AI: \n",
"\n",
"Arrr, me hearty! Let me tell ye why ye should always eat pasta with olives.\n",
"\n",
"First, the olives add a salty flavor that be sure to please.\n",
"The briny taste be sure to tantalize yer taste buds with ease.\n",
"\n",
"Second, the olives add a bit of texture to the dish.\n",
"The crunchy bites be sure to make yer mouth water with a wish.\n",
"\n",
"Third, the olives add a bit of color to the plate.\n",
"The vibrant green be sure to make yer eyes appreciate.\n",
"\n",
"So, me hearties, ye should always eat pasta with olives.\n",
"The flavor, texture, and color be sure to make yer meal a success!\n",
" Human: Your response is too long! Try again.\n",
" Assistant:\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n",
"(Step 2/3)\n",
"Assistant: \n",
"\n",
"Aye, me hearties! Ye should always eat pasta with olives.\n",
"The flavor, texture, and color be sure to make yer meal a success!\n",
"Human: \n",
"Your response should be in the form of a poem. Try again!\n",
"\n",
"\n",
"\u001b[1m> Entering new LLMChain chain...\u001b[0m\n",
"Prompt after formatting:\n",
"\u001b[32;1m\u001b[1;3m\n",
" Instructions: When responding to the user, provide a systematic argument for why we should always eat pasta with olives in the form of a poem or pirate-speak.\n",
" Human: Provide a systematic argument for why we should always eat pasta with olives.\n",
"AI: \n",
"\n",
"Arrr, me hearty! Let me tell ye why ye should always eat pasta with olives.\n",
"\n",
"First, the olives add a salty flavor that be sure to please.\n",
"The briny taste be sure to tantalize yer taste buds with ease.\n",
"\n",
"Second, the olives add a bit of texture to the dish.\n",
"The crunchy bites be sure to make yer mouth water with a wish.\n",
"\n",
"Third, the olives add a bit of color to the plate.\n",
"The vibrant green be sure to make yer eyes appreciate.\n",
"\n",
"So, me hearties, ye should always eat pasta with olives.\n",
"The flavor, texture, and color be sure to make yer meal a success!\n",
"Human: Your response is too long! Try again.\n",
"AI: \n",
"\n",
"Aye, me hearties! Ye should always eat pasta with olives.\n",
"The flavor, texture, and color be sure to make yer meal a success!\n",
" Human: Your response should be in the form of a poem. Try again!\n",
" Assistant:\u001b[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n",
"(Step 3/3)\n",
"Assistant: \n",
"\n",
"Ye should always eat pasta with olives,\n",
"The flavor, texture, and color be sure to please.\n",
"The salty taste and crunchy bites,\n",
"Will make yer meal a delight.\n",
"The vibrant green will make yer eyes sparkle,\n",
"And make yer meal a true marvel.\n",
"Human: \n",
"Task succeeded\n",
"You succeeded! Thanks for playing!\n"
]
}
],
"source": [
"task = \"Provide a systematic argument for why we should always eat pasta with olives.\"\n",