alexunitario-sketch

Prompt Safe

AI 智能体v1.0.4
作者:alexunitario-sketch更新于 2026-05-11共 5 个版本 · 最新版本发布于 2026-02-04prompt-assemble@clawhub_alexunitario-sketch/prompt-assemble
提示词优化上下文管理记忆增强#Prompt#Orchestration

据 AlphaMoat 统计,截至 2026-09,Prompt Safe 累计下载 3,191 次、获 4 个星标,在全部 5,078 个 AI 技能中排名第 3,572 位,在「AI 智能体」分类(969 个)中排名第 728 位。

累计安装
106
累计下载
3,191
星标
4
全站排名
#3,572
全站前 71% · 「AI 智能体」前 76%
平台累计安装累计下载星标评论
ClawHub ↗1023,1104-
SkillHub ↗1063,1914—

各平台的计数口径不同,统计时间不一致。

这个技能是做什么的

主文描述先构建最小上下文、按需检索和摘要记忆、估算 token,再在预算不足时丢弃记忆层的两阶段流程。支持材料指出,防止 token 溢出的保证强于当前实现证据;启用前应将其视为起始实现,使用与模型匹配的 token 计数,并在调用前实施硬限制。检索到的记忆可能包含不可信或指令式内容,应作为参考资料处理,而不能覆盖系统规则。

资料发布于 2026-10-29

可以用来做什么

  • 为 agent 设计可选记忆检索和上下文组装步骤
  • 在提示词超预算时优先舍弃记忆上下文
  • 审查记忆内容在系统提示中的安全边界

什么时候用

  • 需要在构造 LLM 提示时纳入可选的历史记忆时
  • 能以模型适用的计数方式复核预算并在调用前设硬限制时
  • 可以将检索记忆当作不可信参考内容处理时

示例提示词

以下是根据技能文档生成的示例,不代表实际运行结果。

总结这个两阶段提示词组装流程,不要声称它能保证不会溢出
列出调用模型前需要实施的 token 限制检查
说明如何防止检索记忆中的指令覆盖系统规则

月度数据趋势

累计下载3,191
2,1062,6893,2712026-03 · 累计下载 2,1862026-05 · 累计下载 2,6122026-06 · 累计下载 2,7412026-07 · 累计下载 2,9272026-08 · 累计下载 3,0162026-09 · 累计下载 3,19126-0326-09
星标4
3452026-03 · 星标 42026-05 · 星标 42026-06 · 星标 42026-07 · 星标 42026-08 · 星标 42026-09 · 星标 426-0326-09

2026-09 起统计方法调整:同名技能按作者分别统计,并覆盖全部技能。图中虚线为调整前的月份,与之后的数据不直接比较,也不计算跨越调整的增长。

月份累计下载环比星标
2026-093,191—4
2026-083,016+3.0%4
2026-072,927+6.8%4
2026-062,741+4.9%4
2026-052,612—4
2026-032,186—4

SKILL.md 原文

以下是作者发布的原始文件,按纯文本显示,本站未做修改或审核;其中的链接不可点击,命令请核实后再运行。抓取于 2026-10-23。

4.0 KB · ClawHub v1.0.4
---
name: prompt-assemble
description: Token-safe prompt assembly with memory orchestration. Use for any agent that needs to construct LLM prompts with memory retrieval. Guarantees no API failure due to token overflow. Implements two-phase context construction, memory safety valve, and hard limits on memory injection.
---

# Prompt Assemble

## Overview

A standardized, token-safe prompt assembly framework that guarantees API stability. Implements **Two-Phase Context Construction** and **Memory Safety Valve** to prevent token overflow while maximizing relevant context.
展开全部(共 150 行)

**Design Goals:**
- ✅ Never fail due to memory-related token overflow
- ✅ Memory is always discardable enhancement, never rigid dependency
- ✅ Token budget decisions centralized at prompt assemble layer

## When to Use

Use this skill when:
1. Building or modifying any agent that constructs prompts
2. Implementing memory retrieval systems
3. Adding new prompt-related logic to existing agents
4. Any scenario where token budget safety is required

## Core Workflow

```
User Input
    ↓
Need-Memory Decision
    ↓
Minimal Context Build
    ↓
Memory Retrieval (Optional)
    ↓
Memory Summarization
    ↓
Token Estimation
    ↓
Safety Valve Decision
    ↓
Final Prompt → LLM Call
```

## Phase Details

### Phase 0: Base Configuration
```python
# Model Context Windows (2026-02-04)
# - MiniMax-M2.1: 204,000 tokens (default)
# - Claude 3.5 Sonnet: 200,000 tokens
# - GPT-4o: 128,000 tokens

MAX_TOKENS = 204000  # Set to your model's context limit
SAFETY_MARGIN = 0.75 * MAX_TOKENS  # Conservative: 75% threshold = 153,000 tokens
MEMORY_TOP_K = 3                     # Max 3 memories
MEMORY_SUMMARY_MAX = 3 lines        # Max 3 lines per memory
```

**Design Philosophy**:
- Leave 25% buffer for safety (model overhead, estimation errors, spikes)
- Better to underutilize capacity than to overflow

### Phase 1: Minimal Context
- System prompt
- Recent N messages (N=3, trimmed)
- Current user input
- **No memory by default**

### Phase 2: Memory Need Decision
```python
def need_memory(user_input):
    triggers = [
        "previously",
        "earlier we discussed",
        "do you remember",
        "as I mentioned before",
        "continuing from",
        "before we",
        "last time",
        "previously mentioned"
    ]
    for trigger in triggers:
        if trigger.lower() in user_input.lower():
            return True
    return False
```

### Phase 3: Memory Retrieval (Optional)
```python
memories = memory_search(query=user_input, top_k=MEMORY_TOP_K)
for mem in memories:
    summarized_memories.append(summarize(mem, max_lines=MEMORY_SUMMARY_MAX))
```

### Phase 4: Token Estimation
Calculate estimated tokens for base_context + summarized_memories.

### Phase 5: Safety Valve (Critical)
```python
if estimated_tokens > SAFETY_MARGIN:
    base_context.append("[System Notice] Relevant memory skipped due to token budget.")
    return assemble(base_context)
```

**Hard Rules:**
- ❌ Never downgrade system prompt
- ❌ Never truncate user input
- ❌ No "lucky splicing"
- ✅ Only memory layer is expendable

### Phase 6: Final Assembly
```python
final_prompt = assemble(base_context + summarized_memories)
return final_prompt
```

## Memory Data Standards

### Allowed in Long-Term Memory
- ✅ User preferences / identity / long-term goals
- ✅ Confirmed important conclusions
- ✅ System-level settings and rules

### Forbidden in Long-Term Memory
- ❌ Raw conversation logs
- ❌ Reasoning traces
- ❌ Temporary discussions
- ❌ Information recoverable from chat history

## Quick Start

Copy `scripts/prompt_assemble.py` to your agent and use:

```python
from prompt_assemble import build_prompt

# In your agent's prompt construction:
final_prompt = build_prompt(user_input, memory_search_fn, get_recent_dialog_fn)
```

## Resources

### scripts/
- `prompt_assemble.py` - Complete implementation with all phases (PromptAssembler class)

### references/
- `memory_standards.md` - Detailed memory content guidelines
- `token_estimation.md` - Token counting strategies

「AI 智能体」分类下的热门技能

数据月份:2026-09 · 下载/星标/安装数聚合自公开技能注册库(ClawHub、SkillHub),按月更新。口径说明见数据方法。