Architecture and Engineering Practice for Multi-Model Workbenches: Building a Flexible, Switchable LLM Service Layer
Workbench products increasingly plug in multiple third-party LLMs so users can switch models in one session without repeating context. This article covers a unified adapter layer, session-owned context with truncation and multimodal fallback, vision and coding tool integration, unified quota conversion and task-based routing, plus an implementation checklist.
1. Background: Why workbenches are going multi-model
Over the past two years, large language models have iterated quickly, and quality gaps by task have become clearer: some models are stronger at long-context understanding, others at code generation, and some now add visual understanding. For intelligent office and coding workbenches, a single model rarely covers every user scenario.
A typical industry move is to connect several third-party models at once, let users switch models in the same conversation by task, and keep context without restating it. The engineering idea is mature: treat models as pluggable resources and build product capability on top of models rather than binding the product to one of them.
Technically, this raises several questions:
- How do you design a unified model access layer so adding a new model stays cheap?
- After a switch, how do you keep conversation context continuous?
- With multiple models, how do you unify quota and billing?
- How do you route automatically between cost and quality?
The sections below take these in turn.
2. Unified model adapter layer: the foundation
2.1 Abstract a standard invocation interface
Vendor APIs differ in parameter names, message shapes, and streaming protocols. Calling each SDK from business code scatters integration logic and raises maintenance cost. Put a model adapter layer between the product and the models: a unified interface upward, a dedicated adapter per model downward.
A simplified sketch:
from abc import ABC, abstractmethodclass ModelAdapter(ABC):@abstractmethoddef chat(self, messages: list[dict], tools: list | None = None,stream: bool = True) -> ChatResult:"""Unified chat completion API; hides protocol differences"""...class ModelRegistry:"""Registry: route by model_id to the matching adapter"""def __init__(self):self._adapters = {}def register(self, model_id: str, adapter: ModelAdapter):self._adapters[model_id] = adapterdef get(self, model_id: str) -> ModelAdapter:if model_id not in self._adapters:raise UnknownModelError(model_id)return self._adapters[model_id]
2.2 Differences the adapter must normalize
- Message structure: Standardize on
role + content. Describe multimodal payloads as shared blocks (text, image) and let each adapter convert to the target format. - Streaming: Normalize vendor event streams into incremental text, tool-call, and end events.
- Capability declaration: On register, declare vision support, max context length, tool calling, and similar, for upstream routing.
- Error semantics: Map rate limits, timeouts, and safety refusals to shared error codes so the upper layer can degrade and retry.
With this layer, adding a model is usually one adapter plus evaluation, with little change on the product side.
3. Context continuity: switching models without losing working memory
A key UX requirement is that switching models in the same thread does not force users to paste background or restate the task. Engineering must solve two problems.
3.1 Who owns session state
Context belongs to the session, not the model. The product keeps model-agnostic session storage:
{"session_id": "sess_001","messages": [{"role": "user", "blocks": [{"type": "text", "text": "Analyze this sales data"}]},{"role": "assistant", "blocks": [{"type": "text", "text": "..."}], "model_id": "model-a"}],"artifacts": ["file_abc.csv", "chart_001.png"]}
A switch only changes the model_id on later requests. History is loaded from session storage and converted by the new adapter.
3.2 Cross-model compatibility
Models differ in context windows and multimodal support. Switching needs truncation and fallback:
- If the new model has no image input, replace historical image blocks with previously generated text descriptions.
- If history exceeds the new window, use summary compression plus the latest few turns so goals, key conclusions, and file references survive.
- Artifacts (code, charts, documents) should persist with the session so any model can cite them. That is a core difference between workbenches and plain chat.
4. Capability expansion: vision and coding
4.1 Vision
Vision-capable models widen the task surface: chart reading, UI screenshots, document layout. Engineering notes:
- Input standardization: Shared resize, format conversion, and size limits so the same image does not behave wildly across models.
- Mixed multimodal history: Explicit block types and order when text and images interleave.
- Artifact loop-back: Structured results from vision (e.g. data extracted from a screenshot) should be stored as session artifacts for later tasks.
4.2 Code and data analysis
Stronger general coding means not only writing code but analysis, visualization, and building pages or apps. The workbench should provide:
- Safe execution: Run generated code in sandboxed containers with limited network and filesystem access; return charts and result files to the session.
- Tool protocol: A shared tool set (file I/O, code execution, chart rendering, web preview) that any adapter can use if it follows the protocol.
- Validation: Static checks and execution checks; on failure, feed errors back for a correction loop.
5. Unified quota and cost routing
5.1 Unified deduction
From the user’s view, one subscription quota across models is the friendliest billing shape. Convert each call into a common credit or quota unit:
quota deducted = Σ (input tokens × input conversion factor+ output tokens × output conversion factor) × model factor
The model factor reflects cost differences: stronger, more expensive models have a larger factor. Users then have a transparent, predictable sense of whether a given model is “cheaper” for the same job.
5.2 Task-based routing suggestions
On top of unified quota, typical routing:
| Task type | Routing bias | Rationale |
|---|---|---|
| Simple Q&A, format conversion | Cost-sensitive light models | Quality gap is small; save quota |
| Complex code, long-document analysis | Capability-first flagship models | Quality gains are large |
| Chart reading, screenshot analysis | Vision-capable models | Hard requirement of the task |
| Primary model rate-limited or timed out | Auto-fallback to a backup | Availability |
Model service gateways from cloud providers such as Baidu AI Cloud follow a similar idea: one access point for many models, with monitoring, alerts, and usage stats so teams can balance quality, cost, and stability.
6. Implementation checklist
When building a multi-model workbench, check:
- Adapter completeness: Message shape, streaming, error codes, and capability declarations all normalized?
- Model-agnostic context: Session state decoupled from a specific model? No re-entry after a switch?
- Multimodal fallback: Reasonable degradation when vision content hits a text-only model?
- Sandbox and safety: Isolated execution? Permission boundaries on tools?
- Transparent quota: Conversion rules visible to users?
- Eval and rollout: Shared eval set before onboard? Percentage-based gray release?
- Observability: Usage and quality metrics by model and by task?
7. Conclusion
Multi-model access is not “add a few more APIs.” It is an architecture upgrade: treat models as replaceable compute, and persist session, artifacts, tools, and quota as product assets. Once that infrastructure exists, onboarding a new model becomes routine iteration, and users can pick the right model for the task and trade off quality versus cost. Teams planning intelligent office or coding products capture later model-iteration gains more easily if they complete this evolution earlier.
