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で、AIスキル全体5,078件中3,572位、AIエージェントでは969件中728位です。

インストール数
106
ダウンロード数
3191
スター数
4
総合順位
#3,572
全体の上位 71% · AIエージェントの上位 76%
プラットフォームインストール数ダウンロード数スター数コメント
ClawHub ↗10231104-
SkillHub ↗10631914—

プラットフォームごとに集計方法と集計時点が異なります。

このスキルでできること

主文では最小コンテキストの構築、必要に応じたメモリの検索と要約、トークン使用量の推定、予算超過時のメモリ層の破棄を含む二段階の流れを説明しています。補足資料によると、オーバーフロー防止の保証は実装の根拠を上回っています。出発点として扱い、モデルに適したトークン計数を使い、呼び出し直前にハード上限を適用してください。検索メモリには信頼できない内容や指示文が含まれる場合があるため、システム規則を上書きしない参考データとして扱います。

資料公開日 2026-10-29

できること

  • agent 向けの任意メモリ検索とコンテキスト組み立て手順を設計する
  • 予算を超えた場合にメモリコンテキストを先に破棄する
  • メモリ内容をシステム指示から分離する方法を確認する

使う場面

  • LLM プロンプトに任意の会話メモリを含める必要があるとき
  • モデルに適した計数と呼び出し前のハード上限を適用できるとき
  • 検索したメモリを信頼できない参考データとして扱えるとき

プロンプト例

スキルのドキュメントをもとに生成した例であり、実際の実行結果ではありません。

オーバーフローしないと保証せずに二段階組み立ての流れを要約する
モデル呼び出し前に実装するトークン上限チェックを列挙する
検索メモリ内の指示がシステム規則を上書きしない方法を説明する

月次の推移

ダウンロード数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 原文

作者が公開した元のファイルをテキストのまま表示しています。AlphaMoat による編集や審査はしていません。リンクはクリックできません。コマンドは内容を確認してから実行してください。取得日 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)から月単位で集計しています。詳しくはデータの方法論をご覧ください。