# prompttools - Doramagic AI Context Pack

> 定位：安装前体验与判断资产。它帮助宿主 AI 有一个好的开始，但不代表已经安装、执行或验证目标项目。

## 充分原则

- **充分原则，不是压缩原则**：AI Context Pack 应该充分到让宿主 AI 在开工前理解项目价值、能力边界、使用入口、风险和证据来源；它可以分层组织，但不以最短摘要为目标。
- **压缩策略**：只压缩噪声和重复内容，不压缩会影响判断和开工质量的上下文。

## 给宿主 AI 的使用方式

你正在读取 Doramagic 为 prompttools 编译的 AI Context Pack。请把它当作开工前上下文：帮助用户理解适合谁、能做什么、如何开始、哪些必须安装后验证、风险在哪里。不要声称你已经安装、运行或执行了目标项目。

## Claim 消费规则

- **事实来源**：Repo Evidence + Claim/Evidence Graph；Human Wiki 只提供显著性、术语和叙事结构。
- **事实最低状态**：`supported`
- `supported`：可以作为项目事实使用，但回答中必须引用 claim_id 和证据路径。
- `weak`：只能作为低置信度线索，必须要求用户继续核实。
- `inferred`：只能用于风险提示或待确认问题，不能包装成项目事实。
- `unverified`：不得作为事实使用，应明确说证据不足。
- `contradicted`：必须展示冲突来源，不得替用户强行选择一个版本。

## 它最适合谁

- **正在使用 Claude/Codex/Cursor/Gemini 等宿主 AI 的开发者**：README 或插件配置提到多个宿主 AI。 证据：`README.md` Claim：`clm_0002` supported 0.86

## 它能做什么

- **命令行启动或安装流程**（需要安装后验证）：项目文档中存在可执行命令，真实使用需要在本地或宿主环境中运行这些命令。 证据：`README.md` Claim：`clm_0001` supported 0.86

## 怎么开始

- `pip install prompttools` 证据：`README.md` Claim：`clm_0003` supported 0.86
- `git clone https://github.com/hegelai/prompttools.git` 证据：`README.md` Claim：`clm_0004` supported 0.86
- `pip install notebook  # If jupyter notebook has not been installed` 证据：`README.md` Claim：`clm_0005` supported 0.86

## 继续前判断卡

- **当前建议**：仅建议沙盒试装
- **为什么**：项目存在安装命令、宿主配置或本地写入线索，不建议直接进入主力环境，应先在隔离环境试装。

### 30 秒判断

- **现在怎么做**：仅建议沙盒试装
- **最小安全下一步**：先跑 Prompt Preview；若仍要安装，只在隔离环境试装
- **先别相信**：真实输出质量不能在安装前相信。
- **继续会触碰**：命令执行、本地环境或项目文件、宿主 AI 上下文

### 现在可以相信

- **适合人群线索：正在使用 Claude/Codex/Cursor/Gemini 等宿主 AI 的开发者**（supported）：有 supported claim 或项目证据支撑，但仍不等于真实安装效果。 证据：`README.md` Claim：`clm_0002` supported 0.86
- **能力存在：命令行启动或安装流程**（supported）：可以相信项目包含这类能力线索；是否适合你的具体任务仍要试用或安装后验证。 证据：`README.md` Claim：`clm_0001` supported 0.86
- **存在 Quick Start / 安装命令线索**（supported）：可以相信项目文档出现过启动或安装入口；不要因此直接在主力环境运行。 证据：`README.md` Claim：`clm_0003` supported 0.86

### 现在还不能相信

- **真实输出质量不能在安装前相信。**（unverified）：Prompt Preview 只能展示引导方式，不能证明真实项目中的结果质量。
- **宿主 AI 版本兼容性不能在安装前相信。**（unverified）：Claude、Cursor、Codex、Gemini 等宿主加载规则和版本差异必须在真实环境验证。
- **不会污染现有宿主 AI 行为，不能直接相信。**（inferred）：Skill、plugin、AGENTS/CLAUDE/GEMINI 指令可能改变宿主 AI 的默认行为。
- **可安全回滚不能默认相信。**（unverified）：除非项目明确提供卸载和恢复说明，否则必须先在隔离环境验证。
- **真实安装后是否与用户当前宿主 AI 版本兼容？**（unverified）：兼容性只能通过实际宿主环境验证。
- **项目输出质量是否满足用户具体任务？**（unverified）：安装前预览只能展示流程和边界，不能替代真实评测。
- **安装命令是否需要网络、权限或全局写入？**（unverified）：这影响企业环境和个人环境的安装风险。 证据：`README.md`

### 继续会触碰什么

- **命令执行**：包管理器、网络下载、本地插件目录、项目配置或用户主目录。 原因：运行第一条命令就可能产生环境改动；必须先判断是否值得跑。 证据：`README.md`
- **本地环境或项目文件**：安装结果、插件缓存、项目配置或本地依赖目录。 原因：安装前无法证明写入范围和回滚方式，需要隔离验证。 证据：`README.md`
- **宿主 AI 上下文**：AI Context Pack、Prompt Preview、Skill 路由、风险规则和项目事实。 原因：导入上下文会影响宿主 AI 后续判断，必须避免把未验证项包装成事实。

### 最小安全下一步

- **先跑 Prompt Preview**：用安装前交互式试用判断工作方式是否匹配，不需要授权或改环境。（适用：任何项目都适用，尤其是输出质量未知时。）
- **只在隔离目录或测试账号试装**：避免安装命令污染主力宿主 AI、真实项目或用户主目录。（适用：存在命令执行、插件配置或本地写入线索时。）
- **安装后只验证一个最小任务**：先验证加载、兼容、输出质量和回滚，再决定是否深用。（适用：准备从试用进入真实工作流时。）

### 退出方式

- **保留安装前状态**：记录原始宿主配置和项目状态，后续才能判断是否可恢复。
- **记录安装命令和写入路径**：没有明确卸载说明时，至少要知道哪些目录或配置需要手动清理。
- **如果没有回滚路径，不进入主力环境**：不可回滚是继续前阻断项，不应靠信任或运气继续。

## 哪些只能预览

- 解释项目适合谁和能做什么
- 基于项目文档演示典型对话流程
- 帮助用户判断是否值得安装或继续研究

## 哪些必须安装后验证

- 真实安装 Skill、插件或 CLI
- 执行脚本、修改本地文件或访问外部服务
- 验证真实输出质量、性能和兼容性

## 边界与风险判断卡

- **把安装前预览误认为真实运行**：用户可能高估项目已经完成的配置、权限和兼容性验证。 处理方式：明确区分 prompt_preview_can_do 与 runtime_required。 Claim：`clm_0006` inferred 0.45
- **命令执行会修改本地环境**：安装命令可能写入用户主目录、宿主插件目录或项目配置。 处理方式：先在隔离环境或测试账号中运行。 证据：`README.md` Claim：`clm_0007` supported 0.86
- **待确认**：真实安装后是否与用户当前宿主 AI 版本兼容？。原因：兼容性只能通过实际宿主环境验证。
- **待确认**：项目输出质量是否满足用户具体任务？。原因：安装前预览只能展示流程和边界，不能替代真实评测。
- **待确认**：安装命令是否需要网络、权限或全局写入？。原因：这影响企业环境和个人环境的安装风险。

## 开工前工作上下文

### 加载顺序

- 先读取 how_to_use.host_ai_instruction，建立安装前判断资产的边界。
- 读取 claim_graph_summary，确认事实来自 Claim/Evidence Graph，而不是 Human Wiki 叙事。
- 再读取 intended_users、capabilities 和 quick_start_candidates，判断用户是否匹配。
- 需要执行具体任务时，优先查 role_skill_index，再查 evidence_index。
- 遇到真实安装、文件修改、网络访问、性能或兼容性问题时，转入 risk_card 和 boundaries.runtime_required。

### 任务路由

- **命令行启动或安装流程**：先说明这是安装后验证能力，再给出安装前检查清单。 边界：必须真实安装或运行后验证。 证据：`README.md` Claim：`clm_0001` supported 0.86

### 上下文规模

- 文件总数：174
- 重要文件覆盖：40/174
- 证据索引条目：55
- 角色 / Skill 条目：6

### 证据不足时的处理

- **missing_evidence**：说明证据不足，要求用户提供目标文件、README 段落或安装后验证记录；不要补全事实。
- **out_of_scope_request**：说明该任务超出当前 AI Context Pack 证据范围，并建议用户先查看 Human Manual 或真实安装后验证。
- **runtime_request**：给出安装前检查清单和命令来源，但不要替用户执行命令或声称已执行。
- **source_conflict**：同时展示冲突来源，标记为待核实，不要强行选择一个版本。

## Prompt Recipes

### 适配判断

- 目标：判断这个项目是否适合用户当前任务。
- 预期输出：适配结论、关键理由、证据引用、安装前可预览内容、必须安装后验证内容、下一步建议。

```text
请基于 prompttools 的 AI Context Pack，先问我 3 个必要问题，然后判断它是否适合我的任务。回答必须包含：适合谁、能做什么、不能做什么、是否值得安装、证据来自哪里。所有项目事实必须引用 evidence_refs、source_paths 或 claim_id。
```

### 安装前体验

- 目标：让用户在安装前感受核心工作流，同时避免把预览包装成真实能力或营销承诺。
- 预期输出：一段带边界标签的体验剧本、安装后验证清单和谨慎建议；不含真实运行承诺或强营销表述。

```text
请把 prompttools 当作安装前体验资产，而不是已安装工具或真实运行环境。

请严格输出四段：
1. 先问我 3 个必要问题。
2. 给出一段“体验剧本”：用 [安装前可预览]、[必须安装后验证]、[证据不足] 三种标签展示它可能如何引导工作流。
3. 给出安装后验证清单：列出哪些能力只有真实安装、真实宿主加载、真实项目运行后才能确认。
4. 给出谨慎建议：只能说“值得继续研究/试装”“先补充信息后再判断”或“不建议继续”，不得替项目背书。

硬性边界：
- 不要声称已经安装、运行、执行测试、修改文件或产生真实结果。
- 不要写“自动适配”“确保通过”“完美适配”“强烈建议安装”等承诺性表达。
- 如果描述安装后的工作方式，必须使用“如果安装成功且宿主正确加载 Skill，它可能会……”这种条件句。
- 体验剧本只能写成“示例台词/假设流程”：使用“可能会询问/可能会建议/可能会展示”，不要写“已写入、已生成、已通过、正在运行、正在生成”。
- Prompt Preview 不负责给安装命令；如用户准备试装，只能提示先阅读 Quick Start 和 Risk Card，并在隔离环境验证。
- 所有项目事实必须来自 supported claim、evidence_refs 或 source_paths；inferred/unverified 只能作风险或待确认项。

```

### 角色 / Skill 选择

- 目标：从项目里的角色或 Skill 中挑选最匹配的资产。
- 预期输出：候选角色或 Skill 列表，每项包含适用场景、证据路径、风险边界和是否需要安装后验证。

```text
请读取 role_skill_index，根据我的目标任务推荐 3-5 个最相关的角色或 Skill。每个推荐都要说明适用场景、可能输出、风险边界和 evidence_refs。
```

### 风险预检

- 目标：安装或引入前识别环境、权限、规则冲突和质量风险。
- 预期输出：环境、权限、依赖、许可、宿主冲突、质量风险和未知项的检查清单。

```text
请基于 risk_card、boundaries 和 quick_start_candidates，给我一份安装前风险预检清单。不要替我执行命令，只说明我应该检查什么、为什么检查、失败会有什么影响。
```

### 宿主 AI 开工指令

- 目标：把项目上下文转成一次对话开始前的宿主 AI 指令。
- 预期输出：一段边界明确、证据引用明确、适合复制给宿主 AI 的开工前指令。

```text
请基于 prompttools 的 AI Context Pack，生成一段我可以粘贴给宿主 AI 的开工前指令。这段指令必须遵守 not_runtime=true，不能声称项目已经安装、运行或产生真实结果。
```

## 角色 / Skill 索引

- 共索引 6 个角色 / Skill / 项目文档条目。

- **Building the Documentation**（project_doc）：To build the documentation, you will need Sphinx http://www.sphinx-doc.org and various dependencies. You can install them via: 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`docs/README.md`
- **Quickstart**（project_doc）：PromptTools :wrench: Test and experiment with prompts, LLMs, and vector databases. :hammer: 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`README.md`
- **Notebook Examples**（project_doc）：In this folder, you will find various examples of how you can use prompttools for various experimentation and testing. Often, you can simply change a few parameters and put in your own test data to make prompttools suitable for your use case. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`examples/notebooks/README.md`
- **prompttools Playground**（project_doc）：If you are interested to have experiment with a UI rather than a notebook, the playground allows you to do that! You can: - Evaluate different instructions system prompts - Try different prompt templates - Compare across models e.g. GPT-4 vs. local LLaMA 2 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`prompttools/playground/README.md`
- **Contributing to prompttools**（project_doc）：We appreciate all contributions to our project! If you are interested in contributing to prompttools , there are many ways to help out. Your contributions may fall into the following categories: 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`CONTRIBUTING.md`
- **Contributor Covenant Code of Conduct**（project_doc）：Contributor Covenant Code of Conduct 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`CODE_OF_CONDUCT.md`

## 证据索引

- 共索引 55 条证据。

- **Building the Documentation**（documentation）：To build the documentation, you will need Sphinx http://www.sphinx-doc.org and various dependencies. You can install them via: 证据：`docs/README.md`
- **Quickstart**（documentation）：PromptTools :wrench: Test and experiment with prompts, LLMs, and vector databases. :hammer: 证据：`README.md`
- **Notebook Examples**（documentation）：In this folder, you will find various examples of how you can use prompttools for various experimentation and testing. Often, you can simply change a few parameters and put in your own test data to make prompttools suitable for your use case. 证据：`examples/notebooks/README.md`
- **prompttools Playground**（documentation）：If you are interested to have experiment with a UI rather than a notebook, the playground allows you to do that! You can: - Evaluate different instructions system prompts - Try different prompt templates - Compare across models e.g. GPT-4 vs. local LLaMA 2 证据：`prompttools/playground/README.md`
- **Contributing to prompttools**（documentation）：We appreciate all contributions to our project! If you are interested in contributing to prompttools , there are many ways to help out. Your contributions may fall into the following categories: 证据：`CONTRIBUTING.md`
- **License**（source_file）：Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ 证据：`LICENSE`
- **Init**（source_file）：all = "prompttest" 证据：`prompttools/__init__.py`
- **Init**（source_file）：all = 证据：`prompttools/benchmarks/__init__.py`
- **Init**（source_file）：all = 证据：`prompttools/experiment/__init__.py`
- **Error**（source_file）：class PromptExperimentException Exception ⋮---- r""" An exception to throw when something goes wrong with the prompt test setup """ 证据：`prompttools/experiment/experiments/error.py`
- **Utility**（source_file）：def is interactive - bool ⋮---- r""" Used to determine if we are in a jupyter notebook, which determines how we present the visualizations. """ 证据：`prompttools/experiment/widgets/utility.py`
- **Init**（source_file）：all = 证据：`prompttools/harness/__init__.py`
- **Chat History Harness**（source_file）：class ChatHistoryExperimentationHarness ExperimentationHarness ⋮---- r""" An experimentation harness used for compare multiple chat histories. Args: model name str : The name of the model. chat histories List List Dict str, str : A list of chat histories that will be fed into the model. model arguments Optional Dict str, object , optional : Additional arguments for the model. Defaults to None . """ ⋮---- def prepare self - None ⋮---- r""" Initializes and prepares the experiment. """ ⋮---- def run self 证据：`prompttools/harness/chat_history_harness.py`
- **Chat Model Comparison Harness**（source_file）：class ChatModelComparisonHarness ExperimentationHarness ⋮---- r""" An experimentation harness used for comparing chat models. Multi-model version of ChatHistoryExperimentationHarness . Args: model names List str : The names of the models that you would like to compare chat histories List List Dict str, str : A list of chat histories that will be fed into the models. runs int : Number of runs to execute. Defaults to 1 . model arguments Optional Dict str, object , optional : Additional arguments for the model. Defaults to None . """ PIVOT COLUMNS = "model", "messages" ⋮---- def prepare self - None def run self def compare self 证据：`prompttools/harness/chat_model_comparison_harness.py`
- **Chat Prompt Template Harness**（source_file）：def render messages openai chat message template: list dict , user input: dict, environment ⋮---- rendered message = deepcopy message template sys msg template = environment.from string rendered message 0 "content" user msg template = environment.from string rendered message -1 "content" ⋮---- class ChatPromptTemplateExperimentationHarness ExperimentationHarness ⋮---- r""" An experimentation harness used to test various prompt templates for chat models. We use jinja templates, e.g. "Answer the following question: {{input}}". Args: experiment Type Experiment : The experiment constructor that you would like to execute within the harness e.g. prompttools.experiment.OpenAICompletionExperiment m… 证据：`prompttools/harness/chat_prompt_template_harness.py`
- **Harness**（source_file）：class ExperimentationHarness ⋮---- r""" Base class for experimentation harnesses. This should not be used directly, please use the subclasses instead. """ experiment: Experiment PIVOT COLUMNS: list def init self - None ⋮---- @staticmethod def prepare arguments arguments: dict str, object - dict str, list object def prepare self - None ⋮---- r""" Prepares the underlying experiment. """ ⋮---- def run self, clear previous results: bool = False - None ⋮---- r""" Runs the underlying experiment. """ ⋮---- def evaluate self, metric name: str, eval fn: Callable, static eval fn kwargs: dict = {}, eval fn kwargs - None ⋮---- r""" Uses the given eval fn to evaluate the results of the underlying experi… 证据：`prompttools/harness/harness.py`
- **Model Comparison Harness**（source_file）：class ModelComparisonHarness ExperimentationHarness ⋮---- r""" An experimentation harness used for comparing models. Args: model names List str : The names of the models that you would like to compare system prompts List str : A list of system messages, one for each model. model arguments List Optional Dict : A list of model arguments, one for each model. user messages List str User messages that will be tested across models. Defaults to . runs int : Number of runs to execute. Defaults to 1 . """ experiment type = "Comparison" PIVOT COLUMNS = "model", "messages" ⋮---- def prepare self - None ⋮---- system prompt = self.system prompts i model args = {} if self.model arguments == else self.mod… 证据：`prompttools/harness/model_comparison_harness.py`
- **Multi Experiment Harness**（source_file）：class MultiExperimentHarness ⋮---- r""" This is designed to run experiments across multiple model providers. The underlying APIs for different models e.g. LlamaCpp and OpenAI are different, this provides a way to manage that complexity. This will run experiments for different providers, and combine the results into a single table. The notebook "examples/notebooks/GPT4vsLlama2.ipynb" provides a good example how this can used to test prompts across different models. Args: experiments list Experiment : The list of experiments that you would like to execute e.g. prompttools.experiment.OpenAICompletionExperiment """ def init self, experiments: List Experiment def prepare self def run self def ev… 证据：`prompttools/harness/multi_experiment_harness.py`
- **Prompt Template Harness**（source_file）：class PromptTemplateExperimentationHarness ExperimentationHarness ⋮---- r""" An experimentation harness used to test various prompt templates. We use jinja templates, e.g. "Answer the following question: {{input}}". Args: experiment Type Experiment : The experiment constructor that you would like to execute within the harness e.g. prompttools.experiment.OpenAICompletionExperiment model name str : The name of the model. prompt templates List str : A list of prompt jinja -styled templates. user inputs List Dict str, str : A list of dictionaries representing user inputs. model arguments Optional Dict str, object , optional : Additional arguments for the model. Defaults to None . """ PIVOT COLU… 证据：`prompttools/harness/prompt_template_harness.py`
- **Rag Harness**（source_file）：DOC PROMPT TEMPLATE = r"""Given these documents:{{documents}} def doc list to str documents: list str - str ⋮---- res = "" ⋮---- def generate doc prompt documents: list str , prompt or msg: Union str, list dict str, str , is chat: bool ⋮---- prompt = prompt or msg ⋮---- prompt = prompt or msg -1 "content" environment = jinja2.Environment template = environment.from string DOC PROMPT TEMPLATE doc str = doc list to str documents doc prompt = template.render ⋮---- new msg = copy.deepcopy prompt or msg ⋮---- class RetrievalAugmentedGenerationExperimentationHarness ExperimentationHarness ⋮---- r""" An experimentation harness used to test the Retrieval-Augmented Generation process, which involves… 证据：`prompttools/harness/rag_harness.py`
- **System Prompt Harness**（source_file）：class SystemPromptExperimentationHarness ExperimentationHarness ⋮---- r""" An experimentation harness used to test various system prompts. Args: experiment Type Experiment : The experiment that you would like to execute e.g. prompttools.experiment.OpenAICompletionExperiment model name str : The name of the model. system prompts List str : A list of system prompts for the model human messages List str : A list of human user messages to pass into the model model arguments Optional Dict str, object , optional : Additional arguments for the model. Defaults to None . Note that the values are not lists. """ experiment type = "Instruction" PIVOT COLUMNS = "system prompt", "user input" ⋮---- @stati… 证据：`prompttools/harness/system_prompt_harness.py`
- **Utility**（source_file）：def is interactive - bool ⋮---- r""" Used to determine if we are in a jupyter notebook, which determines how we present the visualizations. """ 证据：`prompttools/harness/utility.py`
- **Init**（source_file）：all = 证据：`prompttools/logger/__init__.py`
- **Playground**（source_file）：base dir = os.path.abspath os.path.dirname file path = Path base dir repo dir = path.parent.parent.absolute ⋮---- params = {k: v for k, v in st.query params.items } ⋮---- mode = st.radio "Choose a mode", MODES, key="mode" ⋮---- model type = st.selectbox "Model Type", MODEL TYPES, key="model type" ⋮---- model = st.text input "Local Model Path", key="model" ⋮---- model = st.text input "Repo ID", key="model" api key = st.text input "HuggingFace Hub API Key", type="password" ⋮---- model = st.text input "Model", key="model" api key = st.text input "Google PaLM API Key", type="password" ⋮---- model = st.selectbox "Model", "claude-2", "claude-instant-1" , key="model" api key = st.text input "Anthr… 证据：`prompttools/playground/playground.py`
- **Init**（source_file）：all = 证据：`prompttools/utils/__init__.py`
- **Autoeval**（source_file）：EVALUATION SYSTEM PROMPT = """ EVALUATION USER TEMPLATE = """ def get messages prompt: str, response: str ⋮---- environment = jinja2.Environment template = environment.from string EVALUATION USER TEMPLATE user message = template.render {"prompt": prompt, "response": response} ⋮---- def compute prompt: str, response: str, model: str = "gpt-4" - float ⋮---- r""" Uses a high quality chat model, like GPT-4, to automatically evaluate a given prompt/response pair. Outputs can be 0 or 1. Args: prompt str : The input prompt. response str : The model response. model str : The OpenAI chat model to use for generating an expected response. Defaults to GPT-4. """ ⋮---- evaluation = openai.chat.completio… 证据：`prompttools/utils/autoeval.py`
- **Autoeval From Expected**（source_file）：EVALUATION SYSTEM PROMPT = """ EVALUATION USER TEMPLATE = """ def get messages prompt: str, expected: str, response: str ⋮---- environment = jinja2.Environment template = environment.from string EVALUATION USER TEMPLATE user message = template.render {"prompt": prompt, "expected": expected, "actual": response} ⋮---- def compute prompt: str, expected: str, response: str, model: str = "gpt-4" - float ⋮---- r""" Uses a high quality chat model, like GPT-4, to automatically evaluate a given prompt/response pair. Outputs can be 0 or 1. Args: prompt str : The input prompt. response str : The model response. model str : The OpenAI chat model to use for generating an expected response. Defaults to G… 证据：`prompttools/utils/autoeval_from_expected.py`
- **Autoeval Scoring**（source_file）：anthropic = None AUTO EVAL PROMPT TEMPLATE = """ def generate auto eval prompt fact: str, model answer: str ⋮---- environment = jinja2.Environment template = environment.from string AUTO EVAL PROMPT TEMPLATE auto eval prompt = template.render ⋮---- def compute fact: str, model answer: str, model: str = "claude-2" - float ⋮---- r""" Uses a high quality chat model, like claude-2, to automatically score a given fact/response pair. Output should be an integer ranging from 1 - 7. Args: fact str : The fact truth . The auto-eval model will judge how close the response is from this fact truth . model answer str : The model response. model str : The model that will be judging how close is the respon… 证据：`prompttools/utils/autoeval_scoring.py`
- **Autoeval With Docs**（source_file）：EVALUATION SYSTEM PROMPT = """ EVALUATION USER TEMPLATE = """ def get messages documents: list str , response: str ⋮---- environment = jinja2.Environment template = environment.from string EVALUATION USER TEMPLATE user message = template.render {"documents": "\n".join documents , "response": response} ⋮---- def compute documents: list str , response: str, model: str = "gpt-4" - float ⋮---- r""" Uses a high quality chat model, like GPT-4, to automatically evaluate a given prompt/response pair. Outputs can be 0 or 1. Args: documents list str : documents to provide relevant context for the model to judge model str : The OpenAI chat model to use for generating an expected response. Defaults to… 证据：`prompttools/utils/autoeval_with_docs.py`
- **Chunk Text**（source_file）：def chunk text text: str, max chunk length: int - list str ⋮---- r""" Given a long string paragraph of text and a chunk max length, returns chunks of texts where each chunk's length is smaller than the max length, without breaking up individual words separated by space . Args: text str : source text to be chunked max chunk length int : maximum length of a chunk """ words = text.split chunks = current chunk = "" ⋮---- current chunk = word 证据：`prompttools/utils/chunk_text.py`
- **Error**（source_file）：class PromptToolsUtilityError Exception ⋮---- r""" An exception to throw when something goes wrong with the prompttools utility. """ 证据：`prompttools/utils/error.py`
- **Moderation**（source_file）：r""" Uses OpenAI's moderation API to determine whether the text complies with OpenAI's usage policies. Args: row pandas.core.series.Series : A row of data from the full DataFrame including input, model response, other metrics, etc . text col name str : column name of text to be moderated moderation model str : name of the OpenAI moderation model, defaults to "text-moderation-latest" category names Optional list str : specify the names of category flags to extract from the response and be added as column s in the row, optional. e.g. "harassment", "violence" category score names Optional list str : specify the names of category scores to extract from the response and be added as column s in t… 证据：`prompttools/utils/moderation.py`
- **Similarity**（source_file）：r""" Use a list to optionally hold a reference to the embedding model and client, allowing for lazy initialization. """ ⋮---- cv2 = None ⋮---- skimage structural similarity = None ⋮---- cosine similarity = None ⋮---- librosa = None EMBEDDING MODEL = CHROMA CLIENT = def get embedding model def get chroma client def from huggingface doc1, doc2 ⋮---- model = get embedding model embedding 1 = model.encode doc1, convert to tensor=True embedding 2 = model.encode doc2, convert to tensor=True ⋮---- def from chroma doc1, doc2 ⋮---- chroma client = get chroma client collection = chroma client.create collection name="test collection" ⋮---- query results = collection.query query texts=doc2, n results=1… 证据：`prompttools/utils/similarity.py`
- **Validate Json**（source_file）：KEY EXTRACTION REGEX = r'" ^" +? "\s :' def strip outer brackets text: str - str ⋮---- r""" Removes all chars outside the first '{' and the last '}'. Intended to be a pre-processing step prior to parsing a string as JSON. Args: text str : the text to process """ first brace = text.find "{" last brace = text.rfind "}" ⋮---- def sample pre process fn text: str ⋮---- r""" An example pre-processing that you may use before attempting to parse a string as JSON. This function removes all chars outside the first '{' and the last '}'. Then, it removes "\\n" . This function should be modified depending on your LLM's output. Args: text str : the text to process """ text = strip outer brackets text tex… 证据：`prompttools/utils/validate_json.py`
- **Validate Python**（source_file）：lint = None PROMPTTOOLS TMP = "prompttools tmp.py" def validate text: str ⋮---- r""" Validates that the generated text is python. Args: text str : The generated text, which should be valid python. """ ⋮---- def validate python response row: pandas.core.series.Series, response column name: str = "response" - float ⋮---- r""" Validate whether response string follows Python's syntax. Args: row pandas.core.series.Series : A row of data from the full DataFrame including input, model response, other metrics, etc . response column name str : name of the column that contains the model's response, defaults to "response" """ ⋮---- def evaluate prompt: str, response: str, metadata: Dict - float ⋮----… 证据：`prompttools/utils/validate_python.py`
- **Test Harness**（source_file）：class TestHarness TestCase ⋮---- def test chat history exp harness self def test chat model exp harness self def test prrmpt template exp harness self def test system prompt exp harness self 证据：`test/test_harness.py`
- **Contributor Covenant Code of Conduct**（documentation）：Contributor Covenant Code of Conduct 证据：`CODE_OF_CONDUCT.md`
- **To access remote service, make a copy of this file and save it as .env in the same directory**（source_file）：To access remote service, make a copy of this file and save it as .env in the same directory Then, paste your Hegel API key below between the quotation marks. ENV="prod" HEGELAI API KEY="" 证据：`.env.example`
- **.flake8**（source_file）：flake8 max-line-length = 120 证据：`.flake8`
- **Byte-compiled / optimized / DLL files**（source_file）：Byte-compiled / optimized / DLL files pycache / .py cod $py.class 证据：`.gitignore`
- **.Pre Commit Config**（source_file）：repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v2.3.0 hooks: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/psf/black rev: 22.10.0 hooks: - id: black - repo: https://github.com/PyCQA/flake8 rev: 6.0.0 hooks: - id: flake8 证据：`.pre-commit-config.yaml`
- **.Readthedocs**（source_file）：version: 2 build: os: ubuntu-22.04 tools: python: "3.11" sphinx: configuration: docs/source/conf.py python: install: - requirements: docs/requirements.txt 证据：`.readthedocs.yaml`
- **Minimal makefile for Sphinx documentation**（source_file）：Minimal makefile for Sphinx documentation 证据：`docs/Makefile`
- **Defining the exact version will make sure things don't break**（source_file）：Defining the exact version will make sure things don't break sphinx==5.3.0 furo readthedocs-sphinx-search==0.1.1 prompttools 证据：`docs/requirements.txt`
- **Hegel Ai Logo**（source_file）：.cls-1 { fill: c6c5c5; } .cls-2 { fill: 1e1b1d; } .cls-3 { fill: 771441; } 证据：`img/hegel_ai_logo.svg`
- **Hegel Ai Logo Dark**（source_file）：.cls-1 { fill: f7f6f6; } .cls-2 { fill: 3d3e3f; } .cls-3 { fill: 771441; } 证据：`img/hegel_ai_logo_dark.svg`
- **Common**（source_file）：load dotenv = None ⋮---- dotenv path = join dirname dirname file , ".env" ⋮---- ENV = os.environ.get "ENV", "prod" ⋮---- HEGEL BACKEND URL = """http://127.0.0.1:5000""" ⋮---- HEGEL BACKEND URL = """https://api.hegel-ai.com""" 证据：`prompttools/common.py`
- **Sentry**（source_file）：SENTRY DSN = "https://43fbb5a3a556ca0a879f5a08ce805d87@o4505656408211456.ingest.sentry.io/4505656412667904" token = hashlib.sha256 str uuid.getnode .encode .hexdigest def find certifi path def filter info event, hint def init sentry ⋮---- path = find certifi path ⋮---- filename = os.path.join os.environ.get "HOME", "/tmp" , ".token" ⋮---- filename = os.path.join os.environ.get "USERPROFILE", "c:\\" , ".token" 证据：`prompttools/sentry.py`
- **Pyproject**（source_file）：build-system requires = "setuptools =61.0" build-backend = "setuptools.build meta" 证据：`pyproject.toml`
- **Requirements**（source_file）：openai tenacity tabulate pandas jinja2 jupyterlab ipywidgets pylint sentry-sdk =1.23.0 证据：`requirements.txt`
- **Create Comment**（source_file）：PROMPTTOOLS MD TMP = "markdown.md" selectors = models = "gpt-3.5-turbo", "gpt-4" temperatures = 0.0 openai experiment = OpenAIChatExperiment models, selectors, temperature=temperatures ⋮---- markdown = openai experiment.to markdown 证据：`scripts/create_comment.py`
- **Setup**（source_file）：ROOT DIR = Path file .parent.resolve def get requirements ⋮---- req list = ⋮---- req = line.strip ⋮---- def get version ⋮---- version = "0.0.46a0" sha = "Unknown" ⋮---- sha = subprocess.check output "git", "rev-parse", "HEAD" , cwd=str ROOT DIR .decode "ascii" .strip ⋮---- os build version = os.getenv "BUILD VERSION" ⋮---- version = os build version ⋮---- def export version version, sha ⋮---- version path = ROOT DIR / "prompttools" / "version.py" ⋮---- requirements = get requirements class Clean distutils.command.clean.clean ⋮---- def run self ⋮---- def remove extension pattern ⋮---- build dirs = 证据：`setup.py`
- **App**（source_file）：r""" App for local testing of logger """ ⋮---- app = Flask name ⋮---- @app.route "/", methods= "POST" def process request ⋮---- data = request.json 证据：`test/app.py`
- **Requirements**（source_file）：sentence transformers 证据：`test/requirements.txt`
- **Version**（source_file）：0.0.46a0 证据：`version.txt`

## 宿主 AI 必须遵守的规则

- **把本资产当作开工前上下文，而不是运行环境。**：AI Context Pack 只包含证据化项目理解，不包含目标项目的可执行状态。 证据：`docs/README.md`, `README.md`, `examples/notebooks/README.md`
- **回答用户时区分可预览内容与必须安装后才能验证的内容。**：安装前体验的消费者价值来自降低误装和误判，而不是伪装成真实运行。 证据：`docs/README.md`, `README.md`, `examples/notebooks/README.md`

## 用户开工前应该回答的问题

- 你准备在哪个宿主 AI 或本地环境中使用它？
- 你只是想先体验工作流，还是准备真实安装？
- 你最在意的是安装成本、输出质量、还是和现有规则的冲突？

## 验收标准

- 所有能力声明都能回指到 evidence_refs 中的文件路径。
- AI_CONTEXT_PACK.md 没有把预览包装成真实运行。
- 用户能在 3 分钟内看懂适合谁、能做什么、如何开始和风险边界。

---

## Doramagic Context Augmentation

下面内容用于强化 Repomix/AI Context Pack 主体。Human Manual 只提供阅读骨架；踩坑日志会被转成宿主 AI 必须遵守的工作约束。

## Human Manual 骨架

使用规则：这里只是项目阅读路线和显著性信号，不是事实权威。具体事实仍必须回到 repo evidence / Claim Graph。

宿主 AI 硬性规则：
- 不得把页标题、章节顺序、摘要或 importance 当作项目事实证据。
- 解释 Human Manual 骨架时，必须明确说它只是阅读路线/显著性信号。
- 能力、安装、兼容性、运行状态和风险判断必须引用 repo evidence、source path 或 Claim Graph。

- **概览、安装与支持集成**：importance `high`
  - source_paths: README.md, prompttools/__init__.py, prompttools/version.py, setup.py, pyproject.toml
- **实验系统（Experiments）与多后端集成**：importance `high`
  - source_paths: prompttools/experiment/__init__.py, prompttools/experiment/experiments/__init__.py, prompttools/experiment/experiments/experiment.py, prompttools/experiment/experiments/_utils.py, prompttools/experiment/experiments/error.py
- **Harness 评测框架与 Playground 界面**：importance `high`
  - source_paths: prompttools/harness/__init__.py, prompttools/harness/harness.py, prompttools/harness/utility.py, prompttools/harness/system_prompt_harness.py, prompttools/harness/prompt_template_harness.py
- **工具函数、PromptTest 测试框架与可观测性**：importance `high`
  - source_paths: prompttools/utils/__init__.py, prompttools/utils/error.py, prompttools/utils/autoeval.py, prompttools/utils/autoeval_scoring.py, prompttools/utils/autoeval_with_docs.py

## Repo Inspection Evidence / 源码检查证据

- repo_clone_verified: true
- repo_inspection_verified: true
- repo_commit: `63bedaa342ffb3000d2fabc1d4ba3d87dd16be16`
- inspected_files: `README.md`, `pyproject.toml`, `requirements.txt`, `docs/README.md`, `docs/source/conf.py`, `examples/notebooks/README.md`, `examples/prompttests/test_chromadb.py`, `examples/prompttests/test_huggingface_hub.py`, `examples/prompttests/test_openai_chat.py`, `examples/prompttests/test_qdrant.py`

宿主 AI 硬性规则：
- 没有 repo_clone_verified=true 时，不得声称已经读过源码。
- 没有 repo_inspection_verified=true 时，不得把 README/docs/package 文件判断写成事实。
- 没有 quick_start_verified=true 时，不得声称 Quick Start 已跑通。

## Doramagic Pitfall Constraints / 踩坑约束

这些规则来自 Doramagic 发现、验证或编译过程中的项目专属坑点。宿主 AI 必须把它们当作工作约束，而不是普通说明文字。

### Constraint 1: 来源证据：package breaks while importing LanceDB experiment

- Trigger: GitHub 社区证据显示该项目存在一个维护/版本相关的待验证问题：package breaks while importing LanceDB experiment
- Why it matters: 可能影响升级、迁移或版本选择。
- Evidence: community_evidence:github | https://github.com/hegelai/prompttools/issues/132 | 来源类型 github_issue 暴露的待验证使用条件。
- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。

### Constraint 2: 来源证据：OpenAI Chat Experiment Example dependency issue fix

- Trigger: GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：OpenAI Chat Experiment Example dependency issue fix
- Why it matters: 可能影响授权、密钥配置或安全边界。
- Evidence: community_evidence:github | https://github.com/hegelai/prompttools/issues/121 | 来源讨论提到 python 相关条件，需在安装/试用前复核。
- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。

### Constraint 3: 来源证据：AttributeError: module 'openai' has no attribute 'types'

- Trigger: GitHub 社区证据显示该项目存在一个安装相关的待验证问题：AttributeError: module 'openai' has no attribute 'types'
- Why it matters: 可能增加新用户试用和生产接入成本。
- Evidence: community_evidence:github | https://github.com/hegelai/prompttools/issues/122 | 来源讨论提到 python 相关条件，需在安装/试用前复核。
- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。

### Constraint 4: 来源证据：AzureOpenAIServiceExperiment notebook: TypeError: Missing required arguments; Expected either ('model' and 'prompt') or…

- Trigger: GitHub 社区证据显示该项目存在一个安装相关的待验证问题：AzureOpenAIServiceExperiment notebook: TypeError: Missing required arguments; Expected either ('model' and 'prompt') or ('model', 'prompt' and 'stream') argume…
- Host AI rule: 来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。
- Why it matters: 可能增加新用户试用和生产接入成本。
- Evidence: community_evidence:github | https://github.com/hegelai/prompttools/issues/116 | 来源讨论提到 python 相关条件，需在安装/试用前复核。
- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。

### Constraint 5: 来源证据：Missing requirements - streamlit

- Trigger: GitHub 社区证据显示该项目存在一个安装相关的待验证问题：Missing requirements - streamlit
- Why it matters: 可能增加新用户试用和生产接入成本。
- Evidence: community_evidence:github | https://github.com/hegelai/prompttools/issues/126 | 来源类型 github_issue 暴露的待验证使用条件。
- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。

### Constraint 6: 能力判断依赖假设

- Trigger: README/documentation is current enough for a first validation pass.
- Host AI rule: 将假设转成下游验证清单。
- Why it matters: 假设不成立时，用户拿不到承诺的能力。
- Evidence: capability.assumptions | https://github.com/hegelai/prompttools | README/documentation is current enough for a first validation pass.
- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。

### Constraint 7: 来源证据：Deprecation error : st.experimental_get_query_params and st.experimental_set_query_params will be removed after 2024-04…

- Trigger: GitHub 社区证据显示该项目存在一个运行相关的待验证问题：Deprecation error : st.experimental_get_query_params and st.experimental_set_query_params will be removed after 2024-04-11
- Host AI rule: 来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。
- Why it matters: 可能增加新用户试用和生产接入成本。
- Evidence: community_evidence:github | https://github.com/hegelai/prompttools/issues/124 | 来源类型 github_issue 暴露的待验证使用条件。
- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。

### Constraint 8: 来源证据：Deprecation warnings

- Trigger: GitHub 社区证据显示该项目存在一个运行相关的待验证问题：Deprecation warnings
- Why it matters: 可能增加新用户试用和生产接入成本。
- Evidence: community_evidence:github | https://github.com/hegelai/prompttools/issues/127 | 来源类型 github_issue 暴露的待验证使用条件。
- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。

### Constraint 9: 运行可能依赖外部服务

- Trigger: 项目说明出现 external service/cloud/webhook/database 等运行依赖关键词。
- Host AI rule: 确认是否有离线 demo、mock 数据或可替代服务。
- Why it matters: 本地安装成功不等于能力可用，外部服务不可用会阻断体验。
- Evidence: packet_text.keyword_scan | https://github.com/hegelai/prompttools | matched external service / cloud / webhook / database keyword
- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。

### Constraint 10: 维护活跃度未知

- Trigger: 未记录 last_activity_observed。
- Host AI rule: 补 GitHub 最近 commit、release、issue/PR 响应信号。
- Why it matters: 新项目、停更项目和活跃项目会被混在一起，推荐信任度下降。
- Evidence: evidence.maintainer_signals | https://github.com/hegelai/prompttools | last_activity_observed missing
- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。
