Recently, Professor Andrew Ng of Stanford University open-sourced an AI agent for machine translation, which employs a reflective workflow for translation process. This project serve as an example of machine translation utilizing the reflective agent workflow. The primary steps of the agent are as follow:
- Initial translation, where a large model (LLM) is utilized to translate text from the source language to the target language.
- Reflection, in which the large model identifies deficiencies in the translation and proposes constructive improvement suggestions.
- Revision of the translation, where the large model retranslates the text based on the suggestions derived from the reflection process.
The reflective workflow employed in this project enables the model to identify its own deficiencies and implement targeted revisions, constituting a typical multi-agent collaborative working mechanism. This is also an area in which agentUniverse has been actively engaged, prompting me to contemplate the migration of Andrew Ng's translation agent to agentUniverse framework.
This case is based on the Qianwen large model. Prior to use, you need to configure the DASHSCOPE_API_KEY
in the environment variables.
During the translation process, the priority is to ascertain whether the model's length surpasses the maximum number of tokens it can accommodate. For instances where the length exceeds the limit, the text is initially segmented, followed by the translation of each segment. However, the entire translation process adheres to the initial translation -> reflection -> revision workflow.
Implementing this translation in agentUniverse involves the following steps:
-
Define prompts related to translation, with three for short text and three for long text. Relevant files include:
-
Define three agents
- Short Text Translation Work Agent
- Short Text Translation Reflection Agent
- Short Text Translation Improvement Agent
These agents switch their prompts based on whether the task involves translating long or short texts. The specific logic for this switching mechanism is detailed in the agent file.
-
Define the collaborative work process of the three agents The collaborative process is illustrated in the earlier-mentioned flowchart of multi-agent collaboration.
For a deeper dive into the processes, refer to the detailed code file.
The configuration file for the collaborative agents.
Translation Of Long Text
Translation Of Short Text
We can see that using agentUniverse maintains consistency with the results of the orginal translation_agent project, which hasa been successfully replicated. agentUniverse Results:
translation_agent Results:
In reference to Professor Andrew Ng's code, when managing segmented translations, to ensure the coherence of the translation, each segment is translated with its corresponding context. However, incorporating all translation content into the context within his code can undermine the original intent of segmentation, and in certain cases, it can result in exceeding the model's taken capacity. I have raised a related issue on the corresponding repository address: Issue Link## Implementation in agentUniverse.