Fixing Chain-of-Thought Language Drift in AI Agents After Tool Calls
This article explains why an AI agent’s chain-of-thought can switch from Chinese to English after a tool call, why static prompt constraints often fail, and how a pre-reasoning hook with an idempotent constraint slot can reinforce the reasoning language on every turn. It also covers policy design, implementation steps, validation, monitoring, and boundary practices for stable reasoning in Chinese-language tasks.
Problem Symptoms and Impact
In agent tool-calling scenarios, a common but easily overlooked issue is that the model can follow instructions and complete its chain-of-thought in Chinese during the initial stage of a conversation. Once any tool call is triggered—such as reading a file, retrieving code, querying data, or performing a browser operation—the next round of chain-of-thought often switches automatically to English and continues in English in subsequent rounds. Even if a conversational instruction again asks the model to “think in Chinese,” the model may recover only briefly during the round in which the language switch is requested, then return to English reasoning by following the English content in recent context.
This phenomenon is not a traditional software defect. It is inherent behavior of large models that “prefer to follow the language characteristics of recent context.” Tool descriptions, tool return values, logs, code snippets, and error messages often contain a large amount of English. These contents sit at the tail of the context and exert a stronger language pull on the next generation. For tasks such as Chinese content creation, Chinese business logic processing, Chinese customer service script generation, and Chinese review rule explanation, an English chain-of-thought can lead to awkward expression, unnatural terminology explanations, and business logic that does not match Chinese usage conventions. It also reduces the readability and auditability of the reasoning process.
Root Cause: Recent Context Language Dominance
The conditional generation process of large models depends on statistical features in the context. Messages closer to the end of the request usually have a more direct impact on the next output, and tool call results happen to be located at the tail of the context. When tool results contain many English identifiers, English descriptions, and English logs, the model treats this content as the main evidence of the current language environment and continues English in the internal reasoning stage. The “thinking language” here is not an explicit switch exposed by the model. It is a generation tendency shaped jointly by the language distribution of the context, the position of instructions, and recent content.
Therefore, the key issue is not that the model “does not obey Chinese instructions,” but that the constraint appears in the wrong position and at the wrong time. The initial system prompt is located at the top of the context. As conversation rounds increase, its relative attention weight is continuously diluted. After tool results are backfilled, recent English content becomes the dominant signal. If the constraint appears only once at the beginning of the session, it is difficult for it to continue to take effect before every round of reasoning.
Why Existing Constraint Approaches Fail
Static prompt constraints are the most common approach: adding a rule such as “you must think in Chinese” to the agent description or system prompt. This approach may work in the first one or two rounds of a conversation, but after a tool call, recent English content has higher priority, and top-level rules struggle to cover tail language features. Rule-guidance constraints, such as requiring a fixed Chinese prefix at the beginning of the chain-of-thought, have a similar problem: the model may copy a Chinese prefix and then continue reasoning in English. After a tool call, front-loaded rules are even more easily overwritten by the latest context.
The common weakness of both approaches is that they only change the initial context. They do not change the constraint structure used when each round’s request is assembled. To stabilize Chinese reasoning, it is necessary to find an injection point that executes automatically before every round of reasoning and dynamically sets the language policy after tool results are backfilled and before the model request is sent.
General Injection Point: Pre-Reasoning Hook
In a typical agent orchestration framework, the lifecycle usually includes message assembly, a pre-reasoning hook, model request, tool call, tool result backfill, and the next reasoning round. The pre-reasoning hook is triggered before every model reasoning step and is not affected by conversation round or context content. It is therefore an ideal constraint injection point. Its key value is that it sits before each round’s request is sent and can re-declare the current round’s chain-of-thought language policy even after tool results have already entered the context.
Pseudocode example:
def register_hooks(agent):agent.on("before_reasoning", inject_reasoning_language_policy)def inject_reasoning_language_policy(ctx):task_lang = ctx.task_profile.get("reasoning_language", "zh")if task_lang != "zh":returnpolicy = ("This round's chain-of-thought must be completed in Chinese. ""English content returned by tools is only referenced facts and raw material; it does not change the reasoning language. ""Code, paths, API identifiers, and original log text may remain in English, but explanations, judgments, and the reasoning process must use Chinese.")# Use replacement rather than append to avoid context bloat from repeated injection.ctx.set_constraint_slot(key="reasoning_language_policy",content=policy,mode="replace")ctx.set_metadata("reasoning_language", "zh")
The code above is generic pseudocode. The key point is “replace the constraint slot before every round of reasoning.” A real implementation can use the message construction capabilities of the framework in use. The constraint slot should remain idempotent: keep only one language policy per session per round instead of continuously appending new rules.
Constraint Content Design and Implementation Steps
The constraint content should not merely say “think in Chinese.” It should cover task language, tool result handling, terminology preservation, and output consistency. It is recommended to include: this round’s chain-of-thought uses Chinese; English returned by tools is only factual input; code, paths, logs, and identifiers may retain their original text; English terms may include a Chinese note on first appearance; and the final user-facing output language matches the task language. Implementation steps include: identify the task language and write it to session metadata; register the pre-reasoning hook; construct a short policy in the hook; write it into the constraint slot in replace mode; record injection hits and the language policy; and provide a switch for fallback. For multilingual tasks, the reasoning language should be determined by a task-level policy rather than by forcing Chinese globally.
Validation, Monitoring, and Boundary Practices
For validation, compare the static prompt approach with pre-reasoning injection. Observe the language drift ratio in the first round after a tool call, the proportion of Chinese in the chain-of-thought, the quality of Chinese task output, and the tool call success rate. For monitoring, record the number of injections per round, the length of the policy slot, context increment, and abnormal fallback cases, and set alerts in combination with general logging and monitoring capabilities. Note that forcing Chinese should not affect code, paths, or original log text. Hook exceptions should be isolated and fall back to the default policy. The policy should be short and written in replace mode to avoid context bloat. The pre-reasoning hook does not replace the top-level prompt. It works together with it to form a stable mechanism of “top-level baseline plus per-round reinforcement.” By combining lifecycle injection points, idempotent policy slots, and task language policies, it is possible to significantly reduce chain-of-thought language drift after tool calls and improve reasoning stability and output quality in Chinese scenarios.
