Nacos 3.1.1 and later provides prompt management with centralized storage, version control, multi-environment isolation, and dynamic updates for end-to-end prompt lifecycle management. When a Nacos instance is hosted by MSE, you can configure and manage prompts in the MSE console to improve development collaboration and production stability.
Prerequisites
-
You have activated the MSE service.
-
You have created an instance and upgraded the Nacos engine to
3.1.1.0or later. -
You have created a namespace.
Create a prompt
-
Log on to the MSE microservices registry console and select a Region in the top menu bar.
-
In the navigation pane on the left, choose Microservices Registry > Instances.
-
On the Instances page, click the name of the target instance.
-
In the navigation pane on the left, choose Prompt Management. In the upper-left corner of the page, select a Namespace, and then click Create Prompt.
-
On the Create Prompt page, configure the following parameters and click OK.
-
Prompt name: The name cannot be changed after creation.
-
Version: The version number of the prompt. It must follow the semantic versioning specification (major.minor.patch), for example, 1.0.0.
-
Description: A brief description of the prompt's purpose and use cases.
-
Prompt template: The content of the prompt. You can define replaceable parameters in the format
{{parameter_name}}.
-
Delete a prompt
-
Log on to the MSE microservices registry console. In the top menu bar, select a Region.
-
In the navigation pane on the left, choose Microservices Registry > Instances.
-
On the Instances page, click the name of the target instance.
-
In the navigation pane on the left, choose Prompt Management. In the upper-left corner of the page, select a Namespace. Find the target prompt and click Delete in the Actions column.
View prompt details
-
Log on to the MSE microservices registry console and select a Region in the top menu bar.
-
In the navigation pane on the left, choose Microservices Registry > Instances.
-
On the Instances page, click the name of the target instance.
-
In the navigation pane on the left, click Prompt Management, and in the upper-left corner of the page, select a Namespace.
-
The prompt list displays all prompts in the selected namespace, including the name, published version, and description.
-
-
Click a prompt name to view its details.
-
The prompt details page shows the version number, commit message, prompt template, and parsed parameters for the current version.
-
Use the drop-down list to the right of the prompt name to view the version history. Click a version number to view its details.
-
Edit a prompt
-
Log on to the MSE microservices registry console and select a Region in the top menu bar.
-
In the navigation pane on the left, choose Microservices Registry > Instances.
-
On the Instances page, click the name of the target instance.
-
In the navigation pane on the left, choose Prompt Management. In the upper-left corner, select a Namespace. Find the target prompt and click Edit in the Actions column.
-
In the Edit prompt panel, modify the prompt content.
-
Basic information: Modify the prompt template. The Parameter preview section shows parameter changes before and after your edits. MSE Nacos provides sample templates as a starting point.
-
Version information: Enter a new version number (must be greater than the latest version) and a commit message describing the changes.
-
-
Go to the prompt list page and click the edit icon in the description column to modify the prompt description.
Published versions cannot be modified. To make changes, publish a new version. By default, version history is retained for 30 days.
Optimize a prompt
MSE Nacos includes a built-in AI optimization engine that analyzes and improves prompt quality by clarifying ambiguous wording, refining logical structure, adjusting writing style, and adding security constraints and boundary conditions.
-
Log on to the MSE microservices registry console and select a Region in the top menu bar.
-
In the navigation pane on the left, choose Microservices Registry > Instances.
-
On the Instances page, click the name of the target instance.
-
In the navigation pane on the left, click Prompt Management, and in the upper-left corner of the page, select a Namespace.
-
Click a prompt name to go to the prompt details page.
-
Click the Optimize Prompt button, enter your optimization requirements, and click Optimize.
-
After a short wait, the engine returns the optimized content. You can choose whether to replace the original content.
-
After replacing the content, click Publish New Version in the upper-right corner to publish the optimized prompt.
Debug a prompt
MSE Nacos provides prompt debugging for quick validation and iteration. Enter a question in the console and view the AI response in real time without deploying your application. Adjust template variables and observe how outputs change to find the best parameter combination.
-
Log on to the MSE microservices registry console and select a Region in the top menu bar.
-
In the navigation pane on the left, choose Microservices Registry > Instances.
-
On the Instances page, click the name of the target instance.
-
In the navigation pane on the left, click Prompt Management, and in the upper-left corner of the page, select a Namespace.
-
Click a prompt name to go to the prompt details page.
-
Use the Debug prompt pane on the right to test your prompt:
-
Enter the user input and the corresponding values for the template parameters.
-
Select the model for debugging.
-
Adjust the model parameters as needed.
-
Click Generate response in the upper-right corner.
-
The Model response section displays the model's response.
-
Search for a prompt
-
Log on to the MSE microservices registry console and select a Region in the top menu bar.
-
In the navigation pane on the left, choose Microservices Registry > Instances.
-
On the Instances page, click the name of the target instance.
-
In the navigation pane on the left, choose Prompt Management. In the upper-left corner of the page, select a Namespace.
-
In the search box above the prompt list, enter a prompt name and click the
search icon or press Enter. Fuzzy search is supported.
Query and subscribe to prompts with the Nacos client
Python
Install dependency
pip install nacos-sdk-python
Client configuration
from v2.nacos import NacosNamingService, NacosConfigService, NacosAIService, ClientConfigBuilder, GRPCConfig, \
Instance, SubscribeServiceParam, RegisterInstanceParam, DeregisterInstanceParam, \
BatchRegisterInstanceParam, GetServiceParam, ListServiceParam, ListInstanceParam, ConfigParam
client_config = (ClientConfigBuilder()
.access_key(os.getenv('NACOS_ACCESS_KEY'))
.secret_key(os.getenv('NACOS_SECRET_KEY'))
.server_address(os.getenv('NACOS_SERVER_ADDR', 'localhost:8848'))
.log_level('INFO')
.grpc_config(GRPCConfig(grpc_timeout=5000))
.build())
Query and subscribe to a prompt
config_client = await NacosConfigService.create_config_service(client_config)
# Query the prompt
prompt = await config_client.get_config(ConfigParam(
data_id=f"{promptKey}.json",
group="nacos-ai-prompt"
))
# Subscribe to the prompt
async def config_listener(tenant, data_id, group, prompt):
print("listen, tenant:{} data_id:{} group:{} prompt:{}".format(tenant, data_id, group, prompt))
await config_client.add_listener(f"{promptKey}.json", "nacos-ai-prompt", config_listener)
# Prompt format
# {
# "promptKey": "assistant",
# "version": "1.0.1",
# "template": "You are a professional {{language}} code generation assistant. Generate {{type}} code based on user requirements. Requirements:\n1. Code style: {{style}}\n2. Comment language: {{comment_lang}}\n3. Complexity: {{complexity}}\n",
# "commitMsg": "This is an initial version"
# }
Java
Add dependency
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
<version>${version}</version>
</dependency>
Client configuration
String serverAddr = "localhost:8848";
ConfigService configService = NacosFactory.createConfigService(serverAddr);
Query and subscribe to a prompt
// Query the prompt
String prompt = configService.getConfig("{promptKey}.json", "nacos-ai-prompt", 5000);
// Subscribe to the prompt
configService.addListener("{promptKey}.json", "nacos-ai-prompt", new Listener() {
@Override
public void receiveConfigInfo(String prompt) {
System.out.println("receive prompt:" + prompt);
}
@Override
public Executor getExecutor() {
return null;
}
});