AI Agent / Web3·off-chain (any)
LangChain
TypeScript/Python framework for composing LLM apps and agents from interoperable components: chat models, tools, retrievers, and graphs. LangGraph adds stateful, long-running agent orchestration.
- 01LLM agent orchestration
- 02RAG pipelines
- 03multi-step tool use
- 04stateful agent graphs (LangGraph)
- 05provider-agnostic chat models
- pnpm add langchain @langchain/core @langchain/openai @langchain/langgraph
| Variable | Scope | Description |
|---|---|---|
| OPENAI_API_KEY | Server | Provider API key (OpenAI shown; LangChain supports Anthropic, Google, Bedrock, etc.). |
| LANGSMITH_API_KEY | Server | Optional LangSmith tracing/eval key for observability of agent runs. |
Use LangChain JS to build an agent. `import { ChatOpenAI } from '@langchain/openai'; import { tool } from '@langchain/core/tools'; import { createReactAgent } from '@langchain/langgraph/prebuilt';` Define tools with `tool(async (input) => {...}, { name, description, schema: z.object({...}) })`, instantiate `const model = new ChatOpenAI({ model: 'gpt-5' });` and build `const agent = createReactAgent({ llm: model, tools });` then `await agent.invoke({ messages: [{ role: 'user', content: '...' }] })`. For stateful flows use LangGraph's `StateGraph` to express nodes/edges with checkpointed memory.
- ⚑Requires Node.js 20+ for v1; older runtimes silently fail on ESM imports — pin `engines.node` in package.json.
- ⚑Tool-calling reliability varies by model — GPT-5/Claude work well, smaller models often hallucinate tool names; always validate inputs with the Zod schema.
- ⚑LangGraph state is checkpointed in a store (memory, Postgres, Redis) — without a persistent checkpointer, long-running agents lose state on restart.
- ⚑Provider packages (`@langchain/openai`, `@langchain/anthropic`) must match the core version; mismatched semvers cause cryptic runtime type errors.
- ⚑Streaming token-by-token from agents requires `streamMode: 'values'` or `'updates'` on `agent.stream(...)`; defaults emit only final messages.
- ⚑Network reliability: nested tool calls amplify provider 429s; wrap agents in retry/timeouts and surface partial state via checkpoints.