Prerequisites
Before proceeding, ensure you have:- AgentScope v1.0.14 or higher
- A DashScope API key (or another supported provider)
Refine Workflow Function
Continuing from Overview, assume you have a task dataset and judge function ready. Now, refine your workflow function for prompt tuning:The workflow function for prompt tuning accepts
system_prompt (a str) instead of model. The system_prompt is optimized iteratively during the tuning process.Configuration & Tuning
After refining the workflow function, set up the tuning configuration and start the tuning process. Key configurations include:-
DatasetConfig: Specifies the task dataset for tuning.path: The path to the dataset, which can be a local path or a Hugging Face dataset.split: The split to use for tuning (e.g.,"train","test").name: (Optional) The subset name for Hugging Face datasets with multiple subsets.
-
PromptTuneConfig: Configures the optimization process.lm_model_name: The model name for the prompt proposer (teacher model). Default is"dashscope/qwen-plus".optimization_level: Optimization intensity —"light","medium", or"heavy". Default is"light".eval_display_progress: Whether to display progress during evaluation. Default isTrue.eval_display_table: Number of table rows to display during evaluation. Default is5.eval_num_threads: Number of threads for parallel evaluation. Default is16.compare_performance: Whether to compare baseline vs. optimized performance. Default isTrue.
main.py) and run it:
Output
The following example selects a subset from GSM8K and optimizes a ReAct agent on it. The results include the optimized prompt and its evaluation score:A well-optimized prompt improved task accuracy from 92.67 to 96.88 — a gain of +4.21 points — with no changes to model weights.