LangSmith สำหรับการติดตามและตรวจสอบ
ใช้ LangSmith เพื่อมองเห็นกระบวนการคิด การใช้เครื่องมือ และลำดับการทำงานโดยรวมของเอเจนต์
LangSmith สำหรับการติดตามและตรวจสอบ เป็นบทเรียน AI Agents with LangChain & Autonomous Workflows ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน AI Agents with LangChain & Autonomous Workflows และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส AI Agents with LangChain & Autonomous Workflows มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Seeing Inside Your Agent
When you build an AI agent, it often feels like a black box. You provide an input, and it gives an output, but what happens in between?
- Did it understand your prompt correctly?
- Which tools did it decide to use?
- Why did it choose that particular action?
Understanding these internal workings is crucial for debugging and improving your agents.
Introducing LangSmith
LangSmith is a developer platform by LangChain, designed specifically for building, debugging, and evaluating Large Language Model (LLM) applications.
It provides the visibility you need to understand your agent's behavior, identify issues, and ensure it performs as expected.
Core Concepts: Traces & Runs
In LangSmith, two key concepts are Runs and Traces:
- A Run represents a single execution of a component, like an LLM call, a tool invocation, or a chain step.
- A Trace is a collection of related runs that together form a complete execution of your agent or application, showing the full sequence of events.
Imagine a trace as a detailed log of your agent's entire thought process and actions.
Setting Up LangSmith
To use LangSmith, you need to set a few environment variables:
LANGCHAIN_TRACING_V2=true: Enables LangSmith tracing.LANGCHAIN_API_KEY: Your unique API key for authentication.LANGCHAIN_PROJECT: A name for your project to group related traces.
You can get your API key from the LangSmith website after signing up.
Enabling Tracing in Code
Let's see how to enable tracing for a simple LangChain application. First, ensure you have your API key and project name set up.
import os
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
# Set these environment variables before running
os.environ["LANGCHAIN_TRACING_V2"] = "true"
os.environ["LANGCHAIN_API_KEY"] = "YOUR_LANGSMITH_API_KEY"
os.environ["LANGCHAIN_PROJECT"] = "MyFirstLangSmithProject"
# Replace with your actual OpenAI API key
os.environ["OPENAI_API_KEY"] = "YOUR_OPENAI_API_KEY"
# Create a simple LLM chain
llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)
prompt = ChatPromptTemplate.from_messages([
("system", "You are a helpful assistant."),
("user", "{question}")
])
chain = prompt | llm
# Invoke the chain
response = chain.invoke({"question": "What is the capital of France?"})
print(response.content)Viewing Your First Trace
After running the previous code, a trace will be sent to your LangSmith project. Navigate to the LangSmith UI (app.langsmith.com) and select your project.
You'll see a visual representation of the 'chain' execution, including:
- The input to the prompt.
- The LLM call itself.
- The final output from the LLM.
Each step is a 'Run' within the 'Trace'.
Understanding Agent Thought Process
For more complex agents, LangSmith shines by showing the agent's thought process. You can see the sequence of:
- Thought: The agent's reasoning.
- Action: The tool it decided to use.
- Action Input: The arguments passed to the tool.
- Observation: The result returned by the tool.
This detailed breakdown helps you understand why an agent made certain decisions.
Monitoring Tool Usage
Agents often rely on various tools (e.g., search engines, calculators, custom APIs). LangSmith traces clearly show:
- Which specific tools were called.
- The exact inputs provided to each tool.
- The outputs received from the tools.
This is invaluable for verifying that your agent is using tools correctly and for debugging when a tool returns an unexpected result.
Debugging with LangSmith Traces
Traces are your best friend for debugging. If your agent behaves unexpectedly:
- Identify the exact step: Pinpoint where the incorrect logic or error occurred.
- Inspect inputs/outputs: Check if the prompt received the expected input or if the tool returned the right output.
- Review agent thoughts: Understand if the agent's reasoning led to a bad decision.
This visibility dramatically reduces debugging time compared to traditional print statements.
Check Your Knowledge
Which of the following is NOT a primary benefit of using LangSmith for AI agents?
Recap: Your Observability Ally
LangSmith is an essential tool for anyone building AI agents with LangChain. It transforms the black box of agent execution into a transparent, inspectable process.
By providing detailed traces of runs, agent thoughts, and tool usage, LangSmith empowers you to debug faster, understand your agents better, and build more robust and reliable AI applications.
คำถามที่พบบ่อย
บทเรียน “LangSmith สำหรับการติดตามและตรวจสอบ” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “LangSmith สำหรับการติดตามและตรวจสอบ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส AI Agents with LangChain & Autonomous Workflows ให้อัปเกรดเป็น CoddyKit PRO คอร์ส AI Agents with LangChain & Autonomous Workflows มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “LangSmith สำหรับการติดตามและตรวจสอบ”
ใช้ LangSmith เพื่อมองเห็นกระบวนการคิด การใช้เครื่องมือ และลำดับการทำงานโดยรวมของเอเจนต์ คุณปฏิบัติ AI Agents with LangChain & Autonomous Workflows ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน AI Agents with LangChain & Autonomous Workflows หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน AI Agents with LangChain & Autonomous Workflows บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน
บทเรียน “LangSmith สำหรับการติดตามและตรวจสอบ” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน AI Agents with LangChain & Autonomous Workflows นี้ได้ไหม
ได้ บทเรียน AI Agents with LangChain & Autonomous Workflows ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- LangSmith สำหรับการติดตามและตรวจสอบ
- การแก้ไขข้อบกพร่องในกระบวนการคิดของเอเจนต์
- การประเมินประสิทธิภาพของเอเจนต์
- การใช้โทเคนและการตรวจสอบค่าใช้จ่าย