langchain-fundamentals

Create LangChain agents with create_agent, tools, middleware, and structured output.

Updated Jun 7, 2026
One-click install
npx skills add https://github.com/agnivon/viral_thread_generator --skill langchain-fundamentals-agnivon
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: langchain-fundamentals
Source: https://github.com/agnivon/viral_thread_generator/tree/main/.agents/skills/langchain-fundamentals
Command: npx skills add https://github.com/agnivon/viral_thread_generator --skill langchain-fundamentals-agnivon

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Building production agents with LangChain requires knowing the current recommended patterns, and outdated approaches lead to broken loops, lost conversation state, and uncontrolled tool execution. This Skill provides the canonical patterns for creating agents with create_agent, defining tools, adding middleware, and avoiding common pitfalls. ## Core Features & Use Cases - Agent Creation: Build agents with create_agent using model strings or instances, system prompts, and tool lists in both Python and TypeScript. - Middleware & Human-in-the-Loop: Add approval workflows with HumanInTheLoopMiddleware and custom hooks via wrap_tool_call or createMiddleware. - State & Reliability Patterns: Configure MemorySaver checkpoints with thread_id, set recursion_limit to prevent infinite loops, and produce typed structured output with Pydantic or Zod schemas. - Use Case: You need a support agent that searches the web, remembers each user's conversation across sessions, and pauses for human approval before running destructive actions. ## Quick Start Create a LangChain agent with create_agent that uses a web search tool, persists conversation state with a checkpointer, and requires human approval before executing dangerous tools.

Frequently Asked Questions about langchain-fundamentals

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a LangChain agent with tools?▼

Use create_agent with a model, a list of tools, and an optional system prompt. In Python, define tools with the @tool decorator from langchain_core.tools; in TypeScript, use the tool() function with a Zod schema from @langchain/core/tools.

How do I add human-in-the-loop approval to a LangChain agent?▼

Add HumanInTheLoopMiddleware (Python) or humanInTheLoopMiddleware (TypeScript) to the middleware list, specifying which tools require approval. This requires a checkpointer and a thread_id, and you resume execution by invoking with Command(resume={"decisions": [{"type": "approve"}]}).

Why does my LangChain agent forget previous messages between calls?▼

The agent has no persistence without a checkpointer. Pass MemorySaver as the checkpointer to create_agent and include a thread_id in the invoke config so conversation state is maintained across invocations.

How do I get structured output from a LangChain agent?▼

Pass a Pydantic model as response_format to create_agent and read result["structured_response"], or call with_structured_output on a chat model directly. In TypeScript, use withStructuredOutput with a Zod schema.

How do I stop a LangChain agent from looping forever?▼

Set recursion_limit (Python) or recursionLimit (TypeScript) in the invoke config, for example config={"recursion_limit": 10}. The agent stops after that many steps instead of running indefinitely.