langchain-fundamentals
Build production LangChain agents with create_agent(), tools, and middleware patterns.
- Use
create_agent()with model, tools list, and system prompt; configure state persistence withcheckpointerandthread_idfor conversation memory across invocations - Define tools via
@tooldecorator (Python) ortool()function (TypeScript) with clear descriptions so agents know when to call them - Add middleware like
HumanInTheLoopMiddlewarefor approval workflows, custom error handling, and human-in-the-loop control over agent decisions - Set
recursion_limitin invoke config to prevent infinite loops, and access results viaresult["messages"][-1].contentrather than direct content access
<create_agent>
Creating Agents with create_agent
create_agent() is the recommended way to build agents. It handles the agent loop, tool execution, and state management.
Agent Configuration Options
| Parameter | Purpose | Example |
|---|---|---|
model |
LLM to use | "anthropic:claude-sonnet-4-5" or model instance |
tools |
List of tools | [search, calculator] |
system_prompt / systemPrompt |
Agent instructions | "You are a helpful assistant" |
checkpointer |
State persistence | MemorySaver() |
middleware |
Processing hooks | [HumanInTheLoopMiddleware] (Python) / [humanInTheLoopMiddleware({...})] (TypeScript) |
| </create_agent> |
More from langchain-ai/langchain-skills
deep-agents-memory
INVOKE THIS SKILL when your Deep Agent needs memory, persistence, or filesystem access. Covers StateBackend (ephemeral), StoreBackend (persistent), FilesystemMiddleware, and CompositeBackend for routing.
7.7Klanggraph-fundamentals
INVOKE THIS SKILL when writing ANY LangGraph code. Covers StateGraph, state schemas, nodes, edges, Command, Send, invoke, streaming, and error handling.
7.1Klangchain-rag
INVOKE THIS SKILL when building ANY retrieval-augmented generation (RAG) system. Covers document loaders, RecursiveCharacterTextSplitter, embeddings (OpenAI), and vector stores (Chroma, FAISS, Pinecone).
6.5Klanggraph-persistence
INVOKE THIS SKILL when your LangGraph needs to persist state, remember conversations, travel through history, or configure subgraph checkpointer scoping. Covers checkpointers, thread_id, time travel, Store, and subgraph persistence modes.
6.5Klanggraph-human-in-the-loop
INVOKE THIS SKILL when implementing human-in-the-loop patterns, pausing for approval, or handling errors in LangGraph. Covers interrupt(), Command(resume=...), approval/validation workflows, and the 4-tier error handling strategy.
6.4Kdeep-agents-orchestration
INVOKE THIS SKILL when using subagents, task planning, or human approval in Deep Agents. Covers SubAgentMiddleware, TodoList for planning, and HITL interrupts.
6.3K