Chain Workflow
Chain Workflow pattern decomposes a complicated task into a sequence of steps. Each step takes the output of the previous step as its input, processes the input, then calls the next step with updated input. The input of the first step is the original task input. The output of the last step is the result of the task.
Implementation
This pattern consists of a management task and a sequence of subtasks. All these tasks are implemented using Task Execution pattern.
The flow chart below shows the basic steps.
Example
An example of using chain workflow is improving the quality of the content of an article. The content of an article can be improved in many ways. ChatGPT provides some suggestions about how to polish an article. We can apply one suggestion in each step to improve the content.
For demo purpose, a new article is generated using an LLM first for the given topic. Then this article is passed to a chain of three agents for improvements. Each agent focuses on a particular area for improvement. The result of the last agent is returned as the final result.
Below are the instructions of these steps.
"""
Review the Structure
- Ensure the article has a clear introduction, body, and conclusion.
- Check if ideas flow logically from one section to another.
- Ensure paragraphs are well-organized and each one has a clear purpose.
""",
"""
Improve Clarity and Conciseness
- Remove unnecessary words and redundant phrases.
- Simplify complex sentences for better readability.
- Use active voice where possible.
""",
"""
Enhance Readability
- Break long paragraphs into shorter ones.
- Use bullet points or subheadings for easier scanning.
- Vary sentence length to maintain reader interest.
"""
Below is the prompt template used by steps. There are two variables in this template:
instruction
, value from the list of instructions.article
, value from the generated article, or output of previous step.
Goal: Improve an article by following the instruction:
{instruction}
Article content:
{article}
Article returned by the last step will be the output of the task.
Reference Implementation
See this page for reference implementation and examples.