Context Composition and Token Economics: Worked Example — Claude Models, Prompting, and Context Engineering (Claude Certified Architect - Professional)
Context Composition and Token Economics — Worked Example This worked example demonstrates how a Claude Certified Architect - Professional candidate...
Context Composition and Token Economics — Worked Example
This worked example demonstrates how a Claude Certified Architect - Professional candidate would approach context composition and token economics to optimise prompt design and API usage within a realistic scenario. The goal is to balance latency, cost, and output quality by managing token budgets, prompt caching, and modular context packaging.
Scenario
An enterprise AI solution uses the Claude API to generate dynamic customer support responses. The system must handle 1,000 requests per hour with a maximum latency of 500 ms per call and a strict monthly token budget. The prompt includes:
- Stable company policy and product information (rarely changes)
- Dynamic customer query context (varies per request)
- System instructions to guide response style and format
The architect must design the prompt context composition and caching strategy to minimise token usage and maintain response quality.
Step 1: Analyse Context Components and Token Budget
First, estimate token counts for each context component:
- Company policy and product info: 1,200 tokens (stable)
- System instructions: 300 tokens (stable)
- Customer query context: 400 tokens (dynamic)
Total tokens per call without caching: 1,900 tokens.
At 1,000 calls/hour and 720 hours/month, total monthly tokens = 1,900 × 1,000 × 720 = 1,368,000,000 tokens, which exceeds the budget.
Step 2: Identify Cache Breakpoints and Modular Packaging
To reduce token usage, place cache breakpoints such that stable content is sent once per cache period:
- Package company policy and product info and system instructions as a cached module sent once per hour.
- Send only the dynamic customer query context per request.
Token usage per hour:
- Cached module: 1,500 tokens × 1,000 calls = 1,500,000 tokens (if sent every call)
- Dynamic context: 400 tokens × 1,000 calls = 400,000 tokens
With caching, the cached module is sent once per hour (1,500 tokens), and dynamic context per call (400 tokens):
- Cached module tokens per hour: 1,500
- Dynamic tokens per hour: 400 × 1,000 = 400,000
- Total tokens per hour: 401,500
Monthly tokens: 401,500 × 720 = 288,000,000 tokens, significantly reducing token consumption.
Step 3: Evaluate Prompt-Caching Behaviour and Token Budget
Using the Claude API's prompt caching feature, the architect configures the system to send the stable module once per hour and reuse the cached prompt for subsequent calls within that hour.
This reduces redundant token transmission and respects latency constraints by avoiding repeated transmission of large stable content.
Step 4: Manage Reasoning Effort and Context Lifecycle
To maintain accuracy and latency, the architect chooses a context lifecycle strategy:
- Context editing: Update cached stable content only when company policy changes.
- Compaction: Summarise older conversation history to reduce token count for long-running sessions.
- Memory tool: Use selective memory to retain essential context without exceeding token limits.
Step 5: Final Architecture Summary
- Modular prompt packaging: Stable content cached hourly, dynamic content sent per request.
- Prompt caching: Leverages Claude API caching to reduce token usage and latency.
- Token budget management: Monthly token usage reduced by ~79% compared to naive approach.
- Context lifecycle: Employ editing and compaction to sustain long-running agents within latency and accuracy requirements.
Worked Example Recap
Problem: Design prompt context composition for 1,000 requests/hour with latency < 500 ms and strict token budget.
Solution steps:
- Estimate token counts for stable and dynamic prompt parts.
- Identify cache breakpoints to separate stable from dynamic content.
- Use prompt caching to send stable content once per hour.
- Calculate token savings and verify budget compliance.
- Implement context lifecycle strategies to maintain accuracy and latency.
This approach ensures cost-effective, performant AI responses using Claude platform features aligned with professional architect best practices.
More in this topic
Preparing for the Claude Certified Architect Professional exam?
Start free with 5 practice quizzes a day and track your progress.
Practise Claude Certified Architect Professional questions free →