スキル一覧に戻る
YvodeRooij

langchain-patterns

by YvodeRooij

0🍴 0📅 2026年1月20日
GitHubで見るManusで実行

SKILL.md


name: langchain-patterns description: Apply LangChain and LangGraph best practices and patterns triggers:

  • "langchain"
  • "langgraph"
  • "agent"
  • "tool"
  • "state"
  • "graph"

LangChain/LangGraph Patterns Skill

This skill provides guidance on implementing LangChain and LangGraph patterns correctly.

When to Activate

Automatically activate when working on:

  • Agent definitions
  • State graphs
  • Tool implementations
  • Multi-agent orchestration

Key Patterns

1. State Annotation (LangGraph)

Always use Annotation.Root with proper reducers for lists:

import { Annotation } from "@langchain/langgraph";

const MyState = Annotation.Root({
  // Simple fields - no reducer needed
  query: Annotation<string>(),

  // List fields - MUST have reducer to accumulate
  results: Annotation<Result[]>({
    reducer: (a, b) => [...a, ...b]
  }),

  // Set-like accumulation
  tags: Annotation<string[]>({
    reducer: (a, b) => [...new Set([...a, ...b])]
  }),
});

2. Tool Definition (@langchain/core)

Use the modern tool() function with Zod:

import { tool } from "@langchain/core/tools";
import { z } from "zod";

export const myTool = tool(
  async ({ query, limit }) => {
    // Implementation
    return JSON.stringify(results);
  },
  {
    name: "search_database",
    description: "Search the database for records matching the query",
    schema: z.object({
      query: z.string().describe("The search query"),
      limit: z.number().default(10).describe("Max results to return"),
    }),
  }
);

3. Model Selection

Match model to task complexity:

Task TypeRecommended ModelThinking Level
Planning/Strategygemini-3-pro / claude-opus-4high
Execution/Classificationgemini-3-flashmedium
QA/Evaluationclaude-sonnet-4high
Simple/Fastgemini-3-flashminimal

4. Graph Construction

import { StateGraph } from "@langchain/langgraph";

const workflow = new StateGraph(MyState)
  .addNode("process", processNode)
  .addNode("validate", validateNode)
  .addEdge("__start__", "process")
  .addConditionalEdges("process", routingFunction, {
    success: "validate",
    retry: "process",
    fail: "__end__",
  })
  .addEdge("validate", "__end__");

const app = workflow.compile({
  checkpointer: new MemorySaver(),
  interruptBefore: ["human_review"], // For HITL
});

5. Parallel Execution

For independent tasks, use Promise.all:

const results = await Promise.all(
  batches.map(batch =>
    processSubagent(batch)
  )
);

6. Checkpointing

Always checkpoint before risky operations:

// Save state before batch processing
await checkpointer.put(threadId, checkpoint);

try {
  // Risky operation
} catch (error) {
  // Restore from checkpoint
  const saved = await checkpointer.get(threadId);
}

Common Mistakes to Avoid

  1. Missing reducers on array state fields
  2. Using old imports from langchain instead of @langchain/core
  3. Skipping checkpoints in long-running operations
  4. Single agent for 100+ items - use subagents pattern
  5. No thinking configuration for complex tasks

スコア

総合スコア

50/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です