Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
A comprehensive collection of Agent Skills for context engineering, multi-agent architectures, and production agent systems.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
skills/context-fundamentals/references/context-components.md
1# Context Components: Technical Reference23This document provides detailed technical reference for each context component in agent systems.45## System Prompt Engineering67### Section Structure89Organize system prompts into distinct sections with clear boundaries. A recommended structure:1011```12<BACKGROUND_INFORMATION>13Context about the domain, user preferences, or project-specific details14</BACKGROUND_INFORMATION>1516<INSTRUCTIONS>17Core behavioral guidelines and task instructions18</INSTRUCTIONS>1920<TOOL_GUIDANCE>21When and how to use available tools22</TOOL_GUIDANCE>2324<OUTPUT_DESCRIPTION>25Expected output format and quality standards26</OUTPUT_DESCRIPTION>27```2829This structure allows agents to locate relevant information quickly and enables selective context loading in advanced implementations.3031### Altitude Calibration3233The "altitude" of instructions refers to the level of abstraction. Consider these examples:3435**Too Low (Brittle):**36```37If the user asks about pricing, check the pricing table in docs/pricing.md.38If the table shows USD, convert to EUR using the exchange rate in39config/exchange_rates.json. If the user is in the EU, add VAT at the40applicable rate from config/vat_rates.json. Format the response with41the currency symbol, two decimal places, and a note about VAT.42```4344**Too High (Vague):**45```46Help users with pricing questions. Be helpful and accurate.47```4849**Optimal (Heuristic-Driven):**50```51For pricing inquiries:521. Retrieve current rates from docs/pricing.md532. Apply user location adjustments (see config/location_defaults.json)543. Format with appropriate currency and tax considerations5556Prefer exact figures over estimates. When rates are unavailable,57say so explicitly rather than projecting.58```5960The optimal altitude provides clear steps while allowing flexibility in execution.6162## Tool Definition Specification6364### Schema Structure6566Each tool should define:6768```python69{70"name": "tool_function_name",71"description": "Clear description of what the tool does and when to use it",72"parameters": {73"type": "object",74"properties": {75"param_name": {76"type": "string",77"description": "What this parameter controls",78"default": "reasonable_default_value"79}80},81"required": ["param_name"]82},83"returns": {84"type": "object",85"description": "What the tool returns and its structure"86}87}88```8990### Description Engineering9192Tool descriptions should answer: what the tool does, when to use it, and what it produces. Include usage context, examples, and edge cases.9394**Weak Description:**95```96Search the database for customer information.97```9899**Strong Description:**100```101Retrieve customer information by ID or email.102103Use when:104- User asks about a specific customer's details, history, or status105- User provides a customer identifier and needs related information106107Returns customer object with:108- Basic info (name, email, account status)109- Order history summary110- Support ticket count111112Returns null if customer not found. Returns error if database unreachable.113```114115## Retrieved Document Management116117### Identifier Design118119Design identifiers that convey meaning and enable efficient retrieval:120121**Poor identifiers:**122- `data/file1.json`123- `ref/ref.md`124- `2024/q3/report`125126**Strong identifiers:**127- `customer_pricing_rates.json`128- `engineering_onboarding_checklist.md`129- `2024_q3_revenue_report.pdf`130131Strong identifiers allow agents to locate relevant files even without search tools.132133### Document Chunking Strategy134135For large documents, chunk strategically to preserve semantic coherence:136137```python138# Pseudocode for semantic chunking139def chunk_document(content):140"""Split document at natural semantic boundaries."""141boundaries = find_section_headers(content)142boundaries += find_paragraph_breaks(content)143boundaries += find_logical_breaks(content)144145chunks = []146for i in range(len(boundaries) - 1):147chunk = content[boundaries[i]:boundaries[i+1]]148if len(chunk) > MIN_CHUNK_SIZE and len(chunk) < MAX_CHUNK_SIZE:149chunks.append(chunk)150151return chunks152```153154Avoid arbitrary character limits that split mid-sentence or mid-concept.155156## Message History Management157158### Turn Representation159160Structure message history to preserve key information:161162```python163{164"role": "user" | "assistant" | "tool",165"content": "message text",166"reasoning": "optional chain-of-thought",167"tool_calls": [list if role="assistant"],168"tool_output": "output if role="tool"",169"summary": "compact summary if conversation is long"170}171```172173### Summary Injection Pattern174175For long conversations, inject summaries at intervals:176177```python178def inject_summaries(messages, summary_interval=20):179"""Inject summaries at regular intervals to preserve context."""180summarized = []181for i, msg in enumerate(messages):182summarized.append(msg)183if i > 0 and i % summary_interval == 0:184summary = generate_summary(summarized[-summary_interval:])185summarized.append({186"role": "system",187"content": f"Conversation summary: {summary}",188"is_summary": True189})190return summarized191```192193## Tool Output Optimization194195### Response Formats196197Provide response format options to control token usage:198199```python200def get_customer_response_format():201return {202"format": "concise | detailed",203"fields": ["id", "name", "email", "status", "history_summary"]204}205```206207The concise format returns essential fields only; detailed returns complete objects.208209### Observation Masking210211For verbose tool outputs, consider masking patterns:212213```python214def mask_observation(output, max_length=500):215"""Replace long observations with compact references."""216if len(output) <= max_length:217return output218219reference_id = store_observation(output)220return f"[Previous observation elided. Full content stored at reference {reference_id}]"221```222223This preserves information access while reducing token usage.224225## Context Budget Estimation226227### Token Counting Approximation228229For planning purposes, estimate tokens at approximately 4 characters per token for English text:230231```2321000 words ≈ 7500 characters ≈ 1800-2000 tokens233```234235This is a rough approximation; actual tokenization varies by model and content type.236237### Context Budget Allocation238239Allocate context budget across components:240241| Component | Typical Range | Notes |242|-----------|---------------|-------|243| System prompt | 500-2000 tokens | Stable across session |244| Tool definitions | 100-500 per tool | Grows with tool count |245| Retrieved documents | Variable | Often largest consumer |246| Message history | Variable | Grows with conversation |247| Tool outputs | Variable | Can dominate context |248249Monitor actual usage during development to establish baseline allocations.250251## Progressive Disclosure Implementation252253### Skill Activation Pattern254255```python256def activate_skill_context(skill_name, task_description):257"""Load skill context when task matches skill description."""258skill_metadata = load_all_skill_metadata()259260relevant_skills = []261for skill in skill_metadata:262if skill_matches_task(skill, task_description):263relevant_skills.append(skill)264265# Load full content only for most relevant skills266for skill in relevant_skills[:MAX_CONCURRENT_SKILLS]:267skill_context = load_skill_content(skill)268inject_into_context(skill_context)269```270271### Reference Loading Pattern272273```python274def get_reference(file_reference):275"""Load reference file only when explicitly needed."""276if not file_reference.is_loaded:277file_reference.content = read_file(file_reference.path)278file_reference.is_loaded = True279return file_reference.content280```281282This pattern ensures files are loaded once and cached for the session.283284