Iterative Practices for Building a Unified LLM That Combines Conversational and Coding Capabilities
This article presents practical approaches for iterating on large language models that unify general conversation, writing, instruction following, code generation, mathematical reasoning, and role-playing within a single model. It covers data governance and mixing strategies, multi-stage training to prevent capability regression, preference alignment for real-world tasks, post-training reinforcement with verifiable signals, engineering considerations for web search and file processing, and a sustainable evaluation and release framework with unified interfaces and capability switches.
Iterative Practices for Building a Unified LLM That Combines Conversational and Coding Capabilities
1. Background: From Scenario-Specific Models to a Unified Capability Model
In the early engineering practice of large language models, general conversation, writing, instruction following, and code generation were often handled by different models or different fine-tuned versions. Splitting models by scenario has clear advantages: well-defined objectives, simple data mixing, and clear evaluation criteria. But the drawbacks are equally obvious: the application layer must maintain multiple sets of routing logic, the user experience is fragmented across tasks, model version management and cost control become complex, and cross-task context is hard to reuse.
As a result, capability unification has become an important evolution path: using a single unified model to cover general conversation, writing, instruction following, code generation, mathematical reasoning, and role-playing. “Unification” here does not mean simply stitching two models together; it means establishing unified standards across training data, behavioral alignment, inference strategies, and engineering interfaces. The core challenges include:
- Capability conflicts: Code tasks emphasize determinism, executability, and edge cases, while general conversation emphasizes naturalness, context understanding, and expressive style. The two must be reconciled.
- Data mixing ratios: Data for different capabilities varies greatly in scale, quality, and difficulty. Naive mixing can easily degrade one of the capabilities.
- Preference alignment: Writing and instruction following require more fine-grained human preference modeling. The goal is not just to “sound right,” but to be correct, complete, and executable.
- Evaluation systems: No single metric can reflect comprehensive capability. Offline evaluation, human review, and business regression must be combined.
- Engineering controllability: Once capabilities such as web retrieval, file processing, and tool calling are introduced, security, permissions, traceability, and latency costs become mandatory considerations.
2. The Basic Path to Capability Unification: Unified Training Objectives and Multi-Stage Iteration
Capability unification is rarely achieved in one shot; it converges gradually through multi-stage iteration. A reusable approach is: first build unified base capabilities, then shape behavior through supervised fine-tuning and preference optimization, reinforce specific scenarios through post-training, and control risk on the engineering side with capability switches.
2.1 Data Governance and Mixing Ratios
Data governance is the top priority for a unified model. General conversation data, writing data, instruction-following data, code data, math data, and role-playing data should each have their own quality standards and deduplication strategies. Code data requires attention to executability, dependency completeness, and license compliance; math data requires attention to the reasoning process and answer verification; writing data requires attention to factuality, structure, and stylistic consistency. Mixing ratios should not be a static proportion; they should be adjusted dynamically according to the stage objective: ensure coverage in the foundation stage, improve preference consistency in the alignment stage, and shore up weak capabilities in the reinforcement stage.
2.2 Multi-Stage Training and Capability Retention
The key to multi-stage training is “learning the new without forgetting the old.” When introducing code and math reinforcement data, high-quality general conversation and writing samples should be retained to prevent degradation in natural language expression and complex instruction understanding. Engineering-wise, staged evaluation sets can monitor capability drift: after each training round, evaluate both the improvement of the target capability and the regression of historical capabilities. Only when the target capability improves and regression metrics remain under control should the version proceed to the next stage.
2.3 Unified Behavioral Norms
A unified model needs unified behavioral norms, including answer structure, citation style, refusal policies, tool-calling boundaries, and the expression of uncertainty. For example, code generation should state assumptions and runtime environment requirements; mathematical derivations should show key steps and flag parts that cannot be verified; web-retrieved results should include sources and timeliness notes; file processing should explain the parsing scope and possible format loss. The clearer the behavioral norms, the easier it is for the application side to build stable integrations.
3. Preference Alignment: Making the Model Fit Real Task Requirements
Preference alignment is the key step that takes a unified model from “able to answer” to “genuinely useful.” For developers and enterprise users, preferences are not just about language style; they include task completeness, constraint compliance, factual fidelity, and safety boundaries.
3.1 Alignment for Writing Tasks
Writing tasks usually carry implicit constraints: audience, tone, length, structure, factual accuracy, and prohibited expressions. Preference data should cover different genres and revision instructions, such as “compress to a specified word count,” “keep terminology consistent,” “switch to a more formal tone,” or “add risk disclosures.” Evaluation must go beyond fluency to check constraint satisfaction rates and factual error rates.
3.2 Alignment for Instruction Following
Instruction-following scenarios require the model to parse multi-step constraints, priorities, and conflict-handling rules. High-quality preference samples should include complex instructions, negative constraints, formatting requirements, and multi-turn revisions. Engineering-wise, instruction following is best decomposed into checkable items: whether all requirements are covered, whether the format is followed, whether negative conditions are honored, and whether the model proactively asks for clarification when information is insufficient.
3.3 Engineering the Alignment Evaluation
Preference alignment cannot rely on subjective impressions alone. A layered evaluation can be established: automated rule checks for format and constraints, human review for helpfulness and expression quality, and business regression to verify real task completion rates. For high-risk scenarios, red-team testing should be added, covering prompt injection, privilege-escalation requests, and sensitive information leakage.
4. Post-Training Reinforcement: Strengthening Math, Code, and Role-Playing
The final stage of fine-tuning or post-training is typically used to reinforce specific capabilities and fix problems exposed in earlier stages. The goal is not to endlessly pile on data, but to improve stability around verifiable signals.
4.1 Mathematical Reasoning
Math reinforcement should focus on process correctness and answer consistency. Feedback can be constructed using answer verification, step-consistency checks, and error-type analysis. Training data should cover multi-step derivations, edge cases, unit conversions, and word-problem modeling. Evaluation should examine both the final answer and whether the derivation is reviewable.
4.2 Code Generation
Code capability cannot be measured by text similarity alone. More reliable signals include syntax checks, static analysis, unit test pass rates, and runtime error classification. Engineering-wise, a “generate–check–fix” loop can be built: after the model generates code, a checker returns error information, and the model revises based on the feedback. This loop also works well on the application side as a quality-assurance mechanism for coding assistants.
4.3 Role-Playing and Style Control
Role-playing requires balancing stylistic consistency with safety boundaries. Preference data should clearly define the persona, tone range, and prohibited content. System prompts should include boundary rules so that persona settings cannot override safety policies. Evaluation should check persona consistency, factuality, and the reasonableness of refusals.
5. Web Retrieval and File Processing: From Closed Generation to Verifiable Answers
Web search and file upload are common capability extensions for unified models, but in essence they are engineering problems of retrieval-augmented generation and document question answering—not simply “one more button.”
5.1 The Web Retrieval Pipeline
Web retrieval typically includes query rewriting, retrieval, reranking, summarization, and citation generation. Engineering attention should focus on: result timeliness, source credibility, citation traceability, caching strategy, and failure fallback. For questions requiring real-time information, the model should state the time range of the information; when retrieval fails, it should fall back to answering from known information with uncertainty flagged.
5.2 File Upload and Parsing
File processing must cover format parsing, text extraction, chunking, metadata management, permission checks, and sensitive information handling. The chunking strategy should balance semantic completeness with retrieval granularity; metadata should include the source and page or paragraph location to support citation. For tables, images, and scanned documents, the boundaries of parsing capability should be made explicit, avoiding the treatment of unreliable extraction results as established facts.
5.3 Security and Injection Defense
Both retrieved content and uploaded files may contain prompt injection. The system should treat external content as untrusted input, explicitly separate data from instructions in the prompt, and enforce least-privilege control over tool calls. On the output side, sensitive information and citation-integrity checks should be performed so that answers are traceable and auditable.
6. Evaluation and Release: Building a Sustainable Quality-Assurance System
The release of a unified model should not depend on a one-time evaluation. A closed loop of “offline evaluation–human review–gradual rollout–online monitoring” is recommended.
- Offline evaluation: Cover dimensions such as general conversation, writing, instruction following, code, math, document Q&A, and retrieval citation, with a fixed regression set.
- Human review: Sample-check helpfulness, fidelity, expression quality, and safety boundaries using a quantifiable review rubric.
- Gradual rollout: Ramp up traffic by percentage while observing error rates, latency, cost, and user feedback.
- Online monitoring: Log request types, tool calls, retrieval hits, refusal rates, and abnormal outputs to support issue tracing.
- Version rollback: Retain the ability to quickly roll back to the last stable version so that capability regressions do not impact the business.
7. Engineering Recommendations: Unified Interface and Capability Switches
On the application side, it is advisable to encapsulate model capabilities behind a unified interface, controlling web access, files, and tool calls through capability switches, so that business code is not tightly coupled to a specific model version. Example:
class UnifiedModelClient:def generate(self, messages, options):# options may include: enable_search, files, tools, timeout, trace_idrequest = build_request(messages, options)response = invoke_model(request)return post_process(response, options)def post_process(self, response, options):# Uniformly handle citations, sensitive information, format validation, and fallback noticesreturn response
Engineering work should also cover timeout retries, streaming output, context trimming, caching, cost budgets, and log redaction. For tool calls, adhere to least privilege and explicit authorization; for files and retrieval results, preserve source information to support auditing.
8. Conclusion
Iterating on a large model that unifies conversational and coding capabilities is fundamentally a systems engineering effort spanning “data governance–behavioral alignment–post-training reinforcement–engineering control–continuous evaluation.” When selecting or building such capabilities, developers and enterprise users should focus on unified behavioral norms, verifiable quality signals, the security boundaries of retrieval and file processing, and gradual rollout with rollback mechanisms. Only by combining model capability, evaluation systems, and engineering governance can one achieve stable, controllable, and measurable results across complex scenarios such as writing, instruction following, code generation, mathematical reasoning, and knowledge Q&A.
