跟 Claude 学习提示词的编写,代理 AI 系统的模式学习和实践

更新日期: 2025-06-29 阅读次数: 42 字数: 773 分类: 提示词

在 GitHub 上发现了一个提示词模版库

Crafting Effective Prompts for Agentic AI Systems: Patterns and Practices

https://github.com/dontriskit/awesome-ai-system-prompts

里面收录有 claude 等代码大模型的提示词。

At the heart of every effective agentic Artificial Intelligence (AI) lies its system prompt. More than just initial instructions, the system prompt serves as the foundational blueprint, the operational manual, or even the "constitution" guiding the AI's behavior, capabilities, limitations, and persona. A well-crafted system prompt is critical for ensuring the agent acts reliably, safely, and effectively towards the user's goals.

每个有效的代理 AI 的核心在于其系统提示符。系统提示不仅仅是初始指令,还是指导 AI 行为、能力、限制和角色的基础蓝图、作手册,甚至是“宪法”。精心设计的系统提示对于确保代理可靠、安全和有效地实现用户目标至关重要。

一些摘录

我看了一下 claude 相关的提示词,发现很有意思。周六晚上,边看老电影,边摘录了一些有趣的提示内容。

https://github.com/dontriskit/awesome-ai-system-prompts/blob/main/Claude/Claude-2025-05-06.txt

- Images from the web are not allowed, but you can use placeholder images by specifying the width and height like so `<img src="/api/placeholder/400/320" alt="placeholder" />`
- The only place external scripts can be imported from is https://cdnjs.cloudflare.com

Use only Tailwind's core utility classes for styling. THIS IS VERY IMPORTANT. We don't have access to a Tailwind compiler, so we're limited to the pre-defined classes in Tailwind's base stylesheet.

The `window.fs.readFile` API works similarly to the Node.js fs/promises readFile function. It accepts a filepath and returns the data as a uint8Array by default. You can optionally provide an options object with an encoding param (e.g. `window.fs.readFile($your_filepath, { encoding: 'utf8'})`) to receive a utf8 encoded string response instead.

- Use web_search to answer the user's question ONLY when necessary and when Claude does not know the answer - for very recent info from the internet, real-time data like market data, news, weather, current API docs, people Claude does not know, or when the answer changes on a weekly or monthly basis.

Claude MUST not create search queries for sources that promote hate speech, racism, violence, or discrimination.

<example>
<user>what's the population of tokyo?</user>
<response>
Tokyo has about 14 million people in the prefecture, or 37-38 million in the greater metropolitan area - the world's largest metropolis!
Would you like me to search for the latest official statistics?
</response>
<rationale>
Facts like population change slowly (annually at most), so Claude provides known information first and then offers to search, rather than immediately searching for "current" data.
</rationale>
</example>

完善我的提示词模版

怪不得 claude 4 写出的前端界面要比 gpt4.1 漂亮很多。例如,用 claude 写的按钮,总是会带上图标,而 gpt 4.1 就没有。估计也是增加了相应的提示词。

所以,为了让 gpt 4.1 也能写出类似 claude 4一样漂亮的界面。我在提示词模版中,也增加了对应的描述。例如:

  • 按钮的文字描述前,加上相关的 emoji 图标
  • 样式采用 bootstrap 等等

这个提示词模板,我在每个项目中都保存了一份,根据不同项目类型,和代码风格,都有不同的提示词模版。 把提示词模板保存到项目中的好处是:

  • 方便 AI 理解项目的代码风格
  • 重复利用 github copilot 的无限 gpt4.1 的自动补全功能,很多时候,能主动帮我优化现有的提示词内容

微信关注我哦 👍

大象工具微信公众号

我是来自山东烟台的一名开发者,有感兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式