LLMs for Office Writing and Coding: A Practical Guide to Reasoning, MoE, Cost, and Model Selection
This practical guide examines how large language models are moving from question answering to task execution in office writing and coding. It covers the reasoning, code generation, tool-calling, and orchestration capabilities required for end-to-end work; explains MoE routing; and shows how to measure latency, throughput, and cost, select flagship or lightweight models, and approach formal official document writing deployments.
LLMs for Office Writing and Coding: A Practical Guide to Reasoning, MoE, Cost, and Model Selection
1. From Question Answering to Execution: The Changing Role of LLMs
Early large language models mainly handled question-answering tasks: a user asked a question, and the model returned a text answer. As model capabilities in reasoning, code, and long-text understanding have improved, LLMs have begun to take on more complete work, such as drafting official documents from requirements, generating runnable scripts, decomposing multi-step tasks, and calling external tools. This shift requires a change in evaluation criteria. In the past, the focus was on whether an answer was fluent. Now, the focus is on whether results are verifiable, steps are traceable, and costs are controllable.
For developers, the key to understanding this shift is to distinguish three types of capability:
- Understanding and reasoning: identifying problem constraints and performing multi-step derivation.
- Generation and coding: producing structured text or executable code.
- Action and orchestration: calling tools according to a plan and adjusting the next step based on returned results.
Only when these three capabilities are combined can a model complete end-to-end tasks. If any link is missing, the system is likely to fail in real-world scenarios. For example, with generation capability but no validation, generated code may not run; with reasoning capability but no tool calling, the model cannot read the latest data.
2. Capability Breakdown: Reasoning, Coding, and Task Execution
2.1 Logical Reasoning
Reasoning capability is reflected in whether the model can comply with complex constraints. Take official document writing as an example. A notice needs to satisfy title format, issuing authority, document hierarchy, time elements, and tone requirements at the same time. If the model focuses only on “looking right,” it may miss one of the constraints. A common engineering practice is to break constraints into a checklist, require the model to check the output item by item, and append a self-check conclusion at the end.
2.2 Code Generation and Debugging
The core of code tasks is runnability and maintainability. After the model generates code, unit tests should be executed immediately in an isolated environment, and error messages should be fed back to the model for repair. Generation, execution, and feedback form a closed loop. This approach is more reliable than relying on a one-shot model output.
2.3 Tool Calling and Task Orchestration
Tool calling means the model outputs structured function parameters, and then the host program performs real operations, such as querying a database, reading documents, or submitting tickets. The host program must validate parameters and control permissions. Model output cannot be executed directly as trusted instructions.
3. Mixture of Experts: Trading Division of Labor for Efficiency
Mixture of Experts (MoE) is a common model architecture. The model contains multiple “expert” subnetworks, and a router selects a small number of experts for each input token to participate in computation. As a result, the total parameter count can be large, while the number of parameters actually activated per inference is smaller.
It can be understood as a triage desk: different problems are assigned to the group best suited to handle them, and other groups do not participate in computation. The benefit is that each unit of computation can carry more knowledge capacity, and inference speed is relatively faster. The costs are also clear:
- Memory usage is still related to the total parameter count, so deployment requires sufficient GPU memory or distributed resources.
- The router may experience load imbalance, with some experts overloaded and others idle, so training usually needs balancing constraints.
- In multi-GPU inference, communication overhead between experts affects latency.
The following illustrative code shows the basic idea of top-k routing for understanding the principle. It does not represent any specific implementation:
import mathdef top_k_route(logits, k=2):"""Perform top-k selection on expert scores for a single token and apply softmax normalization to the selected experts."""ranked = sorted(range(len(logits)), key=lambda i: logits[i], reverse=True)[:k]top_scores = [logits[i] for i in ranked]max_s = max(top_scores)exps = [math.exp(s - max_s) for s in top_scores]total = sum(exps)weights = [e / total for e in exps]return ranked, weightslogits = [0.1, 2.3, -0.5, 1.7, 0.4, 0.9, -1.2, 0.0]experts, weights = top_k_route(logits, k=2)print("Selected experts:", experts, "Weights:", [round(w, 3) for w in weights])
After running it, you get two selected experts and their normalized weights, whose sum is 1. The final output is the weighted sum of the outputs of these two experts.
4. Speed and Cost: Measuring with Reproducible Metrics
When selecting models, you should not rely only on marketing claims. Instead, use unified metrics and measure them yourself. Common metrics include:
- Time to First Token: the time from submitting a request to receiving the first output token, which directly affects the interactive experience.
- Output throughput (tokens per second): the number of tokens generated per second, which affects the completion time for long text.
- Cost per request: the number of input tokens and output tokens multiplied by their respective unit prices, then summed.
Most services use different unit prices for input and output, and output is usually more expensive. Therefore, prompts such as “first list an outline, then expand” increase output cost and require a trade-off between quality and expense.
The following is a cost estimation function. The unit prices are placeholder parameters and must be replaced with actual prices when used:
def estimate_cost(input_tokens: int, output_tokens: int,price_in_per_m: float, price_out_per_m: float) -> float:"""Estimate the cost of a single request. Price units must match the return value."""return (input_tokens / 1_000_000) * price_in_per_m \+ (output_tokens / 1_000_000) * price_out_per_mcost = estimate_cost(3_000, 1_200, price_in_per_m=1.0, price_out_per_m=2.0)print(f"Estimated cost per request: {cost:.6f}")
By integrating this calculation into the logging system, you can calculate monthly costs by business line and adjust the model tier accordingly.
5. Model Selection: Trade-offs Between Flagship and Lightweight Models
Model selection is essentially a balance among quality, speed, and cost. A layered strategy can be used:
- For complex reasoning, long-chain planning, and high-risk content review, use stronger large-parameter models.
- For standardized tasks such as batch summarization, format conversion, and keyword extraction, use lightweight models.
- For latency-sensitive interactive scenarios, first measure Time to First Token, then decide whether caching or streaming output is needed.
The selection process should follow four fixed steps: define an evaluation set, run multiple candidate models on the same data, record quality and cost, and make a decision based on deployment constraints. The evaluation set should include real business samples and cover both common and boundary cases. It should not rely only on public leaderboard scores.
6. Practical Implementation: Formal Official Document Writing as an Example
Formal official document writing has strict requirements for format and tone, making it a typical scenario for LLM deployment. Implementation should follow a defined sequence of steps.
