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
累計下載
3191
星標
4
全站排名
#3,572
全站前 71% · 「AI 智慧體」前 76%
平台累計安裝累計下載星標評論
ClawHub ↗10231104-
SkillHub ↗10631914—

各平台的計數口徑不同,統計時間不一致。

這個技能是做什麼的

主文描述先構建最小上下文、按需檢索和摘要記憶、估算 token,再在預算不足時丟棄記憶層的兩階段流程。支援材料指出,防止 token 溢位的保證強於當前實現證據;啟用前應將其視為起始實現,使用與模型匹配的 token 計數,並在呼叫前實施硬限制。檢索到的記憶可能包含不可信或指令式內容,應作為參考資料處理,而不能覆蓋系統規則。

資料釋出於 2026-10-29

可以用來做什麼

  • 為 agent 設計可選記憶檢索和上下文組裝步驟
  • 在提示詞超預算時優先捨棄記憶上下文
  • 審查記憶內容在系統提示中的安全邊界

什麼時候用

  • 需要在構造 LLM 提示時納入可選的歷史記憶時
  • 能以模型適用的計數方式複核預算並在呼叫前設硬限制時
  • 可以將檢索記憶當作不可信參考內容處理時

示例提示詞

以下是根據技能文件生成的示例,不代表實際執行結果。

總結這個兩階段提示片語裝流程,不要聲稱它能保證不會溢位
列出呼叫模型前需要實施的 token 限制檢查
說明如何防止檢索記憶中的指令覆蓋系統規則

月度資料趨勢

累計下載3191
2106268932712026-03 · 累計下載 21862026-05 · 累計下載 26122026-06 · 累計下載 27412026-07 · 累計下載 29272026-08 · 累計下載 30162026-09 · 累計下載 319126-0326-09
星標4
3452026-03 · 星標 42026-05 · 星標 42026-06 · 星標 42026-07 · 星標 42026-08 · 星標 42026-09 · 星標 426-0326-09

2026-09 起統計方法調整:同名技能按作者分別統計,並覆蓋全部技能。圖中虛線為調整前的月份,與之後的資料不直接比較,也不計算跨越調整的增長。

月份累計下載環比星標
2026-093191—4
2026-083016+3.0%4
2026-072927+6.8%4
2026-062741+4.9%4
2026-052612—4
2026-032186—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),按月更新。口徑說明見資料方法。