# Context Caching Optimization Specification ## 1. Prompt Structure (Strict) Prompts MUST follow this sequence: ### [A. STATIC REGION] - Top (Always Cached) 1. System Persona & Rules (e.g., .geminirules) 2. Background Knowledge (API specs, architecture, DB schema) 3. Output Format Definitions ### [B. DYNAMIC REGION] - Bottom (Cache Boundary) 1. Variable Parameters (Current Time, Session Metadata) 2. User Request / Query ## 2. Token Compression - Data Flattening: Use Markdown tables, CSV, or JSON instead of prose - Metadata Sanitization: Remove code comments, redundant empty lines, duplicate spacing, and non-essential tracking properties ## 3. Session Controls - History Truncation: Do not concatenate raw dialog turns (invalidates cache) - Checkpoint Aggregation: Summarize history at checkpoints; cache summary, flush raw turns - Request Batching: Align multi-agent tasks within same TTL cycles for Cache Hit ratio # Agentic Coding Workflow - Model Orchestration Role-based model dispatching strategy for rate limit optimization. ## 1. Agent Architecture 4-layer workflow routing by context size, reasoning difficulty, speed, and remaining quota: - Layer 1. Architect Agent (Design / Bug Tracking) Models: DeepSeek V4 Pro, Qwen3.6 Plus (Sub: GLM-5.1) Role: Requirements analysis and structural design specification - Layer 2. Repository Context Agent (Large-scale Source Analysis) Models: MiMo-V2.5-Pro, Kimi K2.6 Role: Long context codebase analysis and task splitting - Layer 3. Worker Agent (Code Generation / Boilerplate) Models: Qwen3.5 Plus, MiniMax M2.7 Role: Business logic and function-level implementation - Layer 4. Inspector Agent (Compile/Lint Error Self-Correction) Models: DeepSeek V4 Flash Role: Build monitoring, syntax error fix, output format validation ## 2. Layer Routing & Limits | Layer | Models | Hourly | Weekly | Primary Tasks | |---|---|---|---|---| | Architect | DeepSeek V4 Pro, Qwen3.6 Plus, GLM-5.1 | 3450, 3300, 880 | 8550, 8200, 2150 | Domain modeling, DB schema, complex debugging. GLM-5.1: approval only | | Context Manager | MiMo-V2.5-Pro, Kimi K2.6 | 1290, 1150 | 3225, 2880 | Long context analysis, legacy refactoring scope, API doc ingestion | | Worker | Qwen3.5 Plus, MiniMax M2.7 | 10200, 3400 | 25200, 8500 | Unit function impl, API binding, DTO/Entity boilerplate, unit tests | | Inspector | DeepSeek V4 Flash | 31650 | 79050 | Compile/lint error fix, output validation, self-correction loop | ## 3. Implementation Guide ```python architect_llm = CustomLLM("deepseek-v4-pro") context_llm = CustomLLM("mimo-v2.5-pro") worker_llm = CustomLLM("qwen-3.5-plus") inspector_llm = CustomLLM("deepseek-v4-flash") architect = Agent(role="Software Architect", llm=architect_llm) code_worker = Agent(role="Senior Backend Developer", llm=worker_llm) linter_inspector = Agent(role="QA & Code Inspector", llm=inspector_llm) ``` ## 4. Operational Rules 1. DeepSeek V4 Flash Firewall - Typos, semicolons, import errors: NEVER escalate to higher models - Minimum 3 self-correction loops must resolve within Flash (31650/hr) 2. GLM-5.1 Escalation Threshold - 880/hr limit is tight. Exclude from default pipeline - Use only as last-resort fallback after 3+ failures from other models 3. Context Split for Token Savings - After MiMo/Kimi scans full repo, extract only needed snippets for Qwen3.5 Plus 4. MiniMax Surge Switching - During boilerplate/test code surges, temporarily route Worker from Qwen3.5 Plus to MiniMax M2.5 (6300/hr) or M2.7 to prevent weekly/monthly lock ## 5. Development Docs 1. Base docs: ./docs/ 2. Real-time dev logs: ./work_logs/ 3. New session: check ./work_logs/work_log_*.md to resume 4. Milestone complete: use /graphify to map milestone relationships 5. Design elements: ./premium_enterprise/DESIGN.md