Files
magnus919_agent-skills/langchain/references/production-deployment.md
T
Magnus Hedemark 7f2842b358 feat: langchain v1.1.0 — research-validated deepening
Major deepening of the langchain expert skill based on source audit against
official LangChain docs (docs.langchain.com, reference.langchain.com).

Changes:
- Added references/validation-audit.md documenting all research findings
- Deepened references/agent-patterns.md from 74 to 200+ lines:
  create_react_agent full parameter table, @tool decorator with
  args_schema/parse_docstring, streaming events, multi-agent supervisor
- Deepened references/lcel-reference.md from 79 to 180+ lines:
  RunnablePassthrough.assign(), RunnableParallel dict shorthand,
  RunnableLambda, RunnableConfig, .with_fallbacks(), .configurable_fields()
- Deepened references/rag-strategies.md with advanced retrieval patterns
- Deepened references/production-deployment.md with LangSmith Datasets/
  Evaluation Runs/Prompt Hub
- Added new references/callbacks.md (BaseCallbackHandler, event table,
  agent auditing patterns, async callbacks)
- Deepened references/faq-and-troubleshooting.md with Pydantic v1/v2,
  streaming+tools, checkpoint serialization guidance

All API surface claims verified against official documentation.
v1.0.3 -> v1.1.0
2026-07-09 14:33:42 -04:00

2.0 KiB

LangChain Production Deployment

LangSmith Observability

Enable tracing at module import time — before any chain or agent instantiation:

import os
os.environ["LANGCHAIN_TRACING_V2"] = "true"
os.environ["LANGCHAIN_API_KEY"] = "your-key"
os.environ["LANGCHAIN_PROJECT"] = "my-project"

LangSmith provides four layers:

1. Tracing

Every chain/agent step is automatically captured: LLM calls, tool invocations, retrievals, latency, token counts. Traces are visible in the LangSmith UI.

2. Evaluation with Datasets

from langsmith import Client

client = Client()
dataset = client.create_dataset("my-eval-set")
client.create_examples(
    inputs=[{"question": "What is RAG?"}],
    outputs=[{"answer": "Retrieval Augmented Generation"}],
    dataset_id=dataset.id,
)

# Run evaluation
results = client.evaluate(
    lambda inputs: chain.invoke(inputs["question"]),
    data="my-eval-set",
    evaluators=[lambda r, ref: r["output"] == ref["answer"]],
)

Evaluation types: LLM-as-judge, heuristic/validation, pairwise comparison, human annotation queues.

3. Prompt Hub

Version-controlled prompt management:

from langchain import hub
prompt = hub.pull("langchain-ai/chat-langchain-rephrase")
hub.push("my-org/my-prompt", prompt)

4. LangSmith Engine

Autonomous issue detection from production traces — clusters failures, finds root cause, proposes fixes.

LangServe Deployment

from langserve import add_routes
from fastapi import FastAPI

app = FastAPI()
add_routes(app, chain, path="/rag")
# Run: uvicorn main:app --port 8080

Production Checklist

  • Enable LangSmith tracing before any code execution
  • Use create_agent not deprecated AgentExecutor
  • Set max_concurrency in RunnableConfig to avoid rate limits
  • Implement fallbacks with .with_fallbacks() for reliability
  • Use cheaper models (gpt-4o-mini) for simple routing tasks
  • Set up LangSmith Datasets for regression testing
  • Use environment variables for all secrets