Recently, Professor Andrew Ng of Stanford University open-sourced an AI agent for machine translation—an agent that employs a reflective workflow for translation. This project showcases an example of machine translation utilizing the reflective agent workflow. The primary steps of the agent include:
- Initial translation, utilizing a large model (LLM) to translate text from the source language to the target language;
- Reflection, wherein the large model identifies deficiencies in the translation and offers constructive improvement suggestions;
- Revision of the translation, where the large model retranslates based on the suggestions derived from the reflection;
The reflective workflow employed in the project enables the model to identify its own deficiencies and implement targeted revisions, constituting a typical multi-agent collaborative working mechanism. This is also a domain in which agentUniverse has been actively engaged, prompting me to contemplate the migration of Andrew Ng's translation agent to agentUniverse.
This case is based on the Qianwen large model, and 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. Nonetheless, the entire translation process adheres to the initial translation -> reflection -> revision workflow.
Implementing this translation in aU 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 aU maintains consistency with the original translation_agent project results, successfully replicated.
aU 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 the 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 an excess of tokens beyond the model's capacity. I have raised a related issue on the corresponding repository address: Issue Link## Implementation in aU