Files
nexus/wiki/concepts/变量注入.md

31 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "变量注入"
type: concept
tags: [prompt-engineering, ai-tools]
date: 2026-04-16
---
## Definition
变量注入Variable Injection是在提示词模板中插入动态占位符`{{variable_name}}`),运行时替换为具体内容的技术机制,实现一次模板生成、多次自定义使用。
## Core Properties
- 符号形式:`{{topic}}``{input}``$variable` 等多种约定
- 目的:提示词模板复用,避免为每项任务重写提示词
- 上下文注入:将具体任务内容注入模板,保持模板结构稳定
## Usage Patterns
1. 模板定义:固定结构 + 变量槽位
2. 运行时填充:用户或系统代入实际内容
3. 链式传递:变量输出作为下游步骤的输入
4. 类型约束:部分系统支持变量类型声明(字符串/列表/数字)
## Examples
- [[Never-write-another-prompt]]:工具支持在生成提示词中使用变量实现定制化
- [[Nano Banana结构化提示词框架]]9 层结构中可嵌入变量实现多场景复用
- [[Agent Skill 设计模式]]Generator 模式通过填空流程强制一致输出,变量是关键机制
## Related Concepts
- [[提示词库]]:变量注入是提示词库模板的核心技术基础
- [[Prompt工程]]:变量注入是高级 Prompt 工程的常用技术
- [[Generator]]Agent Skill 模式):通过填空流程实现强制一致输出