context-engineering

Design token-budgeted context assembly, memory, and tool-result injection for LLM agents.

Updated Mar 29, 2026
One-click install
npx skills add https://github.com/r-senchuk/agentskills --skill context-engineering-r-senchuk
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: context-engineering
Source: https://github.com/r-senchuk/agentskills/tree/main/.agents/skills/context-engineering
Command: npx skills add https://github.com/r-senchuk/agentskills --skill context-engineering-r-senchuk

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires tiktoken, numpy, and includes references (resource) components.

What problem does it solve? LLM agents lose instructions, forget earlier conversation, or overflow the context window because no one designed what information enters the window at each turn. This Skill provides a step-by-step procedure for budgeting tokens, assembling context dynamically, and managing memory across long conversations. ## Core Features & Use Cases - Token Budgeting: Allocate explicit token budgets across system prompt, history, RAG chunks, tool results, and response reserve using real tokenizers like tiktoken. - Dynamic Context Assembly: Build the context window from prioritized, typed blocks with automatic truncation of low-priority sources when over budget. - Memory Architecture: Choose and implement buffer, sliding window, summary, entity, vector, or hybrid memory patterns with working code for each. - Use Case: Your agent hallucinates or forgets instructions after 30 turns. Use this Skill to add a sliding-window-plus-summary memory, truncate oversized tool results, and log per-turn context snapshots to debug exactly what the model sees. ## Quick Start Use the context-engineering skill to design a token budget and memory strategy for my agent running on GPT-4o with a 128K window that keeps losing instructions after long conversations.

Frequently Asked Questions about context-engineering

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I budget tokens across system prompt, history, and RAG context?▼

Enumerate every context source, assign priorities, and allocate explicit token budgets so total input plus a response reserve stays under the model window. Use tiktoken to measure each source and rebalance by cutting the lowest-priority sources first.

What memory pattern should I use for long LLM conversations?▼

Use a buffer for under 20 turns, sliding window or summary memory for 20-100 turns, and vector or hybrid memory beyond 100 turns. Production agents typically combine a sliding window, running summary, entity extraction, and vector recall.

How do I count tokens accurately for OpenAI chat messages?▼

Use tiktoken's encoding_for_model to count content tokens, then add roughly 3-4 tokens of per-message overhead plus 3 tokens for reply priming. Avoid len(text)/4 estimates, which can be off by 15-40 percent.

Does this approach work with Claude, Mistral, or Gemini models?▼

Yes, the budgeting and assembly procedure is model-agnostic. For models without a public tokenizer, use the provider SDK's token counting or fall back to the cl100k_base encoding, which is within about 5-10 percent for most modern models.

Why does my agent lose instructions in long conversations?▼

The context window overflows and older content, including instructions, gets dropped or pushed out of attention range. Fix it by keeping the system prompt as a never-cut critical block, summarizing old history, and truncating large tool results before injection.

When should I not use context engineering techniques?▼

Do not use it for prompt wording or persona design, RAG infrastructure like chunking and embedding pipelines, or operational guardrails and retry logic. Those belong to prompt engineering, RAG-specific tooling, and harness engineering respectively.