Multi-Model Collaboration: How to Route Document and Code Tasks
With the frequent release of new large language models, technical communities often debate over rankings. However, from an engineering perspective, the binary choice of "which model is best" is the wrong question. This article explores a multi-model collaboration approach based on task layering and routing. It analyzes the differences between document-centric and code-centric tasks in terms of capability requirements, error modes, and cost structures. By establishing a four-tier task classification, building a custom evaluation matrix, and implementing a minimal collaborative architecture featuring routing, verifiers, logging, and fallback mechanisms, teams can achieve stable task delivery and optimize the Total Cost of Ownership (TCO) rather than relying solely on public leaderboards or unit pricing.
With the frequent release of new large language model (LLM) versions, technical communities easily fall into debates over “who ranks first” or “which one to choose.” However, from an engineering implementation perspective, this question misses the mark. A more reasonable approach is to avoid a binary choice in model selection; instead, layer your tasks and route them by type. Document review, analysis reports, content generation, and batch classification have different requirements from code modification, script generation, agent execution, and tool calling. Their error modes, review costs, and failure penalties also differ. If a team is small and must converge on a single model, the decision should be based on the Total Cost of Ownership (TCO) of a real task set, rather than just looking at the price tag or public leaderboards.
Below, we will explore a reusable selection and collaboration practice covering task layering, evaluation methods, document tasks, code and agent tasks, cost models, and implementation architecture.
I. Why “Choosing Only One Model” Is the Wrong Question
First, task heterogeneity is high. Document tasks emphasize clause localization, citation consistency, factual constraints, format stability, and auditability. Code tasks emphasize repository context understanding, valid tool call parameters, test loops, failure recovery, and permission boundaries. A model that performs stably in structured writing is not necessarily reliable in multi-step tool execution. Conversely, a model adept at agent operations may not be suitable for high-value legal or financial documents.
Second, error modes differ. In document tasks, the most dangerous errors are not poor fluency, but mismatched clause numbering, citing outdated expressions, and presenting uncertain content as definitive conclusions. In code tasks, the most dangerous errors are claiming completion despite failed tests, unauthorized tool calls, and inability to rollback after failure. Selection must track “severe error rates” separately, not just average scores.
Third, cost structures differ. Batch summarization and classification can tolerate lower unit prices and spot-check mechanisms. High-value documents require manual review, where every minute of rework is a cost. Code agents require sandboxes, logs, retries, and test environments, leading to higher hidden costs. A low list price does not mean a low bill, and a low bill does not mean a low total cost.
Fourth, relying on a single model poses supply and change risks. Version upgrades, rate limiting, regional availability, and context window changes can all impact production stability. The rational approach is not to stack models infinitely, but to build a minimal collaborative architecture of “primary model + fallback model + verifier.”
II. Task Layering: Four Task Types and Capability Weights
Common requirements can be divided into four layers:
- Content Production and Analysis: Proposals, reports, contract drafts, risk reviews. Core metrics include factual accuracy, traceable citations, structural completeness, clear marking of uncertainties, and minimal manual rework.
- Code and Engineering: Modifying legacy projects, writing scripts, adding tests, fixing defects. Core metrics include compilation success, test pass rate, controllable change scope, and rollback capability.
- Agent and Tool Execution: Calling commands, operating browsers or desktops, multi-step task orchestration. Core metrics include tool call success rate, permission boundaries, step logging, and failure recovery.
- Batch Processing: Copywriting, summarization, classification, extraction. Core metrics include unit cost, throughput, format stability, and spot-check pass rate.
These four task types should not share the same evaluation criteria. A better practice is to define weights for each type. For example, “citation consistency” and “severe error rate” carry the highest weight in document review; “test pass rate” and “legal tool call rate” are highest in code tasks; “cost per item” and “format pass rate” are highest in batch tasks.
III. Evaluation Methods: From Leaderboard Screening to Production Validation
Public leaderboards are suitable for initial screening but cannot directly dictate production selection. Standardized questions often fail to cover engineering metrics like clause citation verification, cross-paragraph consistency in long documents, tool call interruption recovery, and permission sandboxes. Moreover, when leaderboard scores are close, real-world differences manifest more in error types and rework costs.
It is recommended to build your own desensitized task set, sampling from production data for each task type, covering simple, medium, and difficult tiers. During evaluation, record at least the following fields:
- Task success rate: Whether all requirements are met in one go.
- Severe error rate: Factual errors, citation mismatches, unauthorized operations, claiming completion despite failed tests.
- Manual rework time: Minutes required for review, modification, and retry.
- Citation and format pass rate: Whether numbering, fields, and templates meet requirements.
- Tool call success and recovery rate: Whether an executable fallback is provided after failure.
- P95 latency and cost per task.
- Error type distribution, not just an average score.
Evaluation results should not be reduced to a single total score, but retained as a “task type × model strategy × error type” matrix. This provides the basis for subsequent routing strategies.
IV. Document Tasks: Prioritize Accuracy and Auditability
In tasks like document review, analysis reports, and contract drafts, prioritize model strategies that are more stable in structured output, clause localization, and uncertainty marking. A deliverable should not just “read well”; it must satisfy the following: risk points can be localized by clause number; modifications are shown with before-and-after comparisons; uncertainties are explicitly marked for human decision-making; and citations can be traced back to the original text.
A common situation in actual evaluations is that an output is structurally complete and fluent, but clause citations have mismatched numbers, or outdated expressions are cited as current clauses. Such errors are fatal for business delivery. Therefore, the document pipeline must include a verifier rather than fully trusting model output.
For example, require the model to output structured results:
{"clause_id": "7.2","risk_level": "high","risk_summary": "...","evidence_quote": "...","suggested_change": "...","confidence": "low","needs_human": true}
The post-processor verifier should at least do three things: check if the clause_id exists in the original text; check if the evidence_quote can be matched in the original text; and check if an outdated version is being cited. For entries where confidence is low or needs_human is true, route them to a manual review queue. This way, even if the model occasionally mismatches citations, the error can be intercepted before delivery.
V. Code and Agent Tasks: Prioritize Execution Loops
The core of code modification, script generation, and agent execution is not “generating something that looks right,” but “executing something that works.” Selection should focus on: understanding repository context; modifying according to the principle of minimal change; valid tool call parameters; running tests in a sandbox; and rolling back or providing executable repair steps upon failure.
A practical agent execution state machine can be abstracted as:
plan -> validate_tool_call -> execute_in_sandbox -> observe_result-> if success: run_tests-> if fail: retry_or_rollback-> if still fail: escalate_with_logs
Each step must record input, tool parameters, output, error codes, and duration. Without step-level logs, it is difficult to pinpoint whether an agent failure is due to a planning error, a tool parameter error, or an environment issue. Regarding permissions, execution should occur in a container or sandbox, restricting file system, network, and credential access; high-risk operations must require human confirmation.
VI. Cost: Cheaper Pricing Does Not Mean a Cheaper Bill
Total Cost of Ownership can be roughly expressed as:
Total Cost = API Call Fee + Retry Cost + Manual Review Cost + Rework Cost + Latency Cost + O&M and Governance Cost
Batch tasks can use lower-cost strategies but must be paired with spot checks and format validation. High-value documents should prioritize a low severe error rate, because the review cost of one mismatched clause may far exceed the API call fee. Code agents should be calculated based on the “cost per test-passed task,” not the token unit price. If you must converge to a single model, choose the one with the lowest comprehensive cost on major tasks where errors can be caught by a verifier, rather than simply choosing the one with the lowest list price.
VII. Implementation Architecture: Routing, Evaluation, Logging, Monitoring, and Fallback
The recommended minimal architecture includes five layers:
- Task Classifier: Identifies types like document review, code modification, agent execution, and batch processing.
- Policy Router: Selects primary and fallback strategies based on task type.
- Structured Output and Verifier: Performs citation checks for documents, test checks for code, and parameter checks for tool calls.
- Logging and Monitoring: Records requests, responses, error codes, retry counts, manual review duration, and cost per task.
- Canary and Fallback: New versions are validated with small traffic first, automatically switching back to stable strategies upon anomalies.
At the infrastructure layer, general-purpose capabilities can be leveraged using Baidu AI Cloud: object storage for desensitized evaluation samples and task artifacts, log services for call chains and error information, monitoring and alerting for success rates and cost metrics, and container platforms for running evaluation tasks and agent sandboxes. These capabilities should serve as general engineering support, not tied to specific model capabilities.
The illustrative routing pseudocode is as follows:
POLICY = {"doc_review": {"primary": "doc_stable", "fallback": "general_stable", "checks": ["clause_exists", "quote_match", "version_valid"]},"code_agent": {"primary": "agent_stable", "fallback": "general_stable", "checks": ["tool_schema", "test_pass", "diff_scope"]},"batch_extract": {"primary": "cost_efficient", "fallback": "general_stable", "checks": ["schema_valid", "sample_audit"]}}function route(task):kind = classify(task)policy = POLICY[kind]result = invoke(policy.primary, task)if not validate(result, policy.checks):result = invoke(policy.fallback, task)log(task, result, cost, latency, errors)return result
VIII. Common Pitfalls
First, treating public leaderboards as procurement conclusions. Leaderboards are for screening; production selection must be validated with real task sets. Second, comparing only unit prices. Document rework, code retries, and manual reviews are all part of the bill. Third, using one model for everything. Task heterogeneity dictates that layered routing is more stable. Fourth, ignoring verifiers. Document citation checks, code test checks, and tool parameter checks should be default components. Fifth, lacking a fallback chain. During version upgrades or rate limits, the absence of a fallback amplifies failures. Sixth, neglecting permissions and compliance. Agent execution must be sandboxed, and sensitive data must be desensitized and audited.
IX. Conclusion
Evaluating a batch of LLM versions should not stop at the debate of “who is number one.” The more valuable engineering questions are: which tasks require high accuracy and auditability, which require execution loops, and which can be cost-prioritized; how to use real task sets to evaluate severe error rates, rework rates, and TCO; and how to turn multi-model collaboration into a controllable architecture through routing, verification, logging, monitoring, and fallback. If you must converge to a single model, choose the one with the lowest comprehensive cost on major tasks where errors can be caught. Multi-model collaboration is not the goal; stable task delivery is.
