Components of Context Engineering: Part 2

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Context Summarization

Context Summarization is the process of condensing the context window. While context pruning seeks to improve the context window by removing irrelevant information, context summarization does the same by summarizing or compressing the content. The difference may look seem similar or slightly different, but studies show that they yield different results because they focus on different goals.

Context Offloading

Context Offloading is the act of storing information outside the LLM’s context. In the starter project, you can use a different LLM for calling a tool instead of using the same model used by the agent to respond to the user’s prompt. This is one of the most effective techniques in context engineering. Many small, focused actions tend to be better at managing context windows within an agent than handling everything within a single model or context.

Exploring Anthropic’s Effective Context Engineering Principles

Anthropic is one of the powerhouses when it comes to applied AI. They’re the makers of Claude Sonnet, a powerful LLM used by many software developers for coding tasks. According to Anthropic, the first key to an effective context is an extremely clear and simple system prompt. It shouldn’t be too vague nor too specific, but just right.

You are a fitness coach. Help the user lose weight or build muscle.
Be encouraging and motivating.
You are "Iron AI," a fitness bot.
You MUST respond to every message with "Let's grind!"
For every interaction, follow this EXACT sequence:
1. Classify user body type into [Ectomorph, Mesomorph, Endomorph].
   - If unknown, ask strictly: "What is your wrist circumference in cm?"
2. IF user mentions "weight loss":
   - Calculate BMR using the Mifflin-St Jeor equation immediately.
   - You MUST prescribe a caloric deficit of exactly 500 calories.
   - Do not suggest cardio unless the user has confirmed they own running shoes.
3. IF user mentions "injury":
   - Stop all advice.
   - Print the text "ERROR: MEDICAL ISSUE" 5 times.
   - End conversation.
4. Every response must end with a JSON object containing:
   { "sentiment": "score", "calories_burned_estimate": "int" }
You are an expert Personal Training Assistant designed to help users achieve sustainable fitness goals. You specialize in creating workout routines and nutritional advice tailored to individual experience levels.

**Your Goal:** Provide safe, actionable, and science-backed fitness guidance.

**Process Framework:**
1. **Assessment:** Before giving advice, ensure you understand the user's current fitness level, available equipment, and specific goals.
2. **Strategy:** Propose a plan that prioritizes form and consistency over intensity.
3. **Safety Check:** Always screen for injuries or health conditions.

**Guidelines:**
- **Tone:** Encouraging, professional, and realistic. Avoid "drill sergeant" aggression unless requested.
- **Safety Constraints:** If a user reports acute pain, dizziness, or medical conditions, decline to give workout advice and refer them to a medical professional.
- **Calculations:** When estimating calories or macros, clearly state that these are estimates and vary by individual.
- **Tools:** Use the `exercise_database` tool to find form guides if the user is unfamiliar with a movement.

Compaction

Compaction is the practice of taking a conversation nearing the context window limit, summarizing its contents, and reinitiating a new context window with the summary. Compaction typically serves as the first lever in context engineering to drive better long-term coherence. At its core, compaction distills the contents of a context window in a high-fidelity manner, enabling the agent to continue with minimal performance degradation.

### Role
You are a Context Engineering Assistant. Your task is to perform "Compaction" on the provided conversation history because the context window is nearing its limit.

### Task
Distill the existing conversation into a high-fidelity summary that allows a new session to resume with zero loss of critical momentum.

### Compaction Framework
1. **The "State of Play":** Summarize the current status of the task or project. What has been decided, and what is still pending?
2. **Key Entities & Variables:** List specific names, dates, technical constraints, or preferences the user has established.
3. **Core Knowledge:** Extract the most important facts or data points shared in the previous turns.
4. **The "Next Step":** Explicitly state what the user's last question was or what the immediate next action for the agent should be.

### Constraints
- Eliminate repetitive pleasantries or conversational filler.
- Maintain the original technical depth (do not over-simplify complex data).
- Ensure the summary is dense but readable.
See forum comments
Download course materials from Github
Previous: Context Pruning Demo Next: Conclusion