Back to blog
    LangGraph 智能体微调模型:替换智能体技术栈中的 GPT-4
    langgraphagentsfine-tuninglocal-modelssegment:developer

    LangGraph 智能体微调模型:替换智能体技术栈中的 GPT-4

    LangGraph 智能体默认使用 GPT-4,但大多数智能体任务——路由、工具选择、回复生成——用针对特定工作流训练的微调模型效果更好。

    EErtas Team·

    LangGraph 是 2026 年构建有状态 AI 智能体的主流框架。每个 LangGraph 教程的默认模式:ChatOpenAI(model="gpt-4o") 作为推理引擎。每个需要思考、路由、总结或生成的节点都调用 GPT-4。每次调用都花钱。

    大多数 LLM 调用不需要 GPT-4。它们需要了解您特定工具、特定路由逻辑和特定输出格式的模型。这就是微调给您的。

    混合架构

    User Input
        │
        ▼
    [Router Node] ← 微调 8B(分类)
        │
        ├── 路径 A: 简单查询
        │   └── [Response Node] ← 微调 8B
        │
        ├── 路径 B: 需要工具的查询
        │   ├── [Tool Selection] ← 微调 8B(结构化输出)
        │   └── [Response Node] ← 微调 8B
        │
        └── 路径 C: 复杂推理
            └── [Analysis Node] ← GPT-4o
    

    80-90% 的请求走路径 A 或 B——完全由微调模型处理。API 账单降低 80-90%。

    从智能体追踪中训练

    LangGraph 每次执行都产生完整追踪——每个节点的输入输出。这些追踪就是您的训练数据集。

    在 GPT-4 上运行智能体 2-4 周后,您将拥有数千个追踪执行,每个节点都有现成的训练数据。

    使用 Ollama 直接替换

    # Before:
    from langchain_openai import ChatOpenAI
    llm = ChatOpenAI(model="gpt-4o", temperature=0)
    
    # After:
    from langchain_ollama import ChatOllama
    llm = ChatOllama(model="fine-tuned-router", temperature=0)

    费用影响

    客服智能体每天 1,000 个任务,平均每任务 8 次 LLM 调用:

    配置月费用
    全部 GPT-4o$1,500-$3,000/月
    混合(80% 本地)$450-$900/月(降低 70%)
    全部本地(带云降级)$225-$375/月(降低 85-90%)

    Ship AI that runs on your users' devices.

    Ertas early bird pricing starts at $14.50/mo — locked in for life. Plans for builders and agencies.

    延伸阅读

    Ship AI that runs on your users' devices.

    Early bird pricing starts at $14.50/mo — locked in for life. Plans for builders and agencies.

    Keep reading