alexunitario-sketch

Prompt Safe

AI Agentv1.0.4
By alexunitario-sketchUpdated 2026-05-115 versions · latest released 2026-02-04prompt-assemble@clawhub_alexunitario-sketch/prompt-assemble
Prompt OptimizationContext ManagementMemory#Prompt#Orchestration

According to AlphaMoat, as of 2026-09, Prompt Safe has 3,191 downloads and 4 stars — ranked #3,572 of 5,078 AI skills overall, and #728 of 969 in AI Agent.

Installs
106
Downloads
3.2K
Stars
4
Overall Rank
#3,572
Top 71% overall · Top 76% in AI Agent
PlatformInstallsDownloadsStarsComments
ClawHub ↗1023.1K4-
SkillHub ↗1063.2K4—

Platforms count differently and update at different times.

What this skill does

The primary describes building minimal context, retrieving and summarizing memory when needed, estimating token use, and discarding the memory layer when the budget is exceeded. Supporting evidence says the overflow guarantees are stronger than the implementation supports. Treat it as a starter, use model-appropriate token counting, and enforce a hard limit immediately before the call. Retrieved memories may contain untrusted or instruction-like text and must remain reference data rather than override system rules.

Profile published 2026-10-29

What you can do with it

  • Design optional memory retrieval and context-assembly steps for an agent
  • Drop memory context first when a prompt exceeds its budget
  • Review how memory content is isolated from system instructions

When to use it

  • When optional conversation memory is needed in LLM prompt construction
  • When the budget can be checked with model-appropriate counting and a hard limit before calls
  • When retrieved memories can be treated as untrusted reference content

Example prompts

Generated from the skill’s documentation as examples; not results of actual runs.

Summarize this two-phase assembly workflow without claiming it guarantees no overflow
List token-limit checks to implement before calling a model
Explain how to prevent instructions in retrieved memories from overriding system rules

Monthly Trend

Downloads3.2K
2.1K2.7K3.3K2026-03 · Downloads 2.2K2026-05 · Downloads 2.6K2026-06 · Downloads 2.7K2026-07 · Downloads 2.9K2026-08 · Downloads 3.0K2026-09 · Downloads 3.2K26-0326-09
Stars4
3452026-03 · Stars 42026-05 · Stars 42026-06 · Stars 42026-07 · Stars 42026-08 · Stars 42026-09 · Stars 426-0326-09

The counting method changed in 2026-09: skills with the same name are now counted separately by author, and the full catalog is covered. Dashed lines show months before the change; they are not compared with later months, and no growth is computed across the change.

MonthDownloadsMoMStars
2026-093.2K—4
2026-083.0K+3.0%4
2026-072.9K+6.8%4
2026-062.7K+4.9%4
2026-052.6K—4
2026-032.2K—4

SKILL.md (original)

The author’s original file, shown as plain text without edits or review by AlphaMoat. Links are not clickable; check commands before running them. Fetched 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.
Show all (150 lines)

**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

Popular in AI Agent

Data month: 2026-09 · Downloads, stars and installs are aggregated monthly from public skill registries (ClawHub, SkillHub). See methodology.