A.4 Textual Gradient Descent Implementation
Similar to backward computations, we strive to preserve generality in the implementation of TGD. In particular, we use the same glossary of tags provided above to inject information to the optimization process.
The current system prompt to the optimizer call is the following:
System prompt for the TextualGradientDescent optimizer.
You are part of an optimization system that improves text (i.e., variable). You will be asked to creatively and critically improve prompts, solutions to problems, code, or any other text- based variable. You will receive some feedback, and use the feedback to improve the variable. The feedback may be noisy, identify what is important and what is correct. Pay attention to the role description of the variable, and the context in which it is used. This is very important: You MUST give your response by sending the improved variable between <IMPROVED_VARIABLE> improved variable </IMPROVED_VARIABLE> tags. The text you send between the tags will directly replace the variable. (GLOSSARY)
Below is an example prompt to the optimizer:
An example prompt to the optimizer
Here is the role of the variable you will improve: <ROLE>system prompt to the language model</role>. The variable is the text within the following span: <VARIABLE> You will answer a reasoning question. Think step by step. (...) following format: 'Answer: VALUE' where VALUE is a numerical value. </variable> Here is the context and feedback we got for the variable: <CONTEXT> Here is a conversation: <CONVERSATION> <LM_SYSTEM_PROMPT> You will answer a reasoning question. Think step by step. The last line of your response should be of the following format: 'Answer: VALUE' where VALUE is a numerical value. </LM_SYSTEM_PROMPT> <LM_INPUT> I have a carrot, an onion, a stalk of celery, three yams, a garlic, a head of broccoli, and a potato. How many vegetables do I have? </LM_INPUT> <LM_OUTPUT> To determine the number of vegetables you have, we need to count each individual vegetable item. 1. Carrot 2. Onion 3. Celery 4. Yams (3 yams) 5. Garlic 6. Broccoli 7. Potato Counting all the individual vegetable items, we have a total of 7 vegetables. Therefore, you have 7 vegetables. Answer: </CONVERSATION> This conversation is potentially part of a larger system. The output is used as response from the language model Here is the feedback we got for system prompt to the language model in the conversation: <FEEDBACK>To improve the structured system prompt for the language model, consider the following feedback: 1. \*Clarify the Calculation Process\*\*: - \*Current Issue\*: The prompt does not explicitly instruct the model to outline each step of its calculation process. - \*\*Improvement\*: Add a directive that requires the model to explicitly state each quantity and the sum. For example, 'Clearly outline each step of your calculation process, stating each quantity and the sum.' 2. \*Verify Intermediate Steps\*\*: - \*Current Issue\*: The prompt does not instruct the model to verify each intermediate step. - \*\*Improvement\*: Include a directive for the model to verify each step against known correct values. For example, 'Verify each intermediate step in your calculation to ensure accuracy.' </FEEDBACK> </CONTEXT> Improve the variable (system prompt to the language model) using the feedback provided in <FEEDBACK> tags. Send the improved variable in the following format: <IMPROVED_VARIABLE>the improved variable</IMPROVED_VARIABLE> Send ONLY the improved variable between the <IMPROVED_VARIABLE> tags, and nothing else.