目前Agent的必备几大要素:1 LLM / 2 Prompt / 3 Workflow / 4 Memory / 5 Tool。
LLM,Prompt和Workflow决定了Agent性能的上限,故如何设计Agent Prompt以及WorkFlow成为了重中之重。
Agent的倡导者吴恩达最近在Github中开源了翻译Agent——TranslationAgent,该Agent重新设计了Translation Prompt和WorkFlow(没有Memory和Tool的设计)可以实现短文本和长文本的在不同语言之间针对某国家和领域进行偏好翻译。
1 Agent Workflow
TranslationAgent的WorkFlow分为短文本WorkFlow和长文本WorkFlow。
短文本WorkFlow:
- 1 translation initial
- 2 translation reflection
- 3 translation improvement
长文本WorkFlow:
- 1 multi chunk translation initial
- 2 multi chunk translation reflection
- 3 multi chunk translation improvement
2 Agent Prompt
2.1 translation initial
"""This is an {source_language} to {target_language} translation, please provide the {target_language}
for this text. Do not provide any explanations or text apart from the translation.
{source_language}: {text}
{target_language}:"""
该Prompt涉及源语言和目标语言,以及需要翻译的源文本。
2.2 translation reflection
"""You task is to carefully read a source text and a translation from {source_language} to {target_language}.,
and then give constructive criticism and helpful suggestions to improve the translation. You final style an tone of the translation
should match the style of {target_language} and colloquially spoken in {country} and field in {field}.
The source text and initial translation delimited by XLM tags <SOURCE_TEXT></SOURCE_TEXT> and <TRANSLATION></TRANSLATION>, are as follows:
<SOURCE_TEXT>
{text}
</SOURCE_TEXT>
<TRANSLATION>
{translation}
</TRANSLATION>
When writing suggestions, pay attention to whether there are ways to improve the translation's \n\
(i) accuracy (by correcting errors of addition, mistranslation, omission, or untranslated text),\n\
(ii) fluency (by applying {target_language} grammar, spelling and punctuation rules, and ensuring there are no unnecessary repetitions),\n\
(iii) style (by ensuring the translations reflect the style of the source text and take into account any cultural context),\n\
(iv) terminology (by ensuring terminology use is consistent and reflects the source text domain; and by only ensuring you use equivalent idioms {target_language}).\n\
Write a list of specific, helpful and constructive suggestions for improving the translation.
Each suggestion should address one specific part of the translation.
Output only the suggestions and nothing else."""
该Prompt涉及源语言和目标语言,以及需要翻译的源文本,初始翻译版本。
2.3 translation improvement
"""Your task is to carefully read, then edit, a translation from {source_language} to {target_language}, taking into
account a list of expert suggestions and constructive criticisms.
The source text, the initial translation, and the expert linguist suggestions are delimited by XML tags <SOURCE_TEXT></SOURCE_TEXT>, <TRANSLATION></TRANSLATION> and <EXPERT_SUGGESTIONS></EXPERT_SUGGESTIONS> \
as follows:
<SOURCE_TEXT>
{text}
</SOURCE_TEXT>
<TRANSLATION>
{translation}
</TRANSLATION>
<EXPERT_SUGGESTIONS>
{reflection}
</EXPERT_SUGGESTIONS>
Please take into account the expert suggestions when editing the translation. Edit the translation by ensuring:
(i) accuracy (by correcting errors of addition, mistranslation, omission, or untranslated text),
(ii) fluency (by applying {source_language} grammar, spelling and punctuation rules and ensuring there are no unnecessary repetitions), \
(iii) style (by ensuring the translations reflect the style of the source text)
(iv) terminology (inappropriate for context, inconsistent use), or
(v) other errors.
Output only the new translation and nothing else."""
该Prompt涉及源语言和目标语言,以及需要翻译的源文本,初始翻译版本,初始翻译建议版本。
2.4 multi chunk translation initial
"""Your task is to provide a professional translation from {source_language} to {target_language} of PART of a text.
The source text is below, delimited by XML tags <SOURCE_TEXT> and </SOURCE_TEXT>. Translate only the part within the source text
delimited by <TRANSLATE_THIS> and </TRANSLATE_THIS>. You can use the rest of the source text as context, but do not translate any
of the other text. Do not output anything other than the translation of the indicated part of the text.
<SOURCE_TEXT>
{tagged_text}
</SOURCE_TEXT>
To reiterate, you should translate only this part of the text, shown here again between <TRANSLATE_THIS> and </TRANSLATE_THIS>:
<TRANSLATE_THIS>
{chunk_to_translate}
</TRANSLATE_THIS>
Output only the translation of the portion you are asked to translate, and nothing else."""
该Prompt涉及源语言和目标语言,以及需要翻译的chunk源文本。
2.5 multi chunk translation reflection
"""Your task is to carefully read a source text and part of a translation of that text from {source_language} to {target_language}, \
and then give constructive criticism and helpful suggestions for improving the translation.
The final style and tone of the translation should match the style of {target_language} colloquially spoken in {country} and field in {field}.
The source text is below, delimited by XML tags <SOURCE_TEXT> and </SOURCE_TEXT>, and the part that has been translated
is delimited by <TRANSLATE_THIS> and </TRANSLATE_THIS> within the source text. You can use the rest of the source text
as context for critiquing the translated part.
<SOURCE_TEXT>
{tagged_text}
</SOURCE_TEXT>
To reiterate, only part of the text is being translated, shown here again between <TRANSLATE_THIS> and </TRANSLATE_THIS>:
<TRANSLATE_THIS>
{chunk_to_translate}
</TRANSLATE_THIS>
The translation of the indicated part, delimited below by <TRANSLATION> and </TRANSLATION>, is as follows:
<TRANSLATION>
{translation_chunk}
</TRANSLATION>
When writing suggestions, pay attention to whether there are ways to improve the translation's:\n\
(i) accuracy (by correcting errors of addition, mistranslation, omission, or untranslated text),\n\
(ii) fluency (by applying {target_language} grammar, spelling and punctuation rules, and ensuring there are no unnecessary repetitions),\n\
(iii) style (by ensuring the translations reflect the style of the source text and take into account any cultural context),\n\
(iv) terminology (by ensuring terminology use is consistent and reflects the source text domain; and by only ensuring you use equivalent idioms {target_language}).\n\
Write a list of specific, helpful and constructive suggestions for improving the translation.
Each suggestion should address one specific part of the translation.
Output only the suggestions and nothing else."""
该Prompt涉及源语言和目标语言,以及需要翻译的chunk源文本,chunk初始翻译版本。
2.6 multi chunk translation improvement
"""Your task is to carefully read, then improve, a translation from {source_language} to {target_language}, taking into \
account a set of expert suggestions and constructive criticisms. Below, the source text, initial translation, and expert suggestions are provided.
The source text is below, delimited by XML tags and , and the part that has been translated
is delimited by and within the source text. You can use the rest of the source text
as context, but need to provide a translation only of the part indicated by and .
{tagged_text}
To reiterate, only part of the text is being translated, shown here again between and :
{chunk_to_translate}
The translation of the indicated part, delimited below by and , is as follows:
{translation_chunk}
The expert translations of the indicated part, delimited below by and , are as follows:
{reflection_chunk}
Taking into account the expert suggestions rewrite the translation to improve it, paying attention
to whether there are ways to improve the translation's
(i) accuracy (by correcting errors of addition, mistranslation, omission, or untranslated text),
(ii) fluency (by applying {target_language} grammar, spelling and punctuation rules and ensuring there are no unnecessary repetitions), \
(iii) style (by ensuring the translations reflect the style of the source text)
(iv) terminology (inappropriate for context, inconsistent use), or
(v) other errors.
Output only the new translation of the indicated part and nothing else."""
该Prompt涉及源语言和目标语言,以及需要翻译的chunk源文本,初始chunk翻译版本,初始chunk翻译建议版本。