Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Read by thought-leaders and decision-makers around the world. Phone Number: +1-650-246-9381 Email: [email protected]
228 Park Avenue South New York, NY 10003 United States
Website: Publisher: https://towardsai.net/#publisher Diversity Policy: https://towardsai.net/about Ethics Policy: https://towardsai.net/about Masthead: https://towardsai.net/about
Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Founders: Roberto Iriondo, , Job Title: Co-founder and Advisor Works for: Towards AI, Inc. Follow Roberto: X, LinkedIn, GitHub, Google Scholar, Towards AI Profile, Medium, ML@CMU, FreeCodeCamp, Crunchbase, Bloomberg, Roberto Iriondo, Generative AI Lab, Generative AI Lab Denis Piffaretti, Job Title: Co-founder Works for: Towards AI, Inc. Louie Peters, Job Title: Co-founder Works for: Towards AI, Inc. Louis-François Bouchard, Job Title: Co-founder Works for: Towards AI, Inc. Cover:
Towards AI Cover
Logo:
Towards AI Logo
Areas Served: Worldwide Alternate Name: Towards AI, Inc. Alternate Name: Towards AI Co. Alternate Name: towards ai Alternate Name: towardsai Alternate Name: towards.ai Alternate Name: tai Alternate Name: toward ai Alternate Name: toward.ai Alternate Name: Towards AI, Inc. Alternate Name: towardsai.net Alternate Name: pub.towardsai.net
5 stars – based on 497 reviews

Frequently Used, Contextual References

TODO: Remember to copy unique IDs whenever it needs used. i.e., URL: 304b2e42315e

Resources

Take our 85+ lesson From Beginner to Advanced LLM Developer Certification: From choosing a project to deploying a working product this is the most comprehensive and practical LLM course out there!

Publication

An AI Agent to Replace Prompt Engineers
Latest   Machine Learning

An AI Agent to Replace Prompt Engineers

Last Updated on November 3, 2024 by Editorial Team

Author(s): Adam Ben Khalifa

Originally published on Towards AI.

Let’s build a multi-agent system that automates the prompt engineering process and transforms simple input prompts into advanced ones,
aka. An Advanced Prompt Generator!

We will see the idea behind this solution, the first iteration, the second iteration, and the testing, troubleshooting, and optimizations involved.

Eventually, we’ll have a robust prompt enhancer tool, and I’ll share links to the GitHub repository for this project and the Hugging Face Space for a quick demo of the agent at the end of this article.

Prompt Engineers right now

Table of Content

  • The idea
  • Modeling and building the solution
  • Testing and troubleshooting
  • A stable and optimized solution
  • Conclusion

The idea

After exploring various techniques for enhancing prompts, one idea clicked and stood out as particularly intuitive:
Utilizing a large language model (LLM) and guiding it with prompt engineering strategies and techniques to automate and generalize the process.

Here are the steps that were followed:

  • Use OpenAI’s prompting strategies to define a set of rules that ensure the creation of an advanced prompt.
  • Define multiple agents to generate results based on the input prompt and the defined rules.
  • Create a pipeline to define the flow of interactions between the multiple agents

Here’s a flowchart to better visualize these steps:

The described solution’s flowchart

Modeling and building the solution

After we defined the rules, we modeled the pipeline. We will group these rules into specific components and assign an agent to each component. That means every agent will be instructed using a predefined prompt to generate information based on the given rules and input.

Here’s a flowchart to better visualize this step:

The pipeline’s flowchart

Now, all that is left is to code everything and add access to the LLM.

We will use OpenAI’s GPT-4o-mini as the LLM because it is really powerful, stable, and cost-efficient. However, you can adjust the code later to work with any LLM API.

Testing and troubleshooting

The results were promising, so we’re on to something here. We often achieved high-quality advanced prompts. However, there were multiple problems.

The performance was not stable, and we frequently encountered irrelevant results, such as generation output from the prompt, information redundancy, and hallucinations.

Therefore, we needed to optimize our solution.

A stable and optimized solution

The identified causes of the problems mentioned above were the overlap of certain components in the pipeline, the underdevelopment of the agent’s prompts, and a lack of restrictions within.

So, we revisited and updated our pipeline by reducing the number of components and providing robust, well-detailed system prompts for the agents to tackle each component.

Here’s a flowchart of the updated pipeline:

The updated pipeline’s flowchart

With this update, we ensured a stable and robust system that resolved all the previous issues while reducing complexity and generation costs.

Here are some examples to evaluate the solution:
(You can also check the Github repo or the HF Space and try it yourself)

Example 1:

>>> INPUT PROMPT: 
how to write a book?
>>> ADVANCED PROMPT: 
As a knowledgeable writing coach, please provide a comprehensive guide on how to write a book.

Requirements:
1. Outline the key steps involved in the book writing process, including brainstorming, outlining, drafting, and revising.
2. Offer tips for maintaining motivation and overcoming writer's block.
3. Include advice on setting a writing schedule and establishing a writing environment.
4. Suggest resources for further learning about writing techniques and publishing options.

Structure your response as follows:
- Introduction to the book writing journey
- Step-by-step guide with actionable tips
- Strategies for motivation and productivity
- Recommended resources for aspiring authors

Keep the response medium in length (approximately 200-300 words) to ensure thorough coverage of the topic.

##REFERENCE SUGGESTIONS##
- "On Writing: A Memoir of the Craft" by Stephen King
Purpose: Offers insights into the writing process and practical advice for aspiring authors
Integration: Use as a guide for understanding the nuances of writing a book

- "The Elements of Style" by William Strunk Jr. and E.B. White
Purpose: Provides essential rules of English style and composition
Integration: Reference for improving writing clarity and effectiveness

- "Bird by Bird: Some Instructions on Writing and Life" by Anne Lamott
Purpose: Shares personal anecdotes and practical tips for overcoming writing challenges
Integration: Use for motivation and strategies to tackle the writing process

##THOUGHT PROCESS##
*Subtask 1*:
- **Description**: Introduce the book writing journey and its significance.
- **Reasoning**: Providing an introduction sets the context for aspiring authors, helping them understand the importance and challenges of writing a book.
- **Success criteria**: The introduction should clearly articulate the purpose of writing a book and inspire readers about the journey ahead.

*Subtask 2*:
- **Description**: Outline the key steps involved in the book writing process: brainstorming, outlining, drafting, and revising.
- **Reasoning**: Breaking down the writing process into clear steps helps authors navigate their journey systematically and reduces overwhelm.
- **Success criteria**: Each step should be defined with actionable tips, such as techniques for brainstorming ideas, structuring an outline, and strategies for effective drafting and revising.

*Subtask 3*:
- **Description**: Provide tips for maintaining motivation and overcoming writer's block.
- **Reasoning**: Addressing common challenges like writer's block is crucial for sustaining progress and ensuring authors remain engaged with their writing.
- **Success criteria**: Include practical strategies, such as setting small goals, taking breaks, and using prompts to reignite creativity.

*Subtask 4*:
- **Description**: Advise on setting a writing schedule and establishing a conducive writing environment.
- **Reasoning**: A structured writing schedule and a supportive environment are essential for productivity and focus during the writing process.
- **Success criteria**: Offer specific recommendations for daily writing routines and tips for creating a distraction-free workspace.

*Subtask 5*:
- **Description**: Suggest resources for further learning about writing techniques and publishing options.
- **Reasoning**: Providing additional resources empowers authors to deepen their knowledge and explore various publishing avenues.
- **Success criteria**: List reputable books, websites, and courses that cover writing skills and the publishing process, ensuring they are accessible and relevant to aspiring authors.

Example 2:

>>> INPUT PROMPT: 
write a python script to compute and plot the fibonacci spiral
>>> ADVANCED PROMPT: 
As a programming expert, please create a Python script that computes and plots the Fibonacci spiral.

Requirements:
- Use the Fibonacci sequence to generate the necessary points for the spiral.
- Utilize libraries such as Matplotlib for plotting and NumPy for numerical calculations.
- Include comments explaining each step of the code.
- Ensure the script is modular, allowing for easy adjustments to the number of Fibonacci terms used in the spiral.

Provide the implementation with:
- Function to compute Fibonacci numbers up to a specified term.
- Function to plot the Fibonacci spiral using the computed points.
- Example usage demonstrating the script in action, including a plot display.

The Fibonacci spiral should start with the first few Fibonacci numbers and visually represent the growth of the spiral based on these values.

##REFERENCE SUGGESTIONS##
- Matplotlib Documentation
Purpose: Provides details on plotting functions and customization options
Integration: Reference for creating and customizing plots in the script
- Fibonacci Sequence Article
Purpose: Offers insights into the mathematical properties and applications of the Fibonacci sequence
Integration: Use as a reference for understanding the sequence's generation and its relation to the spiral
- Python Programming Guide
Purpose: Serves as a comprehensive resource for Python syntax and libraries
Integration: Reference for general Python programming practices and functions used in the script

##THOUGHT PROCESS##
*Subtask 1*:
- **Description**: Create a function to compute Fibonacci numbers up to a specified term.
- **Reasoning**: This function is essential for generating the sequence of Fibonacci numbers, which will be used to determine the points for the spiral.
- **Success criteria**: The function should return a list of Fibonacci numbers up to the specified term, with correct values (e.g., for n=5, it should return [0, 1, 1, 2, 3]).

*Subtask 2*:
- **Description**: Implement a function to plot the Fibonacci spiral using the computed points.
- **Reasoning**: Plotting the spiral visually represents the growth of the Fibonacci sequence, making it easier to understand the relationship between the numbers and the spiral shape.
- **Success criteria**: The function should create a plot that accurately represents the Fibonacci spiral, with appropriate axes and labels, and should display the plot correctly.

*Subtask 3*:
- **Description**: Include comments explaining each step of the code.
- **Reasoning**: Comments enhance code readability and maintainability, allowing others (or the future self) to understand the logic and flow of the script.
- **Success criteria**: The code should have clear, concise comments that explain the purpose of each function and key steps within the functions.

*Subtask 4*:
- **Description**: Ensure the script is modular, allowing for easy adjustments to the number of Fibonacci terms used in the spiral.
- **Reasoning**: Modularity allows users to easily modify the number of terms without altering the core logic of the script, enhancing usability and flexibility.
- **Success criteria**: The script should allow the user to specify the number of Fibonacci terms as an input parameter, and the plot should update accordingly.

*Subtask 5*:
- **Description**: Provide example usage demonstrating the script in action, including a plot display.
- **Reasoning**: Example usage helps users understand how to implement and run the script, showcasing its functionality and output.
- **Success criteria**: The example should include a clear demonstration of how to call the functions, specify the number of terms, and display the resulting plot, with expected output shown.

Conclusion

In the end, we achieved very promising results. Of course, there is still a lot of room for improvement and further optimization, but most importantly, it was a fun project to work on. I’d love to hear your thoughts and ideas, so feel free to share them in the comments below!

GitHub repository: Link

Hugging Face Space: Link

Let’s connect: linkedin.com/in/adambenkhalifa

Join thousands of data leaders on the AI newsletter. Join over 80,000 subscribers and keep up to date with the latest developments in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming aΒ sponsor.

Published via Towards AI

Feedback ↓