feat(plugins): introduce middleware token proxy plugin suite (reorder, dedup, lookup, skill index)#50
Open
SNM-SNM wants to merge 12 commits into
Open
feat(plugins): introduce middleware token proxy plugin suite (reorder, dedup, lookup, skill index)#50SNM-SNM wants to merge 12 commits into
SNM-SNM wants to merge 12 commits into
Conversation
…dbox, and ZMQ prototypes
…jection and update docs
…console encoding crashes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 theConversationTracker.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'stoolsarray based on the_required_skillslist, trimming unused tool definitions to save context budget.3. Core Engine Optimizations & Fixes
compute_distance_cpu.pywhennum_workers == 1to eliminatemultiprocessing.Poolinitialization and IPC serialization overhead.✓with standard+in all logging/printing calls to preventUnicodeEncodeErrorcrashes on non-UTF-8 consoles.pytest-asyncio,pyzmq, andmsgspecto dependencies to ensure successful integration and testing.Verification & Testing
evaluation/core_merge/mock_proxy.pyto demonstrate the end-to-end integration and telemetry collection of all four plugins.tests/test_kv_lookup.pyandtests/test_skill_index.py.