npx skills add ...
npx skills add langchain-ai/langchain-skills --skill langchain-fundamentals
Create LangChain agents with create_agent, define tools, and use middleware for human-in-the-loop and error handling.
npx skills add langchain-ai/langchain-skills --skill langchain-fundamentals
<create_agent>
create_agent() is the recommended way to build agents. It handles the agent loop, tool execution, and state management.
| 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> |
Tools are functions that agents can call. Use the @tool decorator (Python) or tool() function (TypeScript).
Middleware intercepts the agent loop to add human approval, error handling, logging, and more. A deep understanding of middleware is essential for production agents — use HumanInTheLoopMiddleware (Python) / humanInTheLoopMiddleware (TypeScript) for approval workflows, and @wrap_tool_call (Python) / createMiddleware (TypeScript) for custom hooks.
Key imports:
Key patterns:
middleware=[HumanInTheLoopMiddleware(interrupt_on={"dangerous_tool": True})] — requires checkpointer + thread_idagent.invoke(Command(resume={"decisions": [{"type": "approve"}]}), config=config)@wrap_tool_call decorator (Python) or createMiddleware({ wrapToolCall: ... }) (TypeScript)<structured_output>
Get typed, validated responses from agents using response_format or with_structured_output().
<model_config>
create_agent accepts model strings ("anthropic:claude-sonnet-4-5", "openai:gpt-4.1") or model instances for custom settings:
</model_config>
Clear descriptions help the agent know when to use each tool.