一个人工智能代理替换提示工程师

让我们构建一个多智能体系统,自动化提示工程过程,并将简单的输入提示转化为高级提示,也就是一个高级提示生成器!

我们将看到这个解决方案背后的思想,第一次迭代,第二次迭代,以及涉及的测试、故障排除和优化。

最终,我们将拥有一个强大的提示增强工具,我会在本文末尾分享这个项目的Github存储库和Hugging Face Space的链接,以便快速演示代理。

Prompt Engineers right now

目录

  • 这个想法
  • 建立和构建解决方案
  • 测试和故障排除
  • 一个稳定且优化的解决方案
  • 结论

这个想法

在探索各种增强提示方法后,一种想法突然出现并被认为特别直观:利用大型语言模型(LLM),并利用提示工程策略和技术来引导它,以自动化和概括化这一过程。

以下是所遵循的步骤:

  • 使用OpenAI的提示策略来定义一组规则,以确保创建一个先进的提示。
  • 定义多个代理,根据输入提示和定义的规则生成结果。
  • 创建一个管道,以定义多个代理之间的互动流程

这里是一个流程图,让您更好地可视化这些步骤:

The described solution’s flowchart

建模并构建解决方案

在我们定义规则后,我们对流程进行建模。我们将这些规则分组到特定的组件中,并为每个组件分配一个代理人。这意味着每个代理人都将根据给定的规则和输入使用预定义的提示进行指导生成信息。

这里有一个流程图,以更好地可视化这一步骤:

The pipeline’s flowchart

现在,剩下的就是编写所有代码并为LLM添加访问权限。

我们将使用OpenAI的GPT-4o-mini作为LLM,因为它非常强大、稳定且具有成本效益。但是您可以稍后调整代码以与任何LLM API一起使用。

测试和故障排除

结果令人鼓舞,我们正在朝着正确方向前进。我们经常可以达到高质量的高级提示,然而也存在多个问题。

性能不稳定,我们经常遇到不相关的结果,比如来自提示的生成输出,信息冗余和幻觉。

因此,我们需要优化我们的解决方案。

一个稳定且优化的解决方案.

上述问题的识别原因包括管道中某些组件的重叠、代理提示的不足发展以及内部限制的缺乏。

因此,我们重新审视并更新了我们的流程,通过减少组件数量并为代理提供强大、详细的系统提示,以应对每个组件。

这是更新后的管道流程图:

The updated pipeline’s flowchart

通过这次更新,我们确保了一个稳定且强大的系统,解决了所有先前存在的问题,同时降低了复杂度和生成成本。

以下是一些示例来评估解决方案:(您也可以检查Github存储库或HF Space并尝试自己)

这是一个例子。

>>> 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.

例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.

结论

最终,我们取得了非常有希望的结果。当然,还有很多改进和进一步优化的空间,但最重要的是,这是一个有趣的项目。我很想听到你的想法和建议,所以请在下面的评论中分享吧!

Github 代码库: 链接

拥抱面空间: 链接

让我们保持联系: linkedin.com/in/adambenkhalifa

2024-10-25 04:10:58 AI中文站翻译自原文