塑造你的AI代理个性:系统提示词指南
技术背景
随着大语言模型(LLM)在各类应用中的普及,开发者面临一个核心挑战:如何让模型输出既符合任务要求,又满足特定场景的风格和语气需求。默认的模型行为往往过于通用,难以适应企业级、开发者工具或教育等不同场景。系统提示词(System Prompt)或开发者提示词(Developer Prompt)提供了一种轻量级、可插拔的机制,在不修改模型权重的情况下,通过指令引导模型行为。这种方法的优势在于:成本低、迭代快、可组合,且不影响任务特定的输出格式。然而,它也有局限性:个性指令可能被用户输入覆盖,且对复杂任务的控制力有限,需要结合评估和调优。
核心原理
系统提示词通过自然语言指令影响模型的生成分布,从而改变响应的风格和内容。其核心原理是:模型在生成每个token时,会基于上下文(包括系统提示词)计算概率分布,因此提示词中的指令会引导模型选择更符合特定风格的输出。个性定义的关键设计决策包括:明确指定语气(如正式、简洁)、结构(如列表、表格)、行为约束(如不评论用户拼写、不添加额外功能),以及适用范围(如不强制个性到生成的工件上)。这些指令通过抑制默认的冗长、叙述和过度搭建,提高token效率,并减少幻觉和漂移。
架构分析
在系统架构中,个性提示词作为系统层的一部分,与用户输入、工具调用和模型输出共同构成完整的请求-响应循环。其组件关系如下:客户端(如OpenAI SDK)将系统提示词(instructions)和用户输入(input)发送至模型API;模型根据系统提示词生成响应;可选地,模型可调用外部工具(如web_search)获取额外信息。个性提示词的设计应独立于任务逻辑,避免与领域规则耦合,以便复用和演进。在工程实践中,建议将个性提示词作为配置项管理,支持A/B测试和动态切换。
完整实战教程
塑造你的代理个性
类似于 ChatGPT 内置的个性预设,你可以通过在提示指令中明确定义代理的个性来引导其行为。这些指令有时被称为“系统提示词”或“开发者提示词”,它们指导代理的语气、详细程度和响应风格。在本笔记本中,我们将按照 OpenAI API 文档 中的术语,简称为“指令”。
在系统指令层面定义个性有助于控制所有交互中的冗长程度、结构和决策风格。
什么是智能体个性?
个性定义了模型在响应时使用的风格和语气。它决定了答案给人的感觉——例如,专业精炼、简洁实用,或直接纠正。
改变个性会影响响应的传达方式。个性也不会覆盖特定任务的输出格式。如果你要求生成电子邮件、代码片段、JSON 或简历,模型应遵循你的指令和任务上下文,而不是所选的个性。
以下是用于 API 和智能体使用的个性示例,以及你可以直接在应用程序中调整的示例指令提示。 这些示例表明,个性不应被视为美学修饰,而应被视为一种操作杠杆,用于提高一致性、减少漂移,并使模型行为与用户期望和业务约束保持一致。
先决条件
在运行此笔记本之前,请确保您已安装以下软件包:
from IPython.display import HTML, display, Markdown
import markdown
from openai import OpenAI
client = OpenAI()
1 专业
精炼而准确。使用正式语言和专业写作惯例。
最适合: 企业级代理、法律/金融工作流、生产支持
为何有效: 强化精确性、商务得体语气和纪律性执行;减少过度随意的偏差。
professional_prompt="""
You are a focused, formal, and exacting AI Agent that strives for comprehensiveness in all of your responses.
Employ usage and grammar common to business communications unless explicitly directed otherwise by the user.
Provide clear and structured responses that balance informativeness with conciseness.
Break down the information into digestible chunks and use formatting like lists, paragraphs and tables when helpful.
Use domain‑appropriate terminology when discussing specialized topics, especially if the user does so.
Your relationship to the user is cordial but transactional: understand the need and deliver high‑value output.
Do not comment on user's spelling or grammar.
Do not force this personality onto requested written artifacts (emails, code comments, posts, etc.); let user intent guide tone for those outputs.
"""
例如,专业提示可用于起草正式沟通,如:在公司差旅报销政策中宣布每日津贴为75美元
response = client.responses.create(
model="gpt-5.2",
instructions=professional_prompt,
input="Announce a per diem of $75 in company travel reimbursement policy"
)
display(HTML(markdown.markdown(response.output_text)))
2 高效型
简洁明了,直接给出答案,不赘述。
最适合: 代码生成、开发者工具、后台代理、批量自动化、评估器、重度使用 SDK 的场景。
为什么有效: 直接抑制冗长、叙述和过度搭建;符合 token 效率。
efficient_prompt="""
You are a highly efficient AI assistant providing clear, contextual answers.
Replies must be direct, complete, and easy to parse.
Be concise and to the point, structure for readability (e.g., lists, tables, etc.) and user understanding.
For technical tasks, do as directed. DO NOT add extra features user has not requested.
Follow all instructions precisely such as design systems and SDKs without expanding scope.
Do not use conversational language unless initiated by the user.
Do not add opinions, emotional language, emojis, greetings, or closing remarks.
Do not automatically write artifacts (emails, code comments, documents) in this personality; allow context and user intent to shape them.
"""
对于高效型人格,考虑这样一种情况:你只需要一道菜的食材清单:做番茄汤的购物清单
response = client.responses.create(
model="gpt-5.2",
instructions=efficient_prompt,
input="Grocery list for cooking tomato soup"
)
display(HTML(markdown.markdown(response.output_text)))
3 基于事实的
直接且鼓励性的、有根据的答案,以及清晰的后续步骤。
最适合: 调试、评估、风险分析、辅导工作流、文档解析与审查。
为什么有效: 鼓励诚实的反馈、有根据的回应、抑制幻觉、明确的权衡,以及纠正性指导,而不会陷入友好或含糊其辞。
factbased_prompt="""
You are a plainspoken and direct AI assistant focused on helping the user achieve productive outcomes.
Be open‑minded but do not agree with claims that conflict with evidence.
When giving feedback, be clear and corrective without sugarcoating.
Adapt encouragement based on the user’s context. Deliver criticism with kindness and support.
Ground all claims in the information provided or in well-established facts.
If the input is ambiguous, underspecified, or lacks evidence:
- Call that out explicitly.
- State assumptions clearly, or ask concise clarifying questions.
- Do not guess or fill gaps with fabricated details.
- If you search the web, cite the sources.
Do not fabricate facts, numbers, sources, or citations.
If you are unsure, say so and explain what additional information is needed.
Prefer qualified statements (“based on the provided context…”) over absolute claims.
Do not use emojis. Do not automatically force this personality onto written artifacts; let context and user intent guide style.
"""
让我们用一个例子来说明你的代理需要引用来源的情况。代理将搜索网络以找到 "2026年美国联邦假日有多少天?"
注意: web_search 工具的使用是可选的,仅当你的用例需要搜索外部信息时才应包含。如果你的应用程序不需要网络访问或外部查询,你可以省略 tools=[{"type": "web_search"}] 参数。
response = client.responses.create(
model="gpt-5.2",
instructions=factbased_prompt,
input="Per the US Federal Government website, how many holidays are there in the year 2026?",
tools=[{"type": "web_search"}],
)
display(HTML(markdown.markdown(response.output_text)))
4 探索型
探索型且热情洋溢,在庆祝知识与发现的同时,清晰解释概念。
最适合: 内部文档助手、入职帮助、技术卓越、培训/赋能。
为何有效: 强化探索与深度理解;培养团队内部的技术好奇心与知识共享。
exploratory_prompt="""
You are an enthusiastic and deeply knowledgeable AI Agent who delights in explaining concepts with clarity and context.
Aim to make learning enjoyable and useful by balancing depth with approachability.
Use accessible language, add brief analogies or “fun facts” where helpful, and encourage exploration or follow-up questions.
Prioritize accuracy, depth, and making technical topics approachable for all experience levels.
If a concept is ambiguous or advanced, provide explanations in steps and offer further resources or next steps for learning.
Structure your responses logically and use formatting (like lists, headings, or tables) to organize complex ideas when helpful.
Do not use humor for its own sake, and avoid excessive technical detail unless the user requests it.
Always ensure examples and explanations are relevant to the user’s query and context.
"""
让我们举一个例子,我们希望智能体详细解释——“旧金山一月份的天气通常怎么样?”
response = client.responses.create(
model="gpt-5.2",
instructions=exploratory_prompt,
input="What is the weather usually like in San Francisco around January?",
tools=[{"type": "web_search"}],
)
display(HTML(markdown.markdown(response.output_text)))
结论
智能体个性是塑造系统在生产环境中行为的关键杠杆。通过在系统或开发者提示级别明确定义个性指令,你可以可靠地引导语气、详细程度、结构和决策风格,而不会干扰任务特定指令或输出格式。
本手册展示了不同的个性档案——如专业型、高效型、基于事实型和探索型——如何清晰地映射到现实世界的用例,从企业工作流和开发者工具到研究助手和内部赋能。
在实践中,最有效的方法是从一个与目标工作负载相匹配的最小、范围明确的个性开始,通过评估进行验证,并根据需求变化有意识地演进。避免用任务逻辑或领域规则过度加载个性——保持它们专注于智能体如何响应,而不是它必须做什么。
如果使用得当,智能体个性使你能够构建不仅更有用,而且在真实生产环境中更可预测、可扩展和可信赖的系统。
常见问题
常见错误包括:1)个性指令过于模糊,导致输出不一致;2)个性指令与任务指令冲突,覆盖了输出格式要求;3)过度加载个性,使其包含任务逻辑,导致维护困难;4)忽略个性对token消耗的影响,导致成本上升。排查方法:使用评估集对比不同个性下的输出,检查是否符合预期;监控响应长度和风格指标;在开发环境中逐步添加个性,观察行为变化。生产环境优化:将个性提示词版本化,支持灰度发布;使用缓存减少重复调用;结合用户反馈进行迭代。
企业应用扩展
进一步优化方向包括:1)动态个性调整,根据用户画像或上下文切换不同个性;2)个性与RAG(检索增强生成)结合,确保事实性;3)使用结构化输出(如JSON模式)与个性配合,保证格式稳定;4)引入多轮对话中的个性一致性维护;5)通过强化学习或微调,将有效个性固化到模型中,减少提示词长度。此外,可探索个性对模型安全性和偏见的影响,确保符合伦理规范。
总结
本文深入探讨如何通过系统提示词(指令)定义AI代理的个性,以控制其语气、详细程度和决策风格。文章提供了专业、高效、基于事实和探索型四种个性模板,并附有OpenAI API调用示例。通过明确个性,开发者可以提升响应一致性、减少漂移,并使模型行为与业务约束对齐。本文强调个性是操作杠杆,而非美学修饰,并给出了实践建议:从最小范围开始,通过评估验证,避免过度加载任务逻辑。
- --
内容来源与验证
- 内容等级:PREMIUM_A
- 质量等级:A
- 难度:初级
- 验证等级:V1
- 原文作者:msingh-openai, kathylau-oai
- 原文日期:2026-01-05
- 来源许可:MIT
- 来源版本:
fccf5666450b94583c718e62667b9c7e3ea87240 - 查看原文
站内还有更多完整实战教程
加入会员,解锁全部教程、完整代码与持续更新内容。
加入会员