The Prompt Tool is the core component used to construct inputs (prompts) for language models.
Each Prompt Tool is defined using the @app.prompt decorator.
Its main responsibility is to load the corresponding template file based on the input content (e.g., question, retrieved passages) and generate standardized PromptMessage objects that can be directly passed to the Large Language Model (LLM) for generation or inference.
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 complex Pipelines, the model may need to perform different tasks at different stages—for example, generating sub-questions first, and then producing the final answer based on new retrieval results.
In such cases, multiple Prompt Tools can be configured within the same Pipeline, each responsible for constructing prompts for a specific task.
If you want to load different templates for different tasks, specify distinct template field names when registering each Prompt Tool:
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
Then, add the corresponding template fields in servers/prompt/parameter.yaml:
Ensure you complete this modification before running 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
Build the Pipeline:
Copy
ultrarag build rag_loop.yaml
The system will automatically register the new field in the generated parameter file: