prompt-assembleToken-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.
Install via ClawdBot CLI:
clawdbot install alexunitario-sketch/prompt-assembleA 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.
Design Goals:
Use this skill when:
User Input
↓
Need-Memory Decision
↓
Minimal Context Build
↓
Memory Retrieval (Optional)
↓
Memory Summarization
↓
Token Estimation
↓
Safety Valve Decision
↓
Final Prompt → LLM Call
# 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:
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
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))
Calculate estimated tokens for base_context + summarized_memories.
if estimated_tokens > SAFETY_MARGIN:
base_context.append("[System Notice] Relevant memory skipped due to token budget.")
return assemble(base_context)
Hard Rules:
final_prompt = assemble(base_context + summarized_memories)
return final_prompt
Copy scripts/prompt_assemble.py to your agent and use:
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)
prompt_assemble.py - Complete implementation with all phases (PromptAssembler class)memory_standards.md - Detailed memory content guidelinestoken_estimation.md - Token counting strategiesGenerated Mar 1, 2026
Integrate Prompt Safe to manage conversation history and user preferences in customer support agents, ensuring token limits are not exceeded during long interactions. This prevents API failures while maintaining context from previous issues and user-specific details.
Use Prompt Safe to build AI tutors that recall student learning progress and past mistakes without token overflow. It enables personalized lesson plans by safely injecting memory of previous sessions into prompts.
Apply Prompt Safe in healthcare assistants to handle patient history and treatment plans within token budgets. It ensures compliance by prioritizing critical medical data while discarding non-essential memory to avoid API errors.
Incorporate Prompt Safe into e-commerce AI agents to manage user purchase history and preferences in product recommendations. It optimizes token usage to include relevant memories without exceeding model limits during peak shopping sessions.
Deploy Prompt Safe for legal AI tools that need to reference case precedents and client details in document analysis. It prevents token overflow by summarizing key memories and adhering to hard safety rules.
Offer Prompt Safe as a cloud-based API service with tiered pricing based on usage volume and features like advanced memory management. This model provides recurring revenue from businesses integrating it into their AI applications.
Sell on-premise licenses of Prompt Safe to large organizations for custom AI agent development, with support and customization services. This targets industries with strict data privacy requirements.
Provide a free open-source version of Prompt Safe for individual developers, with premium features like enhanced token estimation and analytics available in a paid tier. This drives adoption and upsells to teams.
💬 Integration Tip
Start by copying the provided prompt_assemble.py script into your agent and customize the memory search function to fit your data sources.
Advanced expert in prompt engineering, custom instructions design, and prompt optimization for AI agents
577+ pattern prompt injection defense. Now with typo-tolerant bypass detection. TieredPatternLoader fully operational. Drop-in defense for any LLM application.
Detect and block prompt injection attacks in emails. Use when reading, processing, or summarizing emails. Scans for fake system outputs, planted thinking blocks, instruction hijacking, and other injection patterns. Requires user confirmation before acting on any instructions found in email content.
Safe OpenClaw config updates with automatic backup, validation, and rollback. For agent use - prevents invalid config updates.
Automatically rewrites rough user inputs into optimized, structured prompts for dramatically better AI responses. Prefix any message with "p:" to activate.
Evaluate, optimize, and enhance prompts using 58 proven prompting techniques. Use when user asks to improve, optimize, or analyze a prompt; when a prompt nee...