跳到主要内容
LangSmith Studio 提供了检查、调试和改进应用程序的工具,超越了执行阶段。通过使用跟踪、数据集和提示,您可以详细了解应用程序的行为、衡量其性能并优化其输出。

迭代提示

Studio 支持以下修改图中提示的方法

直接节点编辑

Studio 允许您直接从图界面编辑单个节点中使用的提示。

图配置

定义您的配置,使用 langgraph_nodeslanggraph_type 键指定提示字段及其关联节点。

langgraph_nodes

  • 描述:指定配置字段与图的哪些节点关联。
  • 值类型:字符串数组,其中每个字符串是图中节点的名称。
  • 使用上下文:包含在 Pydantic 模型的 json_schema_extra 字典或数据类的 metadata["json_schema_extra"] 字典中。
  • 示例:
    system_prompt: str = Field(
        default="You are a helpful AI assistant.",
        json_schema_extra={"langgraph_nodes": ["call_model", "other_node"]},
    )
    

langgraph_type

  • 描述:指定配置字段的类型,它决定了在 UI 中如何处理它。
  • 值类型:字符串
  • 支持的值:
    • "prompt":表示字段包含应在 UI 中特殊处理的提示文本。
  • 使用上下文:包含在 Pydantic 模型的 json_schema_extra 字典或数据类的 metadata["json_schema_extra"] 字典中。
  • 示例:
    system_prompt: str = Field(
        default="You are a helpful AI assistant.",
        json_schema_extra={
            "langgraph_nodes": ["call_model"],
            "langgraph_type": "prompt",
        },
    )
    
## Using Pydantic
from pydantic import BaseModel, Field
from typing import Annotated, Literal

class Configuration(BaseModel):
    """The configuration for the agent."""

    system_prompt: str = Field(
        default="You are a helpful AI assistant.",
        description="The system prompt to use for the agent's interactions. "
        "This prompt sets the context and behavior for the agent.",
        json_schema_extra={
            "langgraph_nodes": ["call_model"],
            "langgraph_type": "prompt",
        },
    )

    model: Annotated[
        Literal[
            "anthropic/claude-sonnet-4-5-20250929",
            "anthropic/claude-haiku-4-5-20251001",
            "openai/o1",
            "openai/gpt-4o-mini",
            "openai/o1-mini",
            "openai/o3-mini",
        ],
        {"__template_metadata__": {"kind": "llm"}},
    ] = Field(
        default="openai/gpt-4o-mini",
        description="The name of the language model to use for the agent's main interactions. "
        "Should be in the form: provider/model-name.",
        json_schema_extra={"langgraph_nodes": ["call_model"]},
    )

## Using Dataclasses
from dataclasses import dataclass, field

@dataclass(kw_only=True)
class Configuration:
    """The configuration for the agent."""

    system_prompt: str = field(
        default="You are a helpful AI assistant.",
        metadata={
            "description": "The system prompt to use for the agent's interactions. "
            "This prompt sets the context and behavior for the agent.",
            "json_schema_extra": {"langgraph_nodes": ["call_model"]},
        },
    )

    model: Annotated[str, {"__template_metadata__": {"kind": "llm"}}] = field(
        default="anthropic/claude-3-5-sonnet-20240620",
        metadata={
            "description": "The name of the language model to use for the agent's main interactions. "
            "Should be in the form: provider/model-name.",
            "json_schema_extra": {"langgraph_nodes": ["call_model"]},
        },
    )

在 UI 中编辑提示

  1. 在具有相关配置字段的节点上找到齿轮图标。
  2. 单击以打开配置模式。
  3. 编辑值。
  4. 保存以更新当前助手版本或创建新版本。

Playground

Playground 界面允许测试单个 LLM 调用,而无需运行整个图
  1. 选择一个线程。
  2. 单击节点上的查看 LLM 运行。这会列出节点内进行的所有 LLM 调用(如果有)。
  3. 选择一个 LLM 运行以在 playground 中打开。
  4. 修改提示并测试不同的模型和工具设置。
  5. 将更新后的提示复制回您的图。

对数据集运行实验

Studio 允许您通过根据预定义的 LangSmith 数据集执行您的助手来运行评估。这使您可以测试各种输入下的性能,将输出与参考答案进行比较,并使用配置的评估器对结果进行评分。 本指南向您展示了如何直接从 Studio 运行完整的端到端实验。

先决条件

在运行实验之前,请确保您拥有以下内容
  • LangSmith 数据集:您的数据集应包含您要测试的输入,以及可选的用于比较的参考输出。输入的模式必须与助手的所需输入模式匹配。有关模式的更多信息,请参阅此处。有关创建数据集的更多信息,请参阅如何管理数据集
  • (可选)评估器:您可以在 LangSmith 中将评估器(例如,作为评判者的 LLM、启发式方法或自定义函数)附加到您的数据集。这些将在图处理完所有输入后自动运行。
  • 正在运行的应用程序:实验可以针对以下对象运行:

实验设置

  1. 启动实验。单击 Studio 页面右上角的运行实验按钮。
  2. 选择您的数据集。在弹出的模式窗口中,选择用于实验的数据集(或特定的数据集拆分),然后单击开始
  3. 监控进度。数据集中的所有输入现在都将针对活动助手运行。通过右上角的徽章监控实验进度。
  4. 您可以在 Studio 中继续工作,而实验在后台运行。随时单击箭头图标按钮以导航到 LangSmith 并查看详细的实验结果。

调试 LangSmith 跟踪

本指南解释了如何在 Studio 中打开 LangSmith 跟踪以进行交互式调查和调试。

打开已部署的线程

  1. 打开 LangSmith 跟踪,选择根运行。
  2. 单击在 Studio 中运行
这将打开连接到关联部署的 Studio,并选中跟踪的父线程。

使用远程跟踪测试本地代理

本节解释了如何根据 LangSmith 中的远程跟踪测试本地代理。这使您可以将生产跟踪用作本地测试的输入,从而允许您在开发环境中调试和验证代理修改。

先决条件

本地代理要求
  • langgraph>=0.3.18
  • langgraph-api>=0.0.32
  • 包含与远程跟踪中存在的节点集相同

克隆线程

  1. 打开 LangSmith 跟踪,选择根运行。
  2. 点击在 Studio 中运行旁边的下拉菜单。
  3. 输入您本地代理的 URL。
  4. 选择本地克隆线程
  5. 如果存在多个图,请选择目标图。
您的本地代理中将创建一个新线程,其线程历史记录将从远程线程推断和复制,并且您将被导航到 Studio 以查看您本地运行的应用程序。

将节点添加到数据集

从线程日志中的节点向 LangSmith 数据集添加示例。这对于评估代理的单个步骤很有用。
  1. 选择一个线程。
  2. 单击添加到数据集
  3. 选择要将其输入/输出添加到数据集的节点。
  4. 对于每个选定的节点,选择目标数据集以创建示例。默认情况下,将选择特定助手和节点的数据集。如果此数据集尚不存在,则会创建它。
  5. 在将示例添加到数据集之前,根据需要编辑示例的输入/输出。
  6. 选择页面底部的添加到数据集以将所有选定节点添加到各自的数据集。
有关更多详细信息,请参阅如何评估应用程序的中间步骤
以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.