本文介绍 Agent 提示工程技巧,包括系统提示优化、示例选择、角色扮演设计。
好的提示是 Agent 可靠性的关键。
SYSTEM_PROMPT = """你是一个专业的 {role}。
## 能力
- 熟练使用 {skills}
- 遵循 {workflow}
## 约束
- {constraints}
- 始终验证输入
## 输出格式
{output_format}
"""
EXAMPLES = """
示例 1:
用户: {input_1}
Agent: {action_1}
结果: {result_1}
示例 2:
用户: {input_2}
Agent: {action_2}
结果: {result_2}
"""
def build_prompt(task_type: str, context: dict) -> str:
base = SYSTEM_PROMPT.format(**context)
if task_type == "code":
base += CODE_SPECIFIC_INSTRUCTIONS
elif task_type == "search":
base += SEARCH_SPECIFIC_INSTRUCTIONS
return base
提示工程验证通过