在我们的文档代理的轨迹上微调一个开放模型
Fine-tuning an open model on our docs agent's traces
导读
LangChain Labs 将基于 GLM 5.3 Flash 微调的模型部署为旗下文档问答代理 Chat LangChain 的主力模型。该微调模型用 Chat LangChain 自身生产轨迹构建的任务训练,在 128 条真实用户问题的基准测试中得分 0.735,高于基础模型 GLM 5.3 Flash 的 0.679,接近 GPT-6.1 Sol 的 0.748,而成本比 GPT-6.1 Sol 低 83%。
正在把原文翻译成中文,长文需要一两分钟;先显示原文。
LangChain Labs
Create agents
Create agents
Key Takeaways
- Production traces let you build a benchmark you can hill-climb to post-train a model.
- Offline evals need headroom to show whether training actually moved the model.
- The training and eval environment needs to match production.
- Online evals on the fine-tune in production build confidence before it takes all the traffic.
We've deployed a fine-tuned version of GLM 5.3 Flash as the main model in Chat LangChain, our agent that answers questions about the LangChain stack from our documentation and our public support knowledge base.
We trained it on tasks built from Chat LangChain's own production traces. We tested it on a benchmark of 128 real user questions. Each answer scores 1 if it is correct and complete, 0 if it falls short, and −0.5 if it is confidently wrong. A model's score is its average over 8 attempts at each question. The fine-tune scores 0.735, up from 0.679 for the base model and close to GPT-6.1 Sol's 0.748. It is 83% cheaper than GPT-6.1 Sol.

Held-out score against cost per 1,000 questions for each model
The benchmark result was strong enough to put the fine-tune in front of users, so we ran it in production alongside base GLM 5.3 Flash and Gemini 3.5 Flash Lite, the model it replaced, and measured all three with online evals. The fine-tune's answers were the most grounded in our docs of the three, and users came back with a follow-up question less often than they did with Gemini (36% of threads against 41%). It answers about twice as slowly as Gemini but costs less to run, at $12 per 1,000 questions against $20.
Why we tried an open model
Frontier models answered our docs questions well but cost too much to run on every question. Sonnet 5.5 costs $192 per 1,000 questions and Opus 5.5 costs $330, against $20 for Gemini 3.5 Flash Lite, our production model at the time. Base GLM 5.3 Flash costs $9 per 1,000 questions but scored well behind GPT-6.1 Sol on our benchmark. We wanted to find out whether training on Chat LangChain's own traffic could close that gap.
Building a benchmark from production traces
We started from Chat LangChain's production traces. An internal agent we're developing grouped them into usage patterns and built tasks from those groups so the benchmark covers how people actually use the agent. Every task has an answer key, and automated graders we call verifiers score the agent's answer against it. We split the tasks into a training set and a held-out set of 128, and the held-out set became the benchmark.
Agent runs are hard to compare when the tools and data they depend on keep changing, so our agent built a mocked environment for the Chat LangChain agent to run in. It mirrors how Chat LangChain is configured in production, which means a change in score comes from the model rather than from the environment.

How Chat LangChain is put together: the model, the harness with its middleware and tools, and the data sources it searches
With the benchmark built, we calibrated it. We checked that it ranks stronger models above weaker ones, as the chart in the intro shows, and that the verifiers give the same score when they grade the same run twice. We also had a model review the verifiers' decisions. Each run surfaced errors in tasks or verifiers, and we kept fixing them until a run turned up none.
The held-out questions resemble production traffic, but the set is harder on purpose. We picked 78 of the 128 tasks because the base model struggled with them, which leaves room to see whether training moves the score.
Training
We tried three training methods. They differ in which parts of a trajectory get a training signal, and that decided how much extra research each one taught the model.

Which parts of a trajectory each method trains on
SFT
Our teacher was the larger GLM 5.3, whose trajectories in our training data averaged 8 tool calls per question.
- The score rose by 0.052.
- The student made 14.5 tool calls per question, against 5 for the base model and more than the teacher itself.
- Median latency in our offline test setup went from 17 seconds to 75, which is too slow for chat.
- Self-distillation, where the base model trains on its own trajectories, changed its behavior much less. It raised the score by only 0.014.
GRPO
- The score rose by 0.037.
- Attempts that made more tool calls tended to score higher, so the model learned to research more. It made 42% more tool calls and took 40% more turns.
- Soft penalties on tool calls didn't hold research down, and the model still roughly doubled its calls.
- Hard caps and strong efficiency weights cut research so far that the score fell below the base model's.
- It cost more to train than SFT.
Answer-only DPO
Only the final answer is trained, so the research steps get no direct signal. We took the candidate answers from the base model, because the best of its four attempts at each question scores 0.914, against about 0.7 for a single attempt. Some hand annotation and a council of judge models picked the better answer in each pair.
- It gave the largest gain, 0.056 over the base model, and it's the version we deployed.
- Research still went up, with 33% more tool calls and 25% more turns, but far less than with teacher SFT.
- About one in five rejected answers was a confident claim that something doesn't exist, made after a shallow search. Our best explanation is that learning to avoid them taught the model not to stop searching early.
Answer-only DPO raised the score the most, and it added far less research than teacher SFT or GRPO.

Change in score against change in tool calls for each training method
What production showed
To see how the fine-tune did with real users, we split Chat LangChain's traffic evenly between the fine-tune, base GLM 5.3 Flash, and Gemini 3.5 Flash Lite, and scored every response with online evals in LangSmith.

Online eval results for the fine-tune, base GLM 5.3 Flash, and Gemini 3.5 Flash Lite
Groundedness measures whether an answer is supported by the docs the agent retrieved. The fine-tune led on groundedness every day of the test.
We also had a model judge read the three answers to each question and pick the best one. On most questions the answers were similar, but where they differed in substance, the judge picked a GLM model 82% of the time across 119 comparisons, split evenly between the fine-tune and the base model.
Online evals also caught a latency problem. In the first days of the test, 18.7% of the fine-tune's runs took longer than 30 seconds. To combat this, we added an instruction to keep answers concise, and over the next six days that share fell to 5.9%, close to base GLM's 5.4%.
We chose the fine-tune even though it answers more slowly than Gemini. For a docs assistant, a wrong answer costs a user more than a few extra seconds, since they may go on to build with an API that doesn't exist, and the fine-tune beat Gemini on every quality measure while costing less to run.
What's next
The fine-tune is now Chat LangChain's main model, and we'll keep feeding new production traces and online eval results back into its training data.
If you want to fine-tune the model behind your own agent on its production traces, reach out and we'll help you get started!
出处
- S 官方LangChain Blog · RSS阅读原文 ↗
Fine-tuning an open model on our docs agent's traces