langchain

โดย langchain-ai

สร้างเอเจนต์ด้วยสถาปัตยกรรมและการผสานรวมที่สร้างไว้ล่วงหน้าสำหรับโมเดลหรือเครื่องมือใดๆ ใช้เมื่อสร้างเอเจนต์ที่เรียกใช้เครื่องมือ เปลี่ยนผู้ให้บริการโมเดล หรือเพิ่ม…

npx skills add https://github.com/langchain-ai/docs --skill langchain

LangChain

LangChain is an open-source framework with a prebuilt agent architecture and integrations for any model or tool. Build agents and LLM-powered applications in under 10 lines of code, with integrations for OpenAI, Anthropic, Google, and hundreds more.

When to use

Use LangChain when you need to:

  • Build tool-calling agents with create_agent() and a prebuilt agent loop
  • Switch model providers without changing application code via init_chat_model()
  • Add structured output to parse LLM responses into typed objects
  • Integrate with any model or tool using LangChain's provider packages
  • Use middleware for cross-cutting concerns like rate limiting and caching

When NOT to use

  • For complex multi-step workflows with custom control flow, use LangGraph instead
  • For a batteries-included agent with planning, subagents, and context management, use Deep Agents instead
  • LangChain provides the core building blocks; LangGraph adds orchestration; Deep Agents adds high-level capabilities on top

Install

# Python
pip install -U langchain

# JavaScript/TypeScript
npm install langchain @langchain/core

Install a provider integration:

# Python
pip install -U langchain-openai       # or langchain-anthropic, langchain-google-genai

# JavaScript/TypeScript
npm install @langchain/openai         # or @langchain/anthropic, @langchain/google-genai

Quick reference

Create an agent

from langchain.agents import create_agent

def get_weather(city: str) -> str:
    """Get weather for a given city."""
    return f"It's always sunny in {city}!"

agent = create_agent(
    model="openai:gpt-5.5",
    tools=[get_weather],
    system_prompt="You are a helpful assistant",
)

result = agent.invoke(
    {"messages": [{"role": "user", "content": "What is the weather in SF?"}]}
)

Initialize a chat model

from langchain.chat_models import init_chat_model

# Switch providers by changing the string
model = init_chat_model("openai:gpt-5.5")
model = init_chat_model("anthropic:claude-opus-4-8")
model = init_chat_model("google_genai:gemini-3.6-flash")

Define a tool

from langchain.tools import tool

@tool
def search(query: str) -> str:
    """Search the web for information."""
    return "search results"

Gotchas

  1. Snake_case tool names—Tool function names must be valid Python identifiers. Use get_weather, not get-weather.
  2. Reserved parameters—Do not name tool parameters type, name, or description as these conflict with the tool schema.
  3. Provider packages—Models live in separate packages (e.g., langchain-openai). The base langchain package does not include providers.
  4. Model string format—Use "provider:model-name" format with init_chat_model() (e.g., "openai:gpt-5.5").

Key documentation

API reference

For SDK class and method details, use the LangChain API Reference site:

  • Browse: https://reference.langchain.com/python/langchain-core
  • MCP server: https://reference.langchain.com/mcp

Related skills

  • langgraph—Low-level orchestration for stateful, durable agent workflows
  • deep-agents—Batteries-included agent harness built on LangChain
  • langsmith—Trace, evaluate, and deploy your LangChain agents

Skills เพิ่มเติมจาก langchain-ai

deepagents-thread-inspector
langchain-ai
ตรวจสอบและอธิบายบทสนทนาในคลังเก็บเซสชัน SQLite ของ Deep Agents Code ในเครื่อง ใช้เป็นตัวสำรองเมื่อเครื่องมือติดตาม LangSmith ไม่พร้อมใช้งาน สำหรับ...
deepagents-python-quickstart
langchain-ai
สร้าง Deep Agent ขนาดเล็กในเครื่องของคุณโดยใช้ Python ตามคู่มือเริ่มต้นใช้งานอย่างเป็นทางการ โดยใช้การค้นหาเว็บแบบดั้งเดิมของผู้ให้บริการแทน Tavily ใช้เมื่อผู้ใช้ต้องการ…
deepagents-typescript-quickstart
langchain-ai
สร้าง Deep Agent ภายในเครื่องขั้นต่ำใน TypeScript โดยทำตามคู่มือเริ่มต้นอย่างเป็นทางการ โดยใช้การค้นหาเว็บแบบเนทีฟของผู้ให้บริการแทน Tavily ใช้เมื่อผู้ใช้...
eval-engineering
langchain-ai
ตรวจสอบ agent repository และ traces ที่ผู้ใช้ให้มา (ถ้ามี) แบบวนซ้ำ สัมภาษณ์ผู้ใช้ และสร้าง รัน และตรวจสอบ Harbor evals ทีละรายการ ใช้สำหรับ…
LangChain RAG Pipeline
langchain-ai
ใช้ทักษะนี้เมื่อสร้างระบบการสร้างเสริมการค้นคืน (RAG) ใดๆ ครอบคลุมตัวโหลดเอกสาร, RecursiveCharacterTextSplitter, การฝังข้อความ (OpenAI),…
LangChain Structured Output & HITL
langchain-ai
langchain-structured-output-&-hitl — ทักษะที่สามารถติดตั้งได้สำหรับเอเจนต์ AI เผยแพร่โดย langchain-ai/langchain-skills
LangSmith Datasets
langchain-ai
เรียกใช้สกิลนี้เมื่อสร้างชุดข้อมูลประเมินผลจาก trace หรืออัปโหลดชุดข้อมูลไปยัง LangSmith หรือสอบถามชุดข้อมูล ครอบคลุมประเภทชุดข้อมูล (final_response, …)
langsmith-evaluator
langchain-ai
เรียกใช้สกิลนี้เมื่อสร้างไปป์ไลน์การประเมินสำหรับ LangSmith ครอบคลุมสามองค์ประกอบหลัก: (1) การสร้างตัวประเมิน - LLM-as-Judge, โค้ดที่กำหนดเอง; (2)…