LangSmith Studio 提供工具来检查、调试和改进您的应用程序,超越执行本身。通过使用追踪、数据集和提示,您可以详细了解应用程序的行为,测量其性能,并优化其输出:

迭代提示

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

直接节点编辑

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

图配置

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

langgraph_nodes

  • 描述:指定配置字段与图的哪些节点相关联。
  • 值类型:字符串数组,其中每个字符串是图中节点的名称。
  • 使用上下文:包含在 Pydantic 模型的 json_schema_extra 字典中或 dataclasses 的 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 字典中或 dataclasses 的 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. 在节点上点击 View LLM Runs。这会列出节点内进行的所有 LLM 调用(如果有)。
  3. 选择一个 LLM 运行以在 playground 中打开。
  4. 修改提示并测试不同的模型和工具设置。
  5. 将更新的提示复制回您的图。

在数据集上运行实验

Studio 允许您通过在预定义的 LangSmith 数据集上执行助手来运行评估。这使您能够测试各种输入的性能,将输出与参考答案进行比较,并使用配置的评估器对结果进行评分。 以下步骤将演示如何在 Studio 中完成端到端实验。

先决条件

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

实验设置

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

调试 LangSmith 追踪

本节说明如何在 Studio 中打开 LangSmith 追踪,便于交互式排查与调试。

打开已部署的线程

  1. 打开 LangSmith 追踪,选择根运行。
  2. 点击 Run in Studio
这将打开 Studio,连接到关联的部署,并选择追踪的父线程。

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

本节说明如何针对来自 LangSmith 的远程追踪测试本地代理。这使您能够使用生产追踪作为本地测试的输入,允许您在开发环境中调试和验证代理修改。

先决条件

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

克隆线程

  1. 打开 LangSmith 追踪,选择根运行。
  2. 点击 Run in Studio 旁边的下拉菜单。
  3. 输入您的本地代理 URL。
  4. 选择 Clone thread locally
  5. 如果存在多个图,选择目标图。
将在您的本地代理中创建一个新线程,线程历史从远程线程推断并复制,您将被导航到本地运行应用程序的 Studio。

将节点添加到数据集

从线程日志中的节点向 LangSmith 数据集 添加示例。这对于评估代理的各个步骤很有用。
  1. 选择一个线程。
  2. 点击 Add to Dataset
  3. 选择要将其输入/输出添加到数据集的节点。
  4. 对于每个选定的节点,选择要在其中创建示例的目标数据集。默认情况下,将选择特定助手和节点的数据集。如果此数据集尚不存在,将创建它。
  5. 在将示例添加到数据集之前,根据需要编辑示例的输入/输出。
  6. 在页面底部选择 Add to dataset 以将所有选定的节点添加到其各自的数据集。
有关更多详细信息,请参阅如何评估应用程序的中间步骤
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.