langchain

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

LangChain

LangChain

Use this skill to build or refactor LangChain application logic with predictable tool use, structured outputs, and clean runtime boundaries.
使用该Skill来构建或重构LangChain应用逻辑,实现可预测的工具调用、结构化输出以及清晰的运行时边界。

Quick Triage

快速判断

  • Use this skill when the task is primarily chain/agent composition, tool calling, middleware, output schemas, or prompt wiring.
  • Switch to
    $langgraph
    when the core problem is graph topology, node routing, checkpoints, interrupts, or multi-step state machines.
  • Switch to
    $ag-ui
    when the core problem is event protocol compliance between backend and UI.
  • Switch to
    $copilotkit
    when the core problem is frontend coagent UX, hooks, and runtime provider wiring.
  • 当任务主要涉及链/Agent组合、工具调用、中间件、输出模式或提示词编排时,使用该Skill。
  • 当核心问题涉及图拓扑、节点路由、检查点、中断或多步骤状态机时,切换至
    $langgraph
  • 当核心问题涉及后端与UI之间的事件协议兼容性时,切换至
    $ag-ui
  • 当核心问题涉及前端协Agent用户体验、钩子函数和运行时提供者编排时,切换至
    $copilotkit

Workflow

工作流

  1. Confirm language/runtime surface first. Choose Python or TypeScript and identify existing package boundaries before code edits.
  2. Define the contract before implementation. Lock input shape, output shape, tool schema, and failure behavior.
  3. Choose abstraction level deliberately. Use simple LCEL chains when tools are not required; use
    create_agent
    when iterative tool use is needed.
  4. Add tools and middleware in a deterministic order. Validate schema compatibility and tool side effects before adding retries or guardrails.
  5. Enforce structured output and state rules. Use explicit schema validation and avoid ad-hoc parsing.
  6. Add observability and limits. Set timeouts, retries, and tracing hooks before rollout.
  7. Verify with focused tests. Run unit tests for tool bindings and integration tests for end-to-end agent loops.
  1. 首先确认语言/运行环境范围。 在编写代码前,选择Python或TypeScript并明确现有包的边界。
  2. 在实现前定义契约。 锁定输入格式、输出格式、工具模式以及故障处理行为。
  3. 谨慎选择抽象层级。 当不需要工具时,使用简单的LCEL链;当需要迭代式工具调用时,使用
    create_agent
  4. 按确定的顺序添加工具和中间件。 在添加重试机制或防护措施前,验证模式兼容性和工具副作用。
  5. 强制执行结构化输出和状态规则。 使用明确的模式验证,避免临时解析。
  6. 添加可观测性和限制措施。 在部署前设置超时、重试和追踪钩子。
  7. 通过针对性测试进行验证。 对工具绑定运行单元测试,对端到端Agent循环进行集成测试。

Default Patterns

默认模式

  • Prefer explicit tool schemas over implicit argument parsing.
  • Keep tool side effects isolated from prompt logic.
  • Keep prompt templates and business logic separate.
  • Validate all structured outputs at boundaries.
  • Keep retries bounded and idempotent.
  • 优先使用明确的工具模式,而非隐式参数解析。
  • 将工具副作用与提示词逻辑隔离。
  • 将提示词模板与业务逻辑分离。
  • 在边界处验证所有结构化输出。
  • 确保重试机制有界且具备幂等性。

Failure Modes

故障模式

  • Tool schema drift between prompt and implementation.
  • Unbounded agent loops due to missing stop conditions.
  • Silent parsing failures from weak output contracts.
  • Middleware order causing policy bypass.
  • State growth without trimming/summarization rules.
  • 提示词与实现之间的工具模式偏差。
  • 因缺少停止条件导致的无界Agent循环。
  • 因输出契约薄弱导致的静默解析失败。
  • 中间件顺序导致的策略绕过。
  • 因缺少裁剪/汇总规则导致的状态膨胀。

Reference Map

参考地图

Load only what is needed for the current subtask.
  • Core workflow patterns:
    references/core-workflows.md
  • Tooling and middleware:
    references/tooling-and-middleware.md
  • Structured output and state:
    references/structured-output-and-state.md
  • Debugging and recovery:
    references/troubleshooting.md
仅加载当前子任务所需的内容。
  • 核心工作流模式:
    references/core-workflows.md
  • 工具与中间件:
    references/tooling-and-middleware.md
  • 结构化输出与状态:
    references/structured-output-and-state.md
  • 调试与恢复:
    references/troubleshooting.md