Closed j-loquat closed 1 year ago
Direct link to the Guidance project and section around agents: https://github.com/guidance-ai/guidance#agents-notebook
We can easily build agents that talk to each other or to a user, via the await command. The await command allows us to pause execution and return a partially executed guidance program. By putting await in a loop, that partially executed program can then be called again and again to form a dialog (or any other structure you design). For example, here is how we might get GPT-4 to simulate two agents talking to one another:
import guidance import re guidance.llm = guidance.llms.OpenAI("gpt-4") role_simulator = guidance(''' {{#system~}} You are a helpful assistant {{~/system}}
{{#user~}} You will answer the user as {{role}} in the following conversation. At every step, I will provide you with the user input, as well as a comment reminding you of your instructions. Never talk about the fact that you are an AI, even if the user asks you. Always answer as {{role}}. {{#if first_question}}You can also start the conversation.{{/if}} {{~/user}}
{{~! The assistant either starts the conversation or not, depending on if this is the first or second agent }} {{#assistant~}} Ok, I will follow these instructions. {{#if first_question}}Let me start the conversation now: {{role}}: {{first_question}}{{/if}} {{~/assistant}}
{{~! Then the conversation unrolls }} {{~#geneach 'conversation' stop=False}} {{#user~}} User: {{set 'this.input' (await 'input')}} Comment: Remember, answer as a {{role}}. Start your utterance with {{role}}: {{~/user}}
{{#assistant~}} {{gen 'this.response' temperature=0 max_tokens=300}} {{~/assistant}} {{~/geneach}}''')
republican = role_simulator(role='Republican', await_missing=True) democrat = role_simulator(role='Democrat', await_missing=True)
Output: Democrat: What do you think is the best way to stop inflation?
Republican: The best way to stop inflation is by implementing sound fiscal policies, such as reducing government spending, lowering taxes, and promoting economic growth. Additionally, the Federal Reserve should focus on maintaining a stable monetary policy to control inflation.
Democrat: I agree that sound fiscal policies are important in controlling inflation. As a Democrat, I would emphasize the importance of investing in education, healthcare, and infrastructure to promote long-term economic growth. Additionally, we should ensure that the Federal Reserve maintains a balanced approach to monetary policy, focusing on both controlling inflation and promoting full employment.
Republican: While investing in education, healthcare, and infrastructure is important, we must also prioritize reducing the national debt and limiting government intervention in the economy. By lowering taxes and reducing regulations, we can encourage businesses to grow and create jobs, which will ultimately lead to long-term economic growth. As for the Federal Reserve, it's crucial to maintain a stable monetary policy that primarily focuses on controlling inflation, as this will create a more predictable economic environment for businesses and consumers.
Democrat: While reducing the national debt and limiting government intervention are valid concerns, Democrats believe that strategic investments in education, healthcare, and infrastructure can lead to long-term economic growth and job creation. We also support a progressive tax system that ensures everyone pays their fair share, which can help fund these investments. As for the Federal Reserve, we believe that a balanced approach to monetary policy, focusing on both controlling inflation and promoting full employment, is essential for a healthy economy. We must strike a balance between fiscal responsibility and investing in our nation's future.
Republican: It's important to find a balance between fiscal responsibility and investing in our nation's future. However, we believe that the best way to achieve long-term economic growth and job creation is through free-market principles, such as lower taxes and reduced regulations. This approach encourages businesses to expand and innovate, leading to a more prosperous economy. A progressive tax system can sometimes discourage growth and investment, so we advocate for a simpler, fairer tax system that promotes economic growth. Regarding the Federal Reserve, while promoting full employment is important, we must not lose sight of the primary goal of controlling inflation to maintain a stable and predictable economic environment.
Democrat: I understand your perspective on free-market principles, but Democrats believe that a certain level of government intervention is necessary to ensure a fair and equitable economy. We support a progressive tax system to reduce income inequality and provide essential services to those in need. Additionally, we believe that regulations are important to protect consumers, workers, and the environment. As for the Federal Reserve, we agree that controlling inflation is crucial, but we also believe that promoting full employment should be a priority. By finding a balance between these goals, we can create a more inclusive and prosperous economy for all Americans.
Thank you. We will test Microsoft Guidance soon, and will consider it if smoothly works.
Use Microsoft Guidance framework for agent communications https://github.com/guidance-ai/guidance
This would allow each agent's output to be structured and controlled accordingly to their roles. This YouTube video explains it well : https://youtu.be/69bH4IHZivs?si=RkdCcQRARFT84bof