The Prompt Tool is the core component for constructing language model inputs (Prompts).
Each Prompt Tool is defined by the @app.prompt decorator, and its main responsibilities are:
Based on the input content (such as questions, retrieved passages, etc.), load the corresponding template file and generate a standardized PromptMessage,
so that it can be directly passed to the Large Language Model (LLM) for generation or reasoning.
Please save your prompt template as a file ending with .jinja, for example:
prompt/qa_rag_boxed.jinja
Copy
Please answer the following question based on the given documents.Think step by step.Provide your final answer in the format \boxed{YOUR_ANSWER}.Documents:{{documents}}Question: {{question}}
In some complex Pipelines, the model often needs to perform different tasks at different stages — for example, first generating sub-questions, and then generating the final answer based on new retrieval results.
In this case, multiple Prompt Tools need to be configured in the same Pipeline, each responsible for different prompt construction logic.
If you want to load different templates for different tasks, you need to specify independent template field names for each Prompt Tool during registration:
servers/prompt/src/prompt.py
Copy
@app.prompt(output="q_ls,ret_psg,template->prompt_ls")def qa_rag_boxed( q_ls: List[str], ret_psg: List[str | Any], template: str | Path) -> list[PromptMessage]: template: Template = load_prompt_template(template) ret = [] for q, psg in zip(q_ls, ret_psg): passage_text = "\n".join(psg) p = template.render(question=q, documents=passage_text) ret.append(p) return ret@app.prompt(output="q_ls,ret_psg,gen_subq_template->prompt_ls")def gen_subq( q_ls: List[str], ret_psg: List[str | Any], template: str | Path,) -> List[PromptMessage]: template: Template = load_prompt_template(template) all_prompts = [] for q, psg in zip(q_ls, ret_psg): passage_text = "\n".join(psg) p = template.render(question=q, documents=passage_text) all_prompts.append(p) return all_prompts
Subsequently, add the corresponding template field in servers/prompt/parameter.yaml:
Please ensure this modification is completed before executing the build command.
servers/prompt/parameter.yaml
Copy
# servers/prompt/parameter.yaml# QAtemplate: prompt/qa_boxed.jinja# RankCoTkr_template: prompt/RankCoT_knowledge_refinement.jinjaqa_template: prompt/RankCoT_question_answering.jinja# Search-R1search_r1_gen_template: prompt/search_r1_append.jinja# R1-Searcherr1_searcher_gen_template: prompt/r1_searcher_append.jinja# For other prompts, please add parameters here as needed# Take webnote as an example:webnote_gen_plan_template: prompt/webnote_gen_plan.jinjawebnote_init_page_template: prompt/webnote_init_page.jinjawebnote_gen_subq_template: prompt/webnote_gen_subq.jinjawebnote_fill_page_template: prompt/webnote_fill_page.jinjawebnote_gen_answer_template: prompt/webnote_gen_answer.jinjagen_subq_template: prompt/gen_subq.jinja
Run the following command to compile the Pipeline:
Copy
ultrarag build rag_loop.yaml
The system will automatically register the new field in the generated parameter file: