迭代提示¶
概述¶
LangGraph Studio 支持两种修改图中提示的方法:直接节点编辑和 LangSmith Playground 界面。
直接节点编辑¶
Studio 允许您直接从图界面编辑单个节点中使用的提示。
先决条件
图配置¶
定义您的配置,使用 langgraph_nodes
和 langgraph_type
键指定提示字段及其关联的节点。
配置参考¶
langgraph_nodes
¶
- 描述:指定配置字段与图中的哪些节点关联。
- 值类型:字符串数组,其中每个字符串是图中节点的名称。
- 使用上下文:包含在 Pydantic 模型的
json_schema_extra
字典中,或 dataclasses 的metadata["json_schema_extra"]
字典中。 - 示例:
langgraph_type
¶
- 描述:指定配置字段的类型,该类型决定了它在用户界面中的处理方式。
- 值类型:字符串
- 支持的值:
"prompt"
:表示该字段包含应在用户界面中特殊处理的提示文本。- 使用上下文:包含在 Pydantic 模型的
json_schema_extra
字典中,或 dataclasses 的metadata["json_schema_extra"]
字典中。 - 示例:
配置示例¶
## 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-3-7-sonnet-latest",
"anthropic/claude-3-5-haiku-latest",
"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"]},
},
)
在用户界面中编辑提示¶
- 找到具有关联配置字段的节点上的齿轮图标
- 点击打开配置模态框
- 编辑值
- 保存以更新当前助手版本或创建新版本
LangSmith Playground¶
LangSmith Playground 界面允许测试单个 LLM 调用,而无需运行整个图。
- 选择一个线程
- 在节点上点击“查看 LLM 运行”。这会列出节点内部进行的所有 LLM 调用(如果有)。
- 选择一个 LLM 运行以在 Playground 中打开
- 修改提示并测试不同的模型和工具设置
- 将更新的提示复制回您的图
如需高级 Playground 功能,请点击右上角的展开按钮。