# Aww: automatic self-improvement of prompts

I implemented self-improvement of prompts in [Augmented Awareness](https://github.com/robertolupi/augmented-awareness). It uses two LLM agents, one acts as the generator and a second one as the critique. The critique receives the prompt, the input and the output of the generator agent, and generates an improved prompt.

It is still an open-loop control for now, meaning the critique doesn’t receive human feedback.

The code looks like the following:

```python
def rewrite_prompt(...):

    # ...

    critique_model = make_model(...)
    critique_agent = Agent(model=critique_model)

    @critique_agent.system_prompt
    def critique():
        return textwrap.dedent("""
        You are an expert at writing LLM prompts. You will receive:
        1) the prompt
        2) the output
        3) a series of input messages
        Your job is to write a revised prompt that is more performant.
        Write only the revised prompt in full, in markdown format.
        """)

    prompt = prompt_file.read_text()

    llm_model = make_model(...)
    gen_agent = Agent(model=llm_model, system_prompt=prompt)

    async def do_critique():
        gen_result = await gen_agent.run(user_prompt=content)
        gen_output = gen_result.output
        critique_result = await critique_agent.run(user_prompt=[prompt, gen_output] + content)
        return critique_result.output

    revised_prompt = asyncio.run(do_critique())
    prompt_file.write_text(revised_prompt)
```

  
I believe the **principle of AI productivity** is that AI systems should be able to improve themselves. That’s how exponential progress can be achieved.  
  
Balancing errors and improvements is the challenging part. That's why it remains a human-in-the-loop process. For Aww, this involves manually analyzing the results and making git commits of the revised prompts.  
  
Aww is a *recursive* system that uses four different agents to create daily, weekly, monthly, and yearly retrospectives, which build on each other. Future updates will aim to make self-improvement and self-adaptation automatic and cover multiple levels.
