Skip to content

feat(plugins): introduce middleware token proxy plugin suite (reorder, dedup, lookup, skill index) - #50

Open
SNM-SNM wants to merge 45 commits into
mainfrom
feature/msc-cache-optimization
Open

feat(plugins): introduce middleware token proxy plugin suite (reorder, dedup, lookup, skill index)#50
SNM-SNM wants to merge 45 commits into
mainfrom
feature/msc-cache-optimization

Conversation

@SNM-SNM

@SNM-SNM SNM-SNM commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Overview

This PR introduces a suite of Middleware Token Proxy Plugins designed to sit between agent frameworks (e.g., OpenClaw) and LLM engines (e.g., SGLang) to optimize KV cache sharing, minimize context budgets, and perform cache-aware routing.

These modules implement the core optimizations detailed in the MSc cache optimization project (Direction A).


Key Features

1. Static Context Optimization Plugins (WP1)

  • ContextReorderPlugin: Processes OpenAI-formatted request batches to group similar contexts, maximizing RadixAttention prefix sharing on SGLang.
  • ContextDedupPlugin: Conversation-aware history compressor. It tracks session turns and automatically replaces redundant historical messages with lightweight reference hints (e.g., [Reference to Turn 1]) utilizing the ConversationTracker.

2. Dynamic Routing & Tool Filtering Plugins (WP2)

  • KVCacheLookupPlugin: Subscribes to SGLang worker event streams via ZeroMQ (ZMQ) to build a real-time, in-memory Shadow Radix Tree representing the workers' GPU KV cache. Routes incoming requests to the worker with the longest prefix match.
  • SkillAwareContextPlugin: Dynamically filters and injects tool schemas into the request's tools array based on the _required_skills list, trimming unused tool definitions to save context budget.

3. Core Engine Optimizations & Fixes

  • Multiprocessing Bypass: Added an execution bypass in compute_distance_cpu.py when num_workers == 1 to eliminate multiprocessing.Pool initialization and IPC serialization overhead.
  • Windows Terminal Compatibility: Replaced Unicode checkmark character with standard + in all logging/printing calls to prevent UnicodeEncodeError crashes on non-UTF-8 consoles.
  • Dependencies: Added pytest-asyncio, pyzmq, and msgspec to dependencies to ensure successful integration and testing.

Verification & Testing

  • Mock Proxy Test: Added a complete pipeline mock test in evaluation/core_merge/mock_proxy.py to demonstrate the end-to-end integration and telemetry collection of all four plugins.
  • Unit Tests: Added tests/test_kv_lookup.py and tests/test_skill_index.py.
  • CI status: All 184 CPU tests passed successfully.

@SNM-SNM
SNM-SNM requested review from Chivier and SecretSettler June 11, 2026 19:00
SNM-SNM and others added 17 commits June 15, 2026 14:11
…e sandbox Dockerfile with transformers/torch
… benchmarking

- Added --mode and A/B test routing logic (baseline vs with_plugin) to run_bigcodebench_elm_full.py
- Implemented global cache hit telemetry in http_server.py
- Added percentage savings calculations to dedup and skill_index plugins
- Added HTTP polling server to ZMQ publisher
- Added HTTP polling mode to ZMQ subscriber
- Created benchmark_routing_latency.py micro-benchmark comparing HTTP vs ZMQ
- Create model-agnostic run_mcpatlas_eval.py for tool-use evaluation
- Implement robust health-checking and boot timeouts for proxy server
- Add SLURM scripts for ELM GPT-5.5 test and full runs
- Add SLURM scripts for DeepSeek V4 Pro test and full runs
- Ensure proper propagation of API keys and caching environment variables
Hengyi Yu added 4 commits July 3, 2026 18:06
- Fix bash redirection bug in pip install

- Adjust vLLM gpu-memory-utilization for 16GB MIG partition

- Add proper vLLM shutdown to prevent Phase 2 VRAM OOM

- Fix hardcoded API base URL in evaluation script

- Add Qwen tool call parser support to vLLM boot command
Hengyi Yu and others added 13 commits July 18, 2026 11:31
- Added academic attribution and MSc vs PhD delineation to README
- Added BibTeX citation snippet
- Standardized python evaluation harnesses to accept dynamic plugins
- Generated 6 universal, parameterized bash entry points
- Purged legacy fractured bash scripts and slurm clutter
- Archived HPC SLURM wrappers for markers
- Added sentence-transformers to requirements.txt
- Provided .env.example for local orchestration
…URL, plugin descriptions, shadow-mode table), remove stale INTEGRATION_GUIDE
…sing benchmark scripts

- Restored the original, un-refactored evaluation scripts (run_mcpatlas_eval.py, etc.)
  that were deleted during the refactor but are still explicitly referenced by the
  HPC SLURM wrappers. This guarantees markers can seamlessly execute the cluster runs.
- Added a --distractor_ratio flag to run_mcpatlas_eval.py for the ablation sweep.
- Created submit_distractor_sweep_mcpatlas.slurm to execute the new ablation.
…ormalization

- Implemented real distractor sampling from global tool pool in MCP-Atlas eval to properly ablate attention dilution.
- Added --seed parameter to BigCodeBench full evaluation for reproducibility.
- Reverted temperature configurations to safely rely on API default (~1.0) to preserve variance analysis matching historic reported metrics.
- Added 3-seed full evaluation SLURM launcher for BigCodeBench.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant